Skip to content

Commit 2c10fbd

Browse files
committed
docs: Documenting commit ref support in CAS
1 parent 750a863 commit 2c10fbd

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">
@@ -195,9 +209,9 @@ When Terragrunt needs to clone a repository using the CAS it does the following,
195209

196210
For cold clones, where the content is not already in the CAS:
197211

198-
1. Terragrunt resolves the Git reference (branch/tag) to a commit hash
212+
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.
199213
2. The tree related to the commit hash is not found in the CAS
200-
3. Terragrunt clones the repository to a temporary directory
214+
3. Terragrunt fetches the repository contents (shallow for branch/tag refs, full history for commit SHAs)
201215
4. All blobs and trees required to reproduce the repository are extracted
202216
5. Content is stored in the CAS, partitioned by hash prefix
203217
6. The tree structure is read from the CAS and hard links are created to the target directory
@@ -206,7 +220,7 @@ For cold clones, where the content is not already in the CAS:
206220

207221
For warm clones, where the content is already in the CAS:
208222

209-
1. Terragrunt resolves the Git reference to a commit hash
223+
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.
210224
2. CAS checks if the content exists
211225
3. The tree structure is read directly from the CAS
212226
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
@@ -957,6 +957,27 @@ func TestDownloadWithCASEnabled(t *testing.T) {
957957
assert.Contains(t, stderr.String(), "Downloading Terraform configurations")
958958
}
959959

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

0 commit comments

Comments
 (0)