|
2 | 2 | layout: collection-browser-doc |
3 | 3 | title: Pinning a Terratest version |
4 | 4 | category: getting-started |
5 | | -excerpt: Lock your tests to a known-good Terratest release and upgrade safely. |
| 5 | +excerpt: Lock your tests to a specific Terratest release. |
6 | 6 | tags: ["versioning", "go-modules", "pinning"] |
7 | 7 | order: 106 |
8 | 8 | nav_title: Documentation |
9 | 9 | nav_title_link: /docs/ |
10 | 10 | --- |
11 | 11 |
|
12 | | -## Why pin a version? |
| 12 | +Pin Terratest if you need reproducible test builds and deliberate control over when you adopt a new release. |
13 | 13 |
|
14 | | -Terratest is a Go library, so the version your tests build against is whatever your test module's `go.mod` resolves to. Without an explicit pin, `go get` will pick up the newest published release the next time the module graph is recomputed, which means a regression in a future release can fail builds you did not change. Pinning makes the version a deliberate choice and keeps CI reproducible. |
| 14 | +## Pin to a release |
15 | 15 |
|
16 | | -Starting with v1.0.0, Terratest follows [semantic versioning](https://semver.org/) and breaking changes only happen in major releases. Pinning is still useful when you want to control _when_ you take a minor or patch bump. |
17 | | - |
18 | | -## Pin to a specific release |
19 | | - |
20 | | -From the directory that contains your test module's `go.mod`, run: |
| 16 | +From the directory that contains your test module's `go.mod`: |
21 | 17 |
|
22 | 18 | ```bash |
23 | 19 | go get github.com/gruntwork-io/terratest@v0.56.0 |
24 | 20 | go mod tidy |
25 | 21 | ``` |
26 | 22 |
|
27 | | -Replace `v0.56.0` with the release tag you want. See the [Releases page](https://github.com/gruntwork-io/terratest/releases) for the full list. Always commit both `go.mod` and `go.sum` so the pin and its checksums travel with your code. Anyone who runs `go test` against the same `go.mod`/`go.sum` will resolve to the exact same Terratest version. |
28 | | - |
29 | | -To downgrade or revert to an earlier release, run the same command with the older tag. |
| 23 | +Replace `v0.56.0` with the tag you want from the [Releases page](https://github.com/gruntwork-io/terratest/releases). The same command upgrades, downgrades, or reverts the pin. Always commit `go.mod` and `go.sum` so the pin travels with your code; avoid `@latest` if you need reproducibility. |
30 | 24 |
|
31 | 25 | ## Use the root module path |
32 | 26 |
|
33 | | -Use the root module path `github.com/gruntwork-io/terratest`, not submodule paths like `github.com/gruntwork-io/terratest/modules/terraform`. Terratest publishes a single Go module at the repository root; submodule-style paths such as `modules/terraform/v0.51.0` are not valid Go module versions and will fail with `unknown revision`: |
34 | | - |
35 | | -```text |
36 | | -reading github.com/gruntwork-io/terratest/modules/terraform/go.mod |
37 | | -at revision modules/terraform/v0.51.0: unknown revision |
38 | | -``` |
39 | | - |
40 | | -If you import individual subpackages in your tests (for example `github.com/gruntwork-io/terratest/modules/terraform`), that is fine. They all resolve through the single root module pin. |
41 | | - |
42 | | -## Upgrading |
43 | | - |
44 | | -When you are ready to take a newer release, bump the pin explicitly and run the test suite: |
45 | | - |
46 | | -```bash |
47 | | -go get github.com/gruntwork-io/terratest@v0.56.0 |
48 | | -go mod tidy |
49 | | -go test ./... |
50 | | -``` |
51 | | - |
52 | | -If a release introduces a regression, revert the pin to the last known-good version and open an issue at [github.com/gruntwork-io/terratest/issues](https://github.com/gruntwork-io/terratest/issues). For history of breaking changes between v0.x and v1.0.0, see [`MIGRATION.md`](https://github.com/gruntwork-io/terratest/blob/main/MIGRATION.md). |
| 27 | +Pin `github.com/gruntwork-io/terratest`, not submodule paths like `github.com/gruntwork-io/terratest/modules/terraform`. Terratest publishes a single Go module at the repository root, so submodule-style versions (e.g. `modules/terraform/v0.51.0`) fail with `unknown revision`. Subpackage imports in your test code are fine; they all resolve through the root module pin. |
0 commit comments