Skip to content

Commit 9565e65

Browse files
authored
Merge pull request #1758 from gruntwork-io/deprecation-api
chore: marked as deprecated functions which have context variant
2 parents 0535ac9 + d953cc8 commit 9565e65

100 files changed

Lines changed: 3452 additions & 907 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/aws/account.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ func NewStsClientContext(t testing.TestingT, ctx context.Context, region string)
9595
return client
9696
}
9797

98+
// NewStsClient creates a new STS client.
99+
//
100+
// Deprecated: Use [NewStsClientContext] instead.
101+
func NewStsClient(t testing.TestingT, region string) *sts.Client {
102+
t.Helper()
103+
104+
return NewStsClientContext(t, context.Background(), region)
105+
}
106+
98107
// NewStsClientE creates a new STS client.
99108
//
100109
// Deprecated: Use [NewStsClientContextE] instead.

modules/aws/asg.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ func WaitForCapacityContextE(
144144
maxRetries int,
145145
sleepBetweenRetries time.Duration,
146146
) error {
147-
msg, err := retry.DoWithRetryE(
147+
msg, err := retry.DoWithRetryContextE(
148148
t,
149+
ctx,
149150
fmt.Sprintf("Waiting for ASG %s to reach desired capacity.", asgName),
150151
maxRetries,
151152
sleepBetweenRetries,

modules/aws/ec2-syslog.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ func GetSyslogForInstanceContextE(t testing.TestingT, ctx context.Context, insta
3636
InstanceId: aws.String(instanceID),
3737
}
3838

39-
syslogB64, err := retry.DoWithRetryE(t, description, maxRetries, syslogRetryInterval, func() (string, error) {
40-
if ctx.Err() != nil {
41-
return "", ctx.Err()
42-
}
43-
39+
syslogB64, err := retry.DoWithRetryContextE(t, ctx, description, maxRetries, syslogRetryInterval, func() (string, error) {
4440
out, err := client.GetConsoleOutput(ctx, &input)
4541
if err != nil {
4642
return "", err

modules/aws/ec2.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,25 @@ func GetLaunchPermissionsForAmiContextE(t testing.TestingT, ctx context.Context,
647647
return output.LaunchPermissions, nil
648648
}
649649

650+
// GetLaunchPermissionsForAmiContext returns launchPermissions as configured in AWS.
651+
// This function will fail the test if there is an error.
652+
// The ctx parameter supports cancellation and timeouts.
653+
func GetLaunchPermissionsForAmiContext(t testing.TestingT, ctx context.Context, awsRegion string, amiID string) []types.LaunchPermission {
654+
t.Helper()
655+
output, err := GetLaunchPermissionsForAmiContextE(t, ctx, awsRegion, amiID)
656+
require.NoError(t, err)
657+
658+
return output
659+
}
660+
661+
// GetLaunchPermissionsForAmi returns launchPermissions as configured in AWS.
662+
//
663+
// Deprecated: Use [GetLaunchPermissionsForAmiContext] instead.
664+
func GetLaunchPermissionsForAmi(t testing.TestingT, awsRegion string, amiID string) []types.LaunchPermission {
665+
t.Helper()
666+
return GetLaunchPermissionsForAmiContext(t, context.Background(), awsRegion, amiID)
667+
}
668+
650669
// GetLaunchPermissionsForAmiE returns launchPermissions as configured in AWS
651670
//
652671
// Deprecated: Use [GetLaunchPermissionsForAmiContextE] instead.
@@ -734,6 +753,38 @@ func GetRecommendedInstanceTypeWithClientContextE(t testing.TestingT, ctx contex
734753
return PickRecommendedInstanceTypeE(availabilityZones, instanceTypeOfferings, instanceTypeOptions)
735754
}
736755

756+
// GetRecommendedInstanceTypeWithClientContext takes in a list of EC2 instance types (e.g., "t2.micro", "t3.micro") and returns the
757+
// first instance type in the list that is available in all Availability Zones (AZs) in the given region. If there's no
758+
// instance available in all AZs, this function exits with an error. This is useful because certain instance types,
759+
// such as t2.micro, are not available in some of the newer AZs, while t3.micro is not available in some of the older
760+
// AZs. If you have code that needs to run on a "small" instance across all AZs in many different regions, you can
761+
// use this function to automatically figure out which instance type you should use.
762+
// This function expects an authenticated EC2 client from the AWS SDK Go library.
763+
// This function will fail the test if there is an error.
764+
// The ctx parameter supports cancellation and timeouts.
765+
func GetRecommendedInstanceTypeWithClientContext(t testing.TestingT, ctx context.Context, ec2Client *ec2.Client, instanceTypeOptions []string) string {
766+
t.Helper()
767+
out, err := GetRecommendedInstanceTypeWithClientContextE(t, ctx, ec2Client, instanceTypeOptions)
768+
require.NoError(t, err)
769+
770+
return out
771+
}
772+
773+
// GetRecommendedInstanceTypeWithClient takes in a list of EC2 instance types (e.g., "t2.micro", "t3.micro") and returns the
774+
// first instance type in the list that is available in all Availability Zones (AZs) in the given region. If there's no
775+
// instance available in all AZs, this function exits with an error. This is useful because certain instance types,
776+
// such as t2.micro, are not available in some of the newer AZs, while t3.micro is not available in some of the older
777+
// AZs. If you have code that needs to run on a "small" instance across all AZs in many different regions, you can
778+
// use this function to automatically figure out which instance type you should use.
779+
// This function expects an authenticated EC2 client from the AWS SDK Go library.
780+
// This function will fail the test if there is an error.
781+
//
782+
// Deprecated: Use [GetRecommendedInstanceTypeWithClientContext] instead.
783+
func GetRecommendedInstanceTypeWithClient(t testing.TestingT, ec2Client *ec2.Client, instanceTypeOptions []string) string {
784+
t.Helper()
785+
return GetRecommendedInstanceTypeWithClientContext(t, context.Background(), ec2Client, instanceTypeOptions)
786+
}
787+
737788
// GetRecommendedInstanceTypeWithClientE takes in a list of EC2 instance types (e.g., "t2.micro", "t3.micro") and returns the
738789
// first instance type in the list that is available in all Availability Zones (AZs) in the given region. If there's no
739790
// instance available in all AZs, this function exits with an error. This is useful because certain instance types,

modules/aws/region.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ func GetRandomStableRegion(t testing.TestingT, approvedRegions []string, forbidd
8989
return GetRandomStableRegionContext(t, context.Background(), approvedRegions, forbiddenRegions)
9090
}
9191

92+
// GetRandomStableRegionE gets a randomly chosen AWS region that is considered stable. Like GetRandomRegion, you can
93+
// further restrict the stable region list using approvedRegions and forbiddenRegions. We consider stable regions to be
94+
// those that have been around for at least 1 year.
95+
// Note that regions in the approvedRegions list that are not considered stable are ignored.
96+
//
97+
// Deprecated: Use [GetRandomStableRegionContextE] instead.
98+
func GetRandomStableRegionE(t testing.TestingT, approvedRegions []string, forbiddenRegions []string) (string, error) {
99+
return GetRandomStableRegionContextE(t, context.Background(), approvedRegions, forbiddenRegions)
100+
}
101+
92102
// GetRandomRegionContextE gets a randomly chosen AWS region. If approvedRegions is not empty, this will be a region from the approvedRegions
93103
// list; otherwise, this method will fetch the latest list of regions from the AWS APIs and pick one of those. If
94104
// forbiddenRegions is not empty, this method will make sure the returned region is not in the forbiddenRegions list.
@@ -348,3 +358,11 @@ func GetRandomRegionForService(t testing.TestingT, serviceName string) string {
348358

349359
return GetRandomRegionForServiceContext(t, context.Background(), serviceName)
350360
}
361+
362+
// GetRandomRegionForServiceE retrieves a list of AWS regions in which a service is available
363+
// Then returns one region randomly from the list and returns errors.
364+
//
365+
// Deprecated: Use [GetRandomRegionForServiceContextE] instead.
366+
func GetRandomRegionForServiceE(t testing.TestingT, serviceName string) (string, error) {
367+
return GetRandomRegionForServiceContextE(t, context.Background(), serviceName)
368+
}

modules/aws/ssm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func WaitForSsmInstanceWithClientContextE(t testing.TestingT, ctx context.Contex
272272
},
273273
}
274274

275-
_, err := retry.DoWithRetryE(t, description, maxRetries, timeBetweenRetries, func() (string, error) {
275+
_, err := retry.DoWithRetryContextE(t, ctx, description, maxRetries, timeBetweenRetries, func() (string, error) {
276276
resp, err := client.GetInventory(ctx, input)
277277
if err != nil {
278278
return "", err
@@ -414,7 +414,7 @@ func CheckSSMCommandWithClientWithDocumentContextE(t testing.TestingT, ctx conte
414414

415415
result := &CommandOutput{}
416416

417-
_, err = retry.DoWithRetryableErrorsE(t, description, retryableErrors, maxRetries, timeBetweenRetries, func() (string, error) {
417+
_, err = retry.DoWithRetryableErrorsContextE(t, ctx, description, retryableErrors, maxRetries, timeBetweenRetries, func() (string, error) {
418418
resp, err := client.GetCommandInvocation(ctx, &ssm.GetCommandInvocationInput{
419419
CommandId: resp.Command.CommandId,
420420
InstanceId: &instanceID,

modules/aws/vpc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ func GetAzDefaultSubnetsForVpc(t testing.TestingT, vpcID string, region string)
311311
return GetAzDefaultSubnetsForVpcContext(t, context.Background(), vpcID, region)
312312
}
313313

314+
// GetAzDefaultSubnetsForVpcE gets the default az subnets in the specified VPC.
315+
//
316+
// Deprecated: Use [GetAzDefaultSubnetsForVpcContextE] instead.
317+
func GetAzDefaultSubnetsForVpcE(t testing.TestingT, vpcID string, region string) ([]Subnet, error) {
318+
return GetAzDefaultSubnetsForVpcContextE(t, context.Background(), vpcID, region)
319+
}
320+
314321
// generateVpcIDFilter is a helper method to generate vpc id filter
315322
func generateVpcIDFilter(vpcID string) types.Filter {
316323
return types.Filter{Name: aws.String(vpcIDFilterName), Values: []string{vpcID}}

modules/azure/actiongroup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GetActionGroupResourceContextE(ctx context.Context, ruleName string, resGro
3232
return nil, err
3333
}
3434

35-
client, err := CreateActionGroupClient(subscriptionID)
35+
client, err := CreateActionGroupClientContext(ctx, subscriptionID)
3636
if err != nil {
3737
return nil, err
3838
}

modules/azure/aks.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88
"github.com/stretchr/testify/require"
99
)
1010

11-
// GetManagedClustersClientE is a helper function that will setup an Azure ManagedClusters client on your behalf.
12-
func GetManagedClustersClientE(subscriptionID string) (*containerservice.ManagedClustersClient, error) {
11+
// GetManagedClustersClientContextE is a helper function that will setup an Azure ManagedClusters client on your behalf.
12+
// The ctx parameter supports cancellation and timeouts.
13+
func GetManagedClustersClientContextE(ctx context.Context, subscriptionID string) (*containerservice.ManagedClustersClient, error) {
1314
// Create a cluster client
14-
client, err := CreateManagedClustersClientE(subscriptionID)
15+
client, err := CreateManagedClustersClientContextE(ctx, subscriptionID)
1516
if err != nil {
1617
return nil, err
1718
}
@@ -27,6 +28,13 @@ func GetManagedClustersClientE(subscriptionID string) (*containerservice.Managed
2728
return &client, nil
2829
}
2930

31+
// GetManagedClustersClientE is a helper function that will setup an Azure ManagedClusters client on your behalf.
32+
//
33+
// Deprecated: Use [GetManagedClustersClientContextE] instead.
34+
func GetManagedClustersClientE(subscriptionID string) (*containerservice.ManagedClustersClient, error) {
35+
return GetManagedClustersClientContextE(context.Background(), subscriptionID)
36+
}
37+
3038
// GetManagedClusterContextE returns a ManagedCluster for the specified cluster in the given resource group.
3139
// The ctx parameter supports cancellation and timeouts.
3240
func GetManagedClusterContextE(t testing.TestingT, ctx context.Context, resourceGroupName, clusterName, subscriptionID string) (*containerservice.ManagedCluster, error) {
@@ -35,7 +43,7 @@ func GetManagedClusterContextE(t testing.TestingT, ctx context.Context, resource
3543
return nil, err
3644
}
3745

38-
client, err := GetManagedClustersClientE(subscriptionID)
46+
client, err := GetManagedClustersClientContextE(ctx, subscriptionID)
3947
if err != nil {
4048
return nil, err
4149
}

modules/azure/appService.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func GetAppServiceContextE(ctx context.Context, appName string, resGroupName str
8282
return nil, err
8383
}
8484

85-
client, err := GetAppServiceClientE(subscriptionID)
85+
client, err := GetAppServiceClientContextE(ctx, subscriptionID)
8686
if err != nil {
8787
return nil, err
8888
}
@@ -102,12 +102,20 @@ func GetAppServiceE(appName string, resGroupName string, subscriptionID string)
102102
return GetAppServiceContextE(context.Background(), appName, resGroupName, subscriptionID)
103103
}
104104

105-
// GetAppServiceClientE creates and returns an App Service web apps client.
106-
func GetAppServiceClientE(subscriptionID string) (*armappservice.WebAppsClient, error) {
105+
// GetAppServiceClientContextE creates and returns an App Service web apps client.
106+
// The ctx parameter supports cancellation and timeouts.
107+
func GetAppServiceClientContextE(_ context.Context, subscriptionID string) (*armappservice.WebAppsClient, error) {
107108
clientFactory, err := getArmAppServiceClientFactory(subscriptionID)
108109
if err != nil {
109110
return nil, err
110111
}
111112

112113
return clientFactory.NewWebAppsClient(), nil
113114
}
115+
116+
// GetAppServiceClientE creates and returns an App Service web apps client.
117+
//
118+
// Deprecated: Use [GetAppServiceClientContextE] instead.
119+
func GetAppServiceClientE(subscriptionID string) (*armappservice.WebAppsClient, error) {
120+
return GetAppServiceClientContextE(context.Background(), subscriptionID)
121+
}

0 commit comments

Comments
 (0)