Skip to content

Commit 4cb949b

Browse files
committed
docs: Documenting commit ref support in CAS
1 parent 3de0dbf commit 4cb949b

4 files changed

Lines changed: 66 additions & 3 deletions

File tree

docs/src/content/docs/03-features/07-caching/04-cas.mdx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ terraform {
4848
}
4949
```
5050

51+
<Since version="1.0.4">
52+
53+
`ref=` also accepts commit SHAs (full or abbreviated), not only branch and tag names.
54+
55+
```hcl
56+
terraform {
57+
source = "git@github.com:acme/infrastructure-modules.git//vpc?ref=a1b2c3d4e5f67890abcdef1234567890deadbeef"
58+
}
59+
```
60+
61+
The first cold clone of a repository pinned to a commit SHA fetches the full history of every branch. Shallow fetches require a ref name, and fetching a commit SHA at limited depth depends on a server option (`uploadpack.allowAnySHA1InWant`) that is not universally enabled, so CAS fetches all branches at full depth and resolves the SHA locally. Subsequent clones reuse the cached repository and never touch the network for the same commit.
62+
63+
</Since>
64+
5165
### Stack Usage
5266

5367
<Before version="1.0.3">
@@ -207,9 +221,9 @@ When Terragrunt needs to clone a repository using the CAS it does the following,
207221

208222
For cold clones, where the content is not already in the CAS:
209223

210-
1. Terragrunt resolves the Git reference (branch/tag) to a commit hash
224+
1. Terragrunt resolves the Git reference to a commit hash. Branch and tag refs resolve via `git ls-remote`. `ls-remote` lists named refs and does not resolve commit SHAs, so for SHA refs Terragrunt fetches the full history of every branch into the central Git store and resolves the SHA locally.
211225
2. The tree related to the commit hash is not found in the CAS
212-
3. Terragrunt opens the bare repository for the remote URL under `cas/store/git/` (initializing it on first use), takes a per-URL lock, and fetches the requested ref. Subsequent misses against the same URL reuse the existing pack files and only transfer new objects.
226+
3. Terragrunt opens the bare repository for the remote URL under `cas/store/git/` (initializing it on first use), takes a per-URL lock, and fetches the requested ref (shallow for branch/tag refs, full history for commit SHAs). Subsequent misses against the same URL reuse the existing pack files and only transfer new objects.
213227
4. All blobs and trees required to reproduce the repository are extracted from the bare repository
214228
5. Content is stored in the CAS, partitioned by hash prefix
215229
6. The tree structure is read from the CAS and hard links are created to the target directory
@@ -220,7 +234,7 @@ Concurrent units that target the same remote URL share one fetch instead of clon
220234

221235
For warm clones, where the content is already in the CAS:
222236

223-
1. Terragrunt resolves the Git reference to a commit hash
237+
1. Terragrunt resolves the Git reference to a commit hash. For commit-SHA refs the local central Git store answers without contacting the remote when the SHA is already cached.
224238
2. CAS checks if the content exists
225239
3. The tree structure is read directly from the CAS
226240
4. Hard links are created from CAS to the target directory
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
version: "v1.0.4"
3+
category: "experiments-updated"
4+
---
5+
6+
#### `cas` — Commit SHAs accepted in `ref=`
7+
8+
Source URLs of the form `git::<url>?ref=<commit-sha>` now resolve through CAS. Previously these clones failed because Terragrunt asked the remote to look up the SHA as a symbolic reference, which Git servers don't support.
9+
10+
Both full SHAs (SHA-1 and SHA-256) and abbreviated SHAs are accepted. Abbreviated SHAs must disambiguate inside the repository, the same rule Git itself applies.
11+
12+
```hcl
13+
terraform {
14+
source = "git::https://github.com/acme/infrastructure-modules.git//vpc?ref=a1b2c3d4e5f67890abcdef1234567890deadbeef"
15+
}
16+
```
17+
18+
The first cold clone of a repository pinned to a commit SHA fetches the full history of every branch. Shallow fetches require a ref name, and fetching a commit SHA at limited depth depends on a server option (`uploadpack.allowAnySHA1InWant`) that is not universally enabled, so CAS fetches all branches at full depth and resolves the SHA locally. Subsequent clones reuse the cached repository and never touch the network for the same commit. Branch and tag refs continue to use the existing shallow path.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
inputs = {
2+
name = "World"
3+
}
4+
5+
terraform {
6+
# Pinned to the commit v0.93.2 resolves to so this fixture exercises
7+
# the commit-SHA path in the CAS getter without depending on whatever
8+
# the tag points to in the future.
9+
source = "github.com/gruntwork-io/terragrunt.git//test/fixtures/download/hello-world-no-remote?ref=dd7913e04f0e812b51ccf2c4f35a0fda16a356a1"
10+
}

test/integration_download_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,3 +955,24 @@ func TestDownloadWithCASEnabled(t *testing.T) {
955955

956956
assert.Contains(t, stderr.String(), "Downloading Terraform configurations")
957957
}
958+
959+
func TestDownloadWithCASCommitRef(t *testing.T) {
960+
t.Parallel()
961+
962+
fixturePath := "fixtures/download/remote-commit-ref"
963+
964+
tmpEnvPath := helpers.CopyEnvironment(t, fixturePath)
965+
testPath := filepath.Join(tmpEnvPath, fixturePath)
966+
helpers.CleanupTerraformFolder(t, testPath)
967+
968+
var (
969+
stdout bytes.Buffer
970+
stderr bytes.Buffer
971+
)
972+
973+
cmd := "terragrunt apply --auto-approve --non-interactive --experiment cas --log-level debug --working-dir " + testPath
974+
err := helpers.RunTerragruntCommand(t, cmd, &stdout, &stderr)
975+
require.NoError(t, err)
976+
977+
assert.Contains(t, stderr.String(), "Downloading Terraform configurations")
978+
}

0 commit comments

Comments
 (0)