Skip to content

Commit d63f3f1

Browse files
authored
Merge branch 'main' into james/oss-3454-aws-pagination
2 parents 38cdf05 + e6d0e15 commit d63f3f1

10 files changed

Lines changed: 264 additions & 25 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Starting with v1.0.0, Terratest follows [semantic versioning](https://semver.org
3535
only happen in major releases (e.g. v2.0.0).
3636

3737
Symbols renamed or replaced in v1 are kept with `// Deprecated:` annotations pointing at the new name; removals happen
38-
in v2. Migrating from v0.x: see [`MIGRATION.md`](./MIGRATION.md).
38+
in v2. Migrating from v0.x: see the [v1 migration guide](https://terratest.gruntwork.io/docs/migrating-to-v1/overview/).
3939

4040
## More info
4141

docs/_docs/01_getting-started/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ custom_js:
1616

1717
Terratest uses the Go testing framework. To use Terratest, you need to install:
1818

19-
- [Go](https://golang.org/) (requires version >=1.21.1)
19+
- [Go](https://golang.org/) (requires version >=1.26)
2020

2121
## Setting up your project
2222

docs/_docs/03_migrating-to-v1/azure.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ category: migrating-to-v1
55
excerpt: >-
66
Migrate Azure tests from Terratest pre-v1 to v1.0.0.
77
tags: ["azure", "migration", "v1"]
8-
order: 300
8+
order: 301
99
nav_title: Documentation
1010
nav_title_link: /docs/
1111
---
@@ -84,7 +84,7 @@ Once imports are updated, expect three follow-on edits per file:
8484

8585
Four client factories were renamed to drop the redundant `New` (a
8686
`Create*New*Client` reads as redundant). The old names remain as deprecated
87-
aliases for one minor release; please update at your convenience.
87+
aliases for the v1 line; please update at your convenience.
8888

8989
| Old name | New name |
9090
| --- | --- |
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
---
2+
layout: collection-browser-doc
3+
title: Overview
4+
category: migrating-to-v1
5+
excerpt: >-
6+
Summary of breaking changes in Terratest v1.0.0 and where to look first.
7+
tags: ["migration", "v1"]
8+
order: 300
9+
nav_title: Documentation
10+
nav_title_link: /docs/
11+
---
12+
13+
Terratest v1.0.0 is the first stable release. Once you are on v1, breaking
14+
changes to the public API only happen in major releases (e.g. v2.0.0), per
15+
[semver](https://semver.org/). Renamed or replaced symbols stay around as
16+
deprecated aliases inside v1; full removal is deferred to v2.
17+
18+
This page is the orientation map for v0.x to v1.0.0. It tells you what
19+
shape the changes take and where to look; the per-service guides hold the
20+
mechanical details.
21+
22+
## Prerequisites
23+
24+
- **Go 1.26 or newer.** v1.0.0 raised the minimum.
25+
- After upgrading, run `go mod tidy` from the directory that holds your
26+
test module's `go.mod`. The AWS, Azure, and GCP SDK pins all moved.
27+
28+
## Function naming conventions
29+
30+
Most public Terratest helpers come in up to four variants. Knowing which
31+
to call is the most common source of confusion when reading v1 godoc:
32+
33+
| Suffix | Takes `context.Context` | On error |
34+
| --- | --- | --- |
35+
| `Foo` | no | calls `t.Fatal` (fails the test) |
36+
| `FooE` | no | returns `error` to the caller |
37+
| `FooContext` | yes | calls `t.Fatal` |
38+
| `FooContextE` | yes | returns `error` |
39+
40+
Two independent suffixes:
41+
42+
- **`E` suffix.** Long-standing Terratest convention. Use the bare name
43+
(`Apply`) when you want any failure to fail the test, and the `E`
44+
variant (`ApplyE`) when you want the error back to assert on it or
45+
retry.
46+
- **`Context` suffix.** Added in v1. Takes an explicit `context.Context`
47+
as the second argument so callers can plumb timeouts, cancellation,
48+
and tracing through. The non-`Context` variants are now deprecated
49+
in favor of their `*Context*` counterparts.
50+
51+
The preferred v1 call is `FooContext` (or `FooContextE`). For example,
52+
prefer `terraform.ApplyContext(t, ctx, opts)` over
53+
`terraform.Apply(t, opts)`.
54+
55+
A small number of helpers do not yet expose all four variants (some
56+
packages added `Context` and dropped the bare `Foo` form, others have
57+
not grown a `Context` variant at all). Trust godoc and the deprecation
58+
warnings over the table when they disagree.
59+
60+
## Migrating to the `Context` variants
61+
62+
The Context migration is the single largest source of deprecation
63+
warnings you will see when upgrading. It touches nearly every helper
64+
package: `terraform`, `helm`, `dns-helper`, `http-helper`, `packer`,
65+
`docker`, `ssh`, `oci`, `k8s`, `aws`, `azure`, `gcp`. The non-`Context`
66+
variants compile and behave the same as before; they just emit a
67+
`// Deprecated:` godoc warning.
68+
69+
Mechanical migration:
70+
71+
```go
72+
// Before
73+
out := terraform.Apply(t, options)
74+
out, err := terraform.ApplyE(t, options)
75+
76+
// After
77+
ctx := context.Background() // or context.WithTimeout(...) for cancellation
78+
out := terraform.ApplyContext(t, ctx, options)
79+
out, err := terraform.ApplyContextE(t, ctx, options)
80+
```
81+
82+
The `*Context*` variants always take `(t, ctx, ...originalArgs)`. If
83+
you do not need cancellation or timeouts, `context.Background()` gives
84+
you the same behavior as the deprecated wrapper. When `t` is
85+
`*testing.T` (Go 1.24+), `t.Context()` is an even better default
86+
because it ties the context lifetime to the test.
87+
88+
You can do this incrementally. The deprecated wrappers will keep
89+
working for the entire v1 line; they only disappear in v2.
90+
91+
## What changed by service
92+
93+
### Azure
94+
95+
The largest set of breaking changes by far. The whole `modules/azure`
96+
package was moved from the archived `services/...` SDK to the actively
97+
maintained `sdk/resourcemanager/...` SDK, plus a handful of naming
98+
cleanups. Updating imports and the resulting compile errors is the bulk
99+
of the work; per-service tables and a search-and-replace cheatsheet are
100+
in [Azure modules](./azure/).
101+
102+
### AWS
103+
104+
`modules/aws/s3.go` migrated off the deprecated
105+
`s3/manager` package onto `s3/transfermanager`. Four exported functions
106+
that returned `*manager.Uploader` now return `*transfermanager.Client`:
107+
`NewS3Uploader`, `NewS3UploaderE`, `NewS3UploaderContext`, and
108+
`NewS3UploaderContextE`. The call shape moves from
109+
`uploader.Upload(ctx, &s3.PutObjectInput{...})` to
110+
`client.UploadObject(ctx, &transfermanager.UploadObjectInput{...})`,
111+
with the input/output types under
112+
`github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager`.
113+
114+
Every direct `github.com/aws/aws-*` dependency was bumped to the
115+
versions current at the v1.0.0 cut. If your tests import the AWS SDKs
116+
directly, expect to run `go mod tidy` and resolve a small number of
117+
type renames at the SDK level.
118+
119+
### GCP
120+
121+
`modules/gcp/pubsub.go` moved from `cloud.google.com/go/pubsub` (v1) to
122+
`cloud.google.com/go/pubsub/v2`. The wrapper functions in `modules/gcp`
123+
are unchanged in shape, but callers that drove the underlying client
124+
directly need to switch from `client.Topic("name")` /
125+
`client.Subscription("name")` handles to `TopicAdminClient` /
126+
`SubscriptionAdminClient` calls that take fully qualified resource
127+
names (`projects/<id>/topics/<name>`).
128+
129+
A new family of `*WithClient` helpers was added across `modules/gcp`
130+
(compute, oslogin, region, pubsub, storage, cloudbuild, gcr) so tests
131+
can inject a pre-built SDK client. This parallels the Azure
132+
`*WithClient` change and is purely additive.
133+
134+
### Kubernetes
135+
136+
`GetKubernetesClientFromOptionsContextE` now logs the kubeconfig load
137+
error before falling back to `rest.InClusterConfig()`; previously the
138+
fallback was silent.
139+
140+
This was a silent-failure footgun: a typo in
141+
`KubectlOptions.ConfigPath` would send tests against the test runner's
142+
in-cluster identity (potentially a different cluster) with no signal
143+
that anything had happened. v1 surfaces the error in the test log, and
144+
adds an explicit `KubectlOptions.InClusterAuth = true` opt-in that
145+
skips kubeconfig loading entirely for callers who want fully explicit
146+
auth.
147+
148+
## Other deprecations you can defer
149+
150+
A large set of legacy spellings picked up Go-idiomatic replacements in
151+
v1, all preserved as deprecated aliases. Most follow common acronym
152+
casing (`Id``ID`, `Ip``IP`, `Json``JSON`, `Url``URL`,
153+
`Ssh``SSH`, `Gcp``GCP`); a few drop redundant prefixes (Azure's
154+
`CreateNew*Client*` becomes `Create*Client*`); and a few rename for
155+
clarity (e.g. `SaveAmiId` / `LoadAmiId` became
156+
`SaveArtifactID` / `LoadArtifactID` to reflect that the helpers are
157+
not AMI-specific).
158+
159+
You do not need to track these one by one. Run `go vet` or
160+
`staticcheck` against your test module after upgrading; the deprecated
161+
aliases all carry `// Deprecated:` annotations and the linter will
162+
list them with the replacement to use. Aliases stay for the v1 line
163+
and are removed in v2.
164+
165+
## Need help
166+
167+
Open an issue on the [Terratest
168+
repo](https://github.com/gruntwork-io/terratest/issues) with a snippet
169+
of the failing code and the relevant module label. If you spot a gap
170+
in this guide, send a PR against `docs/_docs/03_migrating-to-v1/`.

docs/_docs/04_community/contributing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ go test -timeout 30m -run "<TEST_NAME>"
256256
This repo follows the principles of [Semantic Versioning](http://semver.org/). You can find each new release,
257257
along with the changelog, in the [Releases Page](https://github.com/gruntwork-io/terratest/releases).
258258

259-
During initial development, the major version will be 0 (e.g., `0.x.y`), which indicates the code does not yet have a
260-
stable API. Once we hit `1.0.0`, we will make every effort to maintain a backwards compatible API and use the MAJOR,
261-
MINOR, and PATCH versions on each release to indicate any incompatibilities.
259+
Starting with `1.0.0`, breaking changes to the public API only happen in major releases. Symbols renamed or replaced
260+
inside the v1 line are kept as `// Deprecated:` aliases so test code that compiled against an earlier v1.x.y release
261+
will keep compiling against later ones; full removal is deferred to v2.
262262

263263
### Developing For Azure
264264

modules/azure/availabilityset.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ func CheckAvailabilitySetContainsVMWithClient(ctx context.Context, client *armco
106106
return false, err
107107
}
108108

109+
if resp.Properties == nil {
110+
return false, NewNotFoundError("Virtual Machine", vmName, avsName)
111+
}
112+
109113
for _, vm := range resp.Properties.VirtualMachines {
110114
if vm.ID == nil {
111115
continue
@@ -171,6 +175,10 @@ func GetAvailabilitySetVMNamesInCapsWithClient(ctx context.Context, client *armc
171175

172176
vms := []string{}
173177

178+
if resp.Properties == nil {
179+
return vms, nil
180+
}
181+
174182
for _, vm := range resp.Properties.VirtualMachines {
175183
if vm.ID == nil {
176184
continue

modules/azure/client_factory.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,9 @@ func CreateSQLServerClient(subscriptionID string) (*armsql.ServersClient, error)
489489
return CreateSQLServerClientContext(context.Background(), subscriptionID)
490490
}
491491

492-
// CreateSQLMangedInstanceClientContext is a helper function that will create and setup a sql managed instance client.
492+
// CreateSQLManagedInstanceClientContext is a helper function that will create and setup a sql managed instance client.
493493
// The ctx parameter supports cancellation and timeouts.
494-
func CreateSQLMangedInstanceClientContext(_ context.Context, subscriptionID string) (*armsql.ManagedInstancesClient, error) {
494+
func CreateSQLManagedInstanceClientContext(_ context.Context, subscriptionID string) (*armsql.ManagedInstancesClient, error) {
495495
clientFactory, err := getArmSQLClientFactory(subscriptionID)
496496
if err != nil {
497497
return nil, err
@@ -500,16 +500,26 @@ func CreateSQLMangedInstanceClientContext(_ context.Context, subscriptionID stri
500500
return clientFactory.NewManagedInstancesClient(), nil
501501
}
502502

503-
// CreateSQLMangedInstanceClient is a helper function that will create and setup a sql managed instance client.
503+
// CreateSQLManagedInstanceClient is a helper function that will create and setup a sql managed instance client.
504504
//
505-
// Deprecated: Use [CreateSQLMangedInstanceClientContext] instead.
506-
func CreateSQLMangedInstanceClient(subscriptionID string) (*armsql.ManagedInstancesClient, error) {
507-
return CreateSQLMangedInstanceClientContext(context.Background(), subscriptionID)
505+
// Deprecated: Use [CreateSQLManagedInstanceClientContext] instead.
506+
func CreateSQLManagedInstanceClient(subscriptionID string) (*armsql.ManagedInstancesClient, error) {
507+
return CreateSQLManagedInstanceClientContext(context.Background(), subscriptionID)
508508
}
509509

510-
// CreateSQLMangedDatabasesClientContext is a helper function that will create and setup a sql managed databases client.
510+
// Deprecated: Use [CreateSQLManagedInstanceClientContext] instead.
511+
func CreateSQLMangedInstanceClientContext(ctx context.Context, subscriptionID string) (*armsql.ManagedInstancesClient, error) { //nolint:revive,staticcheck // preserving deprecated function name
512+
return CreateSQLManagedInstanceClientContext(ctx, subscriptionID)
513+
}
514+
515+
// Deprecated: Use [CreateSQLManagedInstanceClient] instead.
516+
func CreateSQLMangedInstanceClient(subscriptionID string) (*armsql.ManagedInstancesClient, error) { //nolint:revive,staticcheck // preserving deprecated function name
517+
return CreateSQLManagedInstanceClient(subscriptionID)
518+
}
519+
520+
// CreateSQLManagedDatabasesClientContext is a helper function that will create and setup a sql managed databases client.
511521
// The ctx parameter supports cancellation and timeouts.
512-
func CreateSQLMangedDatabasesClientContext(_ context.Context, subscriptionID string) (*armsql.ManagedDatabasesClient, error) {
522+
func CreateSQLManagedDatabasesClientContext(_ context.Context, subscriptionID string) (*armsql.ManagedDatabasesClient, error) {
513523
clientFactory, err := getArmSQLClientFactory(subscriptionID)
514524
if err != nil {
515525
return nil, err
@@ -518,11 +528,21 @@ func CreateSQLMangedDatabasesClientContext(_ context.Context, subscriptionID str
518528
return clientFactory.NewManagedDatabasesClient(), nil
519529
}
520530

521-
// CreateSQLMangedDatabasesClient is a helper function that will create and setup a sql managed databases client.
531+
// CreateSQLManagedDatabasesClient is a helper function that will create and setup a sql managed databases client.
522532
//
523-
// Deprecated: Use [CreateSQLMangedDatabasesClientContext] instead.
524-
func CreateSQLMangedDatabasesClient(subscriptionID string) (*armsql.ManagedDatabasesClient, error) {
525-
return CreateSQLMangedDatabasesClientContext(context.Background(), subscriptionID)
533+
// Deprecated: Use [CreateSQLManagedDatabasesClientContext] instead.
534+
func CreateSQLManagedDatabasesClient(subscriptionID string) (*armsql.ManagedDatabasesClient, error) {
535+
return CreateSQLManagedDatabasesClientContext(context.Background(), subscriptionID)
536+
}
537+
538+
// Deprecated: Use [CreateSQLManagedDatabasesClientContext] instead.
539+
func CreateSQLMangedDatabasesClientContext(ctx context.Context, subscriptionID string) (*armsql.ManagedDatabasesClient, error) { //nolint:revive,staticcheck // preserving deprecated function name
540+
return CreateSQLManagedDatabasesClientContext(ctx, subscriptionID)
541+
}
542+
543+
// Deprecated: Use [CreateSQLManagedDatabasesClient] instead.
544+
func CreateSQLMangedDatabasesClient(subscriptionID string) (*armsql.ManagedDatabasesClient, error) { //nolint:revive,staticcheck // preserving deprecated function name
545+
return CreateSQLManagedDatabasesClient(subscriptionID)
526546
}
527547

528548
// getArmSQLClientFactory gets an arm sql client factory

modules/azure/sql_managedinstance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func GetManagedInstanceContext(t testing.TestingT, ctx context.Context, resGroup
6767
// GetManagedInstanceContextE retrieves the SQL managed instance object for the given subscription.
6868
// The ctx parameter supports cancellation and timeouts.
6969
func GetManagedInstanceContextE(ctx context.Context, subscriptionID string, resGroupName string, managedInstanceName string) (*armsql.ManagedInstance, error) {
70-
sqlmiClient, err := CreateSQLMangedInstanceClientContext(ctx, subscriptionID)
70+
sqlmiClient, err := CreateSQLManagedInstanceClientContext(ctx, subscriptionID)
7171
if err != nil {
7272
return nil, err
7373
}
@@ -117,7 +117,7 @@ func GetManagedInstanceDatabaseContext(t testing.TestingT, ctx context.Context,
117117
// GetManagedInstanceDatabaseContextE retrieves the SQL managed database object for the given subscription.
118118
// The ctx parameter supports cancellation and timeouts.
119119
func GetManagedInstanceDatabaseContextE(ctx context.Context, subscriptionID string, resGroupName string, managedInstanceName string, databaseName string) (*armsql.ManagedDatabase, error) {
120-
sqlmiDBClient, err := CreateSQLMangedDatabasesClientContext(ctx, subscriptionID)
120+
sqlmiDBClient, err := CreateSQLManagedDatabasesClientContext(ctx, subscriptionID)
121121
if err != nil {
122122
return nil, err
123123
}

modules/gcp/compute.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,22 @@ func (i *Instance) SetLabelsContextE(t testing.TestingT, ctx context.Context, la
425425
return i.SetLabelsWithClient(ctx, service, labels)
426426
}
427427

428-
// SetLabelsWithClient adds the tags to the given Compute Instance using the supplied *compute.Service.
429-
// Prefer this variant in unit tests where the service is backed by an httptest fake server
430-
// (see compute_unit_test.go for the pattern).
428+
// SetLabelsWithClient merges the given labels into the instance's existing labels using the
429+
// supplied *compute.Service. Keys present in labels overwrite existing values; other labels
430+
// are preserved. Prefer this variant in unit tests where the service is backed by an httptest
431+
// fake server (see compute_unit_test.go for the pattern).
431432
// The ctx parameter supports cancellation and timeouts.
432433
func (i *Instance) SetLabelsWithClient(ctx context.Context, service *compute.Service, labels map[string]string) error {
433-
req := compute.InstancesSetLabelsRequest{Labels: labels, LabelFingerprint: i.LabelFingerprint}
434+
merged := make(map[string]string, len(i.Labels)+len(labels))
435+
for k, v := range i.Labels {
436+
merged[k] = v
437+
}
438+
439+
for k, v := range labels {
440+
merged[k] = v
441+
}
442+
443+
req := compute.InstancesSetLabelsRequest{Labels: merged, LabelFingerprint: i.LabelFingerprint}
434444

435445
if _, err := service.Instances.SetLabels(i.projectID, ZoneURLToZone(i.Zone), i.Name, &req).Context(ctx).Do(); err != nil {
436446
return fmt.Errorf("Instances.SetLabels(%s) got error: %w", i.Name, err)

0 commit comments

Comments
 (0)