diff --git a/internal/conns/awsclient.go b/internal/conns/awsclient.go index 6e5230be7a0f..93aca9b3ee53 100644 --- a/internal/conns/awsclient.go +++ b/internal/conns/awsclient.go @@ -117,40 +117,45 @@ func (c *AWSClient) PartitionHostname(ctx context.Context, prefix string) string // GlobalARN returns a global (no Region) ARN for the specified service namespace and resource. func (c *AWSClient) GlobalARN(ctx context.Context, service, resource string) string { - return c.GlobalARNWithAccount(ctx, service, c.AccountID(ctx), resource) + return c.arn(ctx, service, "", c.AccountID(ctx), resource) } // GlobalARNNoAccount returns a global (no Region) ARN for the specified service namespace and resource without AWS account ID. func (c *AWSClient) GlobalARNNoAccount(ctx context.Context, service, resource string) string { - return c.GlobalARNWithAccount(ctx, service, "", resource) + return c.arn(ctx, service, "", "", resource) } // GlobalARNWithAccount returns a global (no Region) ARN for the specified service namespace, resource and account ID. func (c *AWSClient) GlobalARNWithAccount(ctx context.Context, service, accountID, resource string) string { - return arn.ARN{ - Partition: c.Partition(ctx), - Service: service, - AccountID: accountID, - Resource: resource, - }.String() + return c.arn(ctx, service, "", accountID, resource) } // RegionalARN returns a regional ARN for the specified service namespace and resource. func (c *AWSClient) RegionalARN(ctx context.Context, service, resource string) string { - return c.RegionalARNWithAccount(ctx, service, c.AccountID(ctx), resource) + return c.arn(ctx, service, c.Region(ctx), c.AccountID(ctx), resource) } // RegionalARNNoAccount returns a regional ARN for the specified service namespace and resource without AWS account ID. func (c *AWSClient) RegionalARNNoAccount(ctx context.Context, service, resource string) string { - return c.RegionalARNWithAccount(ctx, service, "", resource) + return c.arn(ctx, service, c.Region(ctx), "", resource) } // RegionalARNWithAccount returns a regional ARN for the specified service namespace, resource and account ID. func (c *AWSClient) RegionalARNWithAccount(ctx context.Context, service, accountID, resource string) string { + return c.arn(ctx, service, c.Region(ctx), accountID, resource) +} + +// RegionalARNWithRegion returns a regional ARN for the specified service namespace, resource and account ID. +func (c *AWSClient) RegionalARNWithRegion(ctx context.Context, service, region, resource string) string { + return c.arn(ctx, service, region, c.AccountID(ctx), resource) +} + +// arn returns an ARN for the specified service namespace, region, account ID and resource. +func (c *AWSClient) arn(ctx context.Context, service, region, accountID, resource string) string { return arn.ARN{ Partition: c.Partition(ctx), Service: service, - Region: c.Region(ctx), + Region: region, AccountID: accountID, Resource: resource, }.String() diff --git a/internal/conns/awsclient_test.go b/internal/conns/awsclient_test.go index 267d8b27d1e2..7f7399f0ff86 100644 --- a/internal/conns/awsclient_test.go +++ b/internal/conns/awsclient_test.go @@ -252,3 +252,349 @@ func TestAWSClientValidateInContextRegionInPartition(t *testing.T) { // nosemgre }) } } + +func TestAWSClientGlobalARN(t *testing.T) { // nosemgrep:ci.aws-in-func-name + t.Parallel() + + ctx := t.Context() + testCases := []struct { + Name string + AWSClient *AWSClient + Service string + Resource string + Expected string + }{ + { + Name: "AWS Commercial", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: standardPartition, + }, + Service: "iam", + Resource: "policy/test", + Expected: "arn:aws:iam::123456789012:policy/test", //lintignore:AWSAT003,AWSAT005 + }, + { + Name: "AWS China", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: chinaPartition, + }, + Service: "iam", + Resource: "policy/test", + Expected: "arn:aws-cn:iam::123456789012:policy/test", //lintignore:AWSAT003,AWSAT005 + }, + } + + for _, testCase := range testCases { + t.Run(testCase.Name, func(t *testing.T) { + t.Parallel() + + got := testCase.AWSClient.GlobalARN(ctx, testCase.Service, testCase.Resource) + + if got != testCase.Expected { + t.Errorf("got %s, expected %s", got, testCase.Expected) + } + }) + } +} + +func TestAWSClientGlobalARNNoAccount(t *testing.T) { // nosemgrep:ci.aws-in-func-name + t.Parallel() + + ctx := t.Context() + testCases := []struct { + Name string + AWSClient *AWSClient + Service string + Resource string + Expected string + }{ + { + Name: "AWS Commercial", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: standardPartition, + }, + Service: "s3", + Resource: "bucket/test", + Expected: "arn:aws:s3:::bucket/test", //lintignore:AWSAT003,AWSAT005 + }, + { + Name: "AWS China", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: chinaPartition, + }, + Service: "s3", + Resource: "bucket/test", + Expected: "arn:aws-cn:s3:::bucket/test", //lintignore:AWSAT003,AWSAT005 + }, + } + + for _, testCase := range testCases { + t.Run(testCase.Name, func(t *testing.T) { + t.Parallel() + + got := testCase.AWSClient.GlobalARNNoAccount(ctx, testCase.Service, testCase.Resource) + + if got != testCase.Expected { + t.Errorf("got %s, expected %s", got, testCase.Expected) + } + }) + } +} + +func TestAWSClientGlobalARNWithAccount(t *testing.T) { // nosemgrep:ci.aws-in-func-name + t.Parallel() + + ctx := t.Context() + testCases := []struct { + Name string + AWSClient *AWSClient + Service string + Resource string + Expected string + }{ + { + Name: "AWS Commercial", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: standardPartition, + }, + Service: "iam", + Resource: "policy/test", + Expected: "arn:aws:iam::234567890123:policy/test", //lintignore:AWSAT003,AWSAT005 + }, + { + Name: "AWS China", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: chinaPartition, + }, + Service: "iam", + Resource: "policy/test", + Expected: "arn:aws-cn:iam::234567890123:policy/test", //lintignore:AWSAT003,AWSAT005 + }, + } + + for _, testCase := range testCases { + t.Run(testCase.Name, func(t *testing.T) { + t.Parallel() + + got := testCase.AWSClient.GlobalARNWithAccount(ctx, testCase.Service, "234567890123", testCase.Resource) + + if got != testCase.Expected { + t.Errorf("got %s, expected %s", got, testCase.Expected) + } + }) + } +} + +func TestAWSClientRegionalARN(t *testing.T) { // nosemgrep:ci.aws-in-func-name + t.Parallel() + + ctx := t.Context() + testCases := []struct { + Name string + AWSClient *AWSClient + Service string + Resource string + Expected string + }{ + { + Name: "AWS Commercial", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: standardPartition, + awsConfig: &aws.Config{ + Region: "us-west-2", //lintignore:AWSAT003 + }, + }, + Service: "ec2", + Resource: "vpc/test", + Expected: "arn:aws:ec2:us-west-2:123456789012:vpc/test", //lintignore:AWSAT003,AWSAT005 + }, + { + Name: "AWS China", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: chinaPartition, + awsConfig: &aws.Config{ + Region: "cn-northwest-1", //lintignore:AWSAT003 + }, + }, + Service: "ec2", + Resource: "vpc/test", + Expected: "arn:aws-cn:ec2:cn-northwest-1:123456789012:vpc/test", //lintignore:AWSAT003,AWSAT005 + }, + } + + for _, testCase := range testCases { + t.Run(testCase.Name, func(t *testing.T) { + t.Parallel() + + got := testCase.AWSClient.RegionalARN(ctx, testCase.Service, testCase.Resource) + + if got != testCase.Expected { + t.Errorf("got %s, expected %s", got, testCase.Expected) + } + }) + } +} + +func TestAWSClientRegionalARNNoAccount(t *testing.T) { // nosemgrep:ci.aws-in-func-name + t.Parallel() + + ctx := t.Context() + testCases := []struct { + Name string + AWSClient *AWSClient + Service string + Resource string + Expected string + }{ + { + Name: "AWS Commercial", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: standardPartition, + awsConfig: &aws.Config{ + Region: "us-west-2", //lintignore:AWSAT003 + }, + }, + Service: "ec2", + Resource: "vpc/test", + Expected: "arn:aws:ec2:us-west-2::vpc/test", //lintignore:AWSAT003,AWSAT005 + }, + { + Name: "AWS China", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: chinaPartition, + awsConfig: &aws.Config{ + Region: "cn-northwest-1", //lintignore:AWSAT003 + }, + }, + Service: "ec2", + Resource: "vpc/test", + Expected: "arn:aws-cn:ec2:cn-northwest-1::vpc/test", //lintignore:AWSAT003,AWSAT005 + }, + } + + for _, testCase := range testCases { + t.Run(testCase.Name, func(t *testing.T) { + t.Parallel() + + got := testCase.AWSClient.RegionalARNNoAccount(ctx, testCase.Service, testCase.Resource) + + if got != testCase.Expected { + t.Errorf("got %s, expected %s", got, testCase.Expected) + } + }) + } +} + +func TestAWSClientRegionalARNWithAccount(t *testing.T) { // nosemgrep:ci.aws-in-func-name + t.Parallel() + + ctx := t.Context() + testCases := []struct { + Name string + AWSClient *AWSClient + Service string + Resource string + Expected string + }{ + { + Name: "AWS Commercial", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: standardPartition, + awsConfig: &aws.Config{ + Region: "us-west-2", //lintignore:AWSAT003 + }, + }, + Service: "ec2", + Resource: "vpc/test", + Expected: "arn:aws:ec2:us-west-2:234567890123:vpc/test", //lintignore:AWSAT003,AWSAT005 + }, + { + Name: "AWS China", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: chinaPartition, + awsConfig: &aws.Config{ + Region: "cn-northwest-1", //lintignore:AWSAT003 + }, + }, + Service: "ec2", + Resource: "vpc/test", + Expected: "arn:aws-cn:ec2:cn-northwest-1:234567890123:vpc/test", //lintignore:AWSAT003,AWSAT005 + }, + } + + for _, testCase := range testCases { + t.Run(testCase.Name, func(t *testing.T) { + t.Parallel() + + got := testCase.AWSClient.RegionalARNWithAccount(ctx, testCase.Service, "234567890123", testCase.Resource) + + if got != testCase.Expected { + t.Errorf("got %s, expected %s", got, testCase.Expected) + } + }) + } +} + +func TestAWSClientRegionalARNWithRegion(t *testing.T) { // nosemgrep:ci.aws-in-func-name + t.Parallel() + + ctx := t.Context() + testCases := []struct { + Name string + AWSClient *AWSClient + Service string + Resource string + Expected string + }{ + { + Name: "AWS Commercial", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: standardPartition, + awsConfig: &aws.Config{ + Region: "us-west-2", //lintignore:AWSAT003 + }, + }, + Service: "ec2", + Resource: "vpc/test", + Expected: "arn:aws:ec2:region-1:123456789012:vpc/test", //lintignore:AWSAT003,AWSAT005 + }, + { + Name: "AWS China", + AWSClient: &AWSClient{ + accountID: "123456789012", + partition: chinaPartition, + awsConfig: &aws.Config{ + Region: "cn-northwest-1", //lintignore:AWSAT003 + }, + }, + Service: "ec2", + Resource: "vpc/test", + Expected: "arn:aws-cn:ec2:region-1:123456789012:vpc/test", //lintignore:AWSAT003,AWSAT005 + }, + } + + for _, testCase := range testCases { + t.Run(testCase.Name, func(t *testing.T) { + t.Parallel() + + got := testCase.AWSClient.RegionalARNWithRegion(ctx, testCase.Service, "region-1", testCase.Resource) + + if got != testCase.Expected { + t.Errorf("got %s, expected %s", got, testCase.Expected) + } + }) + } +} diff --git a/internal/retry/op.go b/internal/retry/op.go index f37ff06e7e6c..58ed1b95c123 100644 --- a/internal/retry/op.go +++ b/internal/retry/op.go @@ -9,7 +9,6 @@ import ( "time" "github.com/hashicorp/terraform-provider-aws/internal/backoff" - inttypes "github.com/hashicorp/terraform-provider-aws/internal/types" ) type opFunc[T any] func(context.Context) (T, error) @@ -87,33 +86,31 @@ func (op opFunc[T]) If(predicate predicateFunc[T]) runFunc[T] { return func(ctx context.Context, timeout time.Duration, opts ...backoff.Option) (T, error) { // We explicitly don't set a deadline on the context here to maintain compatibility // with the Plugin SDKv2 implementation. A parent context may have set a deadline. - var l *backoff.Loop + var ( + l *backoff.Loop + t T + err error + ) for l = backoff.NewLoopWithOptions(timeout, opts...); l.Continue(ctx); { - t, err := op(ctx) + t, err = op(ctx) if retry, err := predicate(t, err); !retry { return t, err } } - var err error - if l.Remaining() == 0 { - err = inttypes.ErrDeadlineExceeded - } else { - err = context.Cause(ctx) - } - - if errors.Is(err, inttypes.ErrDeadlineExceeded) || errors.Is(err, context.DeadlineExceeded) { - err = &TimeoutError{ - // LastError must be nil for `TimedOut` to return true. - // LastError: err, - LastState: "retryableerror", - Timeout: timeout, - ExpectedState: []string{"success"}, + if err == nil { + if l.Remaining() == 0 || errors.Is(err, context.Cause(ctx)) { + err = &TimeoutError{ + // LastError must be nil for `TimedOut` to return true. + // LastError: err, + LastState: "retryableerror", + Timeout: timeout, + ExpectedState: []string{"success"}, + } } } - var zero T - return zero, err + return t, err } } diff --git a/internal/service/appautoscaling/exports_test.go b/internal/service/appautoscaling/exports_test.go index 2e6d1d5fb39c..0eed3b411ae4 100644 --- a/internal/service/appautoscaling/exports_test.go +++ b/internal/service/appautoscaling/exports_test.go @@ -11,5 +11,6 @@ var ( FindScalingPolicyByFourPartKey = findScalingPolicyByFourPartKey FindScheduledActionByFourPartKey = findScheduledActionByFourPartKey + FindTargetByThreePartKey = findTargetByThreePartKey ValidPolicyImportInput = validPolicyImportInput ) diff --git a/internal/service/appautoscaling/target.go b/internal/service/appautoscaling/target.go index e2a95b7151a8..5d2a0866638b 100644 --- a/internal/service/appautoscaling/target.go +++ b/internal/service/appautoscaling/target.go @@ -141,9 +141,9 @@ func resourceTargetRead(ctx context.Context, d *schema.ResourceData, meta any) d var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppAutoScalingClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, 2*time.Minute, - func() (any, error) { - return FindTargetByThreePartKey(ctx, conn, d.Id(), d.Get("service_namespace").(string), d.Get("scalable_dimension").(string)) + t, err := tfresource.RetryWhenNewResourceNotFound(ctx, 2*time.Minute, + func(ctx context.Context) (*awstypes.ScalableTarget, error) { + return findTargetByThreePartKey(ctx, conn, d.Id(), d.Get("service_namespace").(string), d.Get("scalable_dimension").(string)) }, d.IsNewResource(), ) @@ -158,8 +158,6 @@ func resourceTargetRead(ctx context.Context, d *schema.ResourceData, meta any) d return sdkdiag.AppendErrorf(diags, "reading Application AutoScaling Target (%s): %s", d.Id(), err) } - t := outputRaw.(*awstypes.ScalableTarget) - d.Set(names.AttrARN, t.ScalableTargetARN) d.Set(names.AttrMaxCapacity, t.MaxCapacity) d.Set("min_capacity", t.MinCapacity) @@ -227,7 +225,7 @@ func resourceTargetDelete(ctx context.Context, d *schema.ResourceData, meta any) } _, err = tfresource.RetryUntilNotFound(ctx, 5*time.Minute, func(ctx context.Context) (any, error) { - return FindTargetByThreePartKey(ctx, conn, d.Id(), d.Get("service_namespace").(string), d.Get("scalable_dimension").(string)) + return findTargetByThreePartKey(ctx, conn, d.Id(), d.Get("service_namespace").(string), d.Get("scalable_dimension").(string)) }) if err != nil { @@ -237,7 +235,7 @@ func resourceTargetDelete(ctx context.Context, d *schema.ResourceData, meta any) return diags } -func FindTargetByThreePartKey(ctx context.Context, conn *applicationautoscaling.Client, resourceID, namespace, dimension string) (*awstypes.ScalableTarget, error) { +func findTargetByThreePartKey(ctx context.Context, conn *applicationautoscaling.Client, resourceID, namespace, dimension string) (*awstypes.ScalableTarget, error) { input := applicationautoscaling.DescribeScalableTargetsInput{ ResourceIds: []string{resourceID}, ScalableDimension: awstypes.ScalableDimension(dimension), diff --git a/internal/service/appmesh/gateway_route.go b/internal/service/appmesh/gateway_route.go index 5109d2460949..76f2546651aa 100644 --- a/internal/service/appmesh/gateway_route.go +++ b/internal/service/appmesh/gateway_route.go @@ -539,7 +539,7 @@ func resourceGatewayRouteRead(ctx context.Context, d *schema.ResourceData, meta var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppMeshClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + gatewayRoute, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.GatewayRouteData, error) { return findGatewayRouteByFourPartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get("virtual_gateway_name").(string), d.Get(names.AttrName).(string)) }, d.IsNewResource()) @@ -553,8 +553,6 @@ func resourceGatewayRouteRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "reading App Mesh Gateway Route (%s): %s", d.Id(), err) } - gatewayRoute := outputRaw.(*awstypes.GatewayRouteData) - d.Set(names.AttrARN, gatewayRoute.Metadata.Arn) d.Set(names.AttrCreatedDate, gatewayRoute.Metadata.CreatedAt.Format(time.RFC3339)) d.Set(names.AttrLastUpdatedDate, gatewayRoute.Metadata.LastUpdatedAt.Format(time.RFC3339)) diff --git a/internal/service/appmesh/mesh.go b/internal/service/appmesh/mesh.go index fa4f42bb8254..3a3f30c78db6 100644 --- a/internal/service/appmesh/mesh.go +++ b/internal/service/appmesh/mesh.go @@ -147,7 +147,7 @@ func resourceMeshRead(ctx context.Context, d *schema.ResourceData, meta any) dia var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppMeshClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + mesh, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.MeshData, error) { return findMeshByTwoPartKey(ctx, conn, d.Id(), d.Get("mesh_owner").(string)) }, d.IsNewResource()) @@ -161,8 +161,6 @@ func resourceMeshRead(ctx context.Context, d *schema.ResourceData, meta any) dia return sdkdiag.AppendErrorf(diags, "reading App Mesh Service Mesh (%s): %s", d.Id(), err) } - mesh := outputRaw.(*awstypes.MeshData) - d.Set(names.AttrARN, mesh.Metadata.Arn) d.Set(names.AttrCreatedDate, mesh.Metadata.CreatedAt.Format(time.RFC3339)) d.Set(names.AttrLastUpdatedDate, mesh.Metadata.LastUpdatedAt.Format(time.RFC3339)) diff --git a/internal/service/appmesh/route.go b/internal/service/appmesh/route.go index 7a95bbf61e31..53ca01d22833 100644 --- a/internal/service/appmesh/route.go +++ b/internal/service/appmesh/route.go @@ -778,7 +778,7 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta any) di var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppMeshClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + route, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.RouteData, error) { return findRouteByFourPartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get("virtual_router_name").(string), d.Get(names.AttrName).(string)) }, d.IsNewResource()) @@ -792,8 +792,6 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta any) di return sdkdiag.AppendErrorf(diags, "reading App Mesh Route (%s): %s", d.Id(), err) } - route := outputRaw.(*awstypes.RouteData) - d.Set(names.AttrARN, route.Metadata.Arn) d.Set(names.AttrCreatedDate, route.Metadata.CreatedAt.Format(time.RFC3339)) d.Set(names.AttrLastUpdatedDate, route.Metadata.LastUpdatedAt.Format(time.RFC3339)) diff --git a/internal/service/appmesh/virtual_gateway.go b/internal/service/appmesh/virtual_gateway.go index 764a737a3f10..0f9d839c52e5 100644 --- a/internal/service/appmesh/virtual_gateway.go +++ b/internal/service/appmesh/virtual_gateway.go @@ -687,7 +687,7 @@ func resourceVirtualGatewayRead(ctx context.Context, d *schema.ResourceData, met var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppMeshClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + virtualGateway, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.VirtualGatewayData, error) { return findVirtualGatewayByThreePartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get(names.AttrName).(string)) }, d.IsNewResource()) @@ -701,8 +701,6 @@ func resourceVirtualGatewayRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading App Mesh Virtual Gateway (%s): %s", d.Id(), err) } - virtualGateway := outputRaw.(*awstypes.VirtualGatewayData) - d.Set(names.AttrARN, virtualGateway.Metadata.Arn) d.Set(names.AttrCreatedDate, virtualGateway.Metadata.CreatedAt.Format(time.RFC3339)) d.Set(names.AttrLastUpdatedDate, virtualGateway.Metadata.LastUpdatedAt.Format(time.RFC3339)) diff --git a/internal/service/appmesh/virtual_node.go b/internal/service/appmesh/virtual_node.go index 081dccbb0875..068de1ed2e3a 100644 --- a/internal/service/appmesh/virtual_node.go +++ b/internal/service/appmesh/virtual_node.go @@ -1004,7 +1004,7 @@ func resourceVirtualNodeRead(ctx context.Context, d *schema.ResourceData, meta a var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppMeshClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + vn, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.VirtualNodeData, error) { return findVirtualNodeByThreePartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get(names.AttrName).(string)) }, d.IsNewResource()) @@ -1018,8 +1018,6 @@ func resourceVirtualNodeRead(ctx context.Context, d *schema.ResourceData, meta a return sdkdiag.AppendErrorf(diags, "reading App Mesh Virtual Node (%s): %s", d.Id(), err) } - vn := outputRaw.(*awstypes.VirtualNodeData) - d.Set(names.AttrARN, vn.Metadata.Arn) d.Set(names.AttrCreatedDate, vn.Metadata.CreatedAt.Format(time.RFC3339)) d.Set(names.AttrLastUpdatedDate, vn.Metadata.LastUpdatedAt.Format(time.RFC3339)) diff --git a/internal/service/appmesh/virtual_router.go b/internal/service/appmesh/virtual_router.go index eaefc9a2832b..978e9826dbce 100644 --- a/internal/service/appmesh/virtual_router.go +++ b/internal/service/appmesh/virtual_router.go @@ -165,7 +165,7 @@ func resourceVirtualRouterRead(ctx context.Context, d *schema.ResourceData, meta var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppMeshClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + vr, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.VirtualRouterData, error) { return findVirtualRouterByThreePartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get(names.AttrName).(string)) }, d.IsNewResource()) @@ -179,8 +179,6 @@ func resourceVirtualRouterRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "reading App Mesh Virtual Router (%s): %s", d.Id(), err) } - vr := outputRaw.(*awstypes.VirtualRouterData) - d.Set(names.AttrARN, vr.Metadata.Arn) d.Set(names.AttrCreatedDate, vr.Metadata.CreatedAt.Format(time.RFC3339)) d.Set(names.AttrLastUpdatedDate, vr.Metadata.LastUpdatedAt.Format(time.RFC3339)) diff --git a/internal/service/appmesh/virtual_service.go b/internal/service/appmesh/virtual_service.go index efaa51f57276..33a47e749d5d 100644 --- a/internal/service/appmesh/virtual_service.go +++ b/internal/service/appmesh/virtual_service.go @@ -173,7 +173,7 @@ func resourceVirtualServiceRead(ctx context.Context, d *schema.ResourceData, met var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppMeshClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + vs, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.VirtualServiceData, error) { return findVirtualServiceByThreePartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get(names.AttrName).(string)) }, d.IsNewResource()) @@ -187,8 +187,6 @@ func resourceVirtualServiceRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading App Mesh Virtual Service (%s): %s", d.Id(), err) } - vs := outputRaw.(*awstypes.VirtualServiceData) - d.Set(names.AttrARN, vs.Metadata.Arn) d.Set(names.AttrCreatedDate, vs.Metadata.CreatedAt.Format(time.RFC3339)) d.Set(names.AttrLastUpdatedDate, vs.Metadata.LastUpdatedAt.Format(time.RFC3339)) diff --git a/internal/service/cloudtrail/trail.go b/internal/service/cloudtrail/trail.go index f1ca579288ce..83011b861f92 100644 --- a/internal/service/cloudtrail/trail.go +++ b/internal/service/cloudtrail/trail.go @@ -363,7 +363,7 @@ func resourceTrailRead(ctx context.Context, d *schema.ResourceData, meta any) di var diags diag.Diagnostics conn := meta.(*conns.AWSClient).CloudTrailClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + trail, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*types.Trail, error) { return findTrailByARN(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -377,7 +377,6 @@ func resourceTrailRead(ctx context.Context, d *schema.ResourceData, meta any) di return sdkdiag.AppendErrorf(diags, "reading CloudTrail Trail (%s): %s", d.Id(), err) } - trail := outputRaw.(*types.Trail) d.Set(names.AttrARN, trail.TrailARN) d.Set("cloud_watch_logs_group_arn", trail.CloudWatchLogsLogGroupArn) d.Set("cloud_watch_logs_role_arn", trail.CloudWatchLogsRoleArn) diff --git a/internal/service/ec2/ebs_snapshot_block_public_access.go b/internal/service/ec2/ebs_snapshot_block_public_access.go index 9dc8c1aad11f..2dfde4599246 100644 --- a/internal/service/ec2/ebs_snapshot_block_public_access.go +++ b/internal/service/ec2/ebs_snapshot_block_public_access.go @@ -7,7 +7,7 @@ import ( "context" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -32,7 +32,7 @@ func resourceEBSSnapshotBlockPublicAccess() *schema.Resource { names.AttrState: { Type: schema.TypeString, Required: true, - ValidateDiagFunc: enum.Validate[types.SnapshotBlockPublicAccessState](), + ValidateDiagFunc: enum.Validate[awstypes.SnapshotBlockPublicAccessState](), }, }, } @@ -44,7 +44,7 @@ func resourceEBSSnapshotBlockPublicAccessPut(ctx context.Context, d *schema.Reso state := d.Get(names.AttrState).(string) input := ec2.EnableSnapshotBlockPublicAccessInput{ - State: types.SnapshotBlockPublicAccessState(state), + State: awstypes.SnapshotBlockPublicAccessState(state), } _, err := conn.EnableSnapshotBlockPublicAccess(ctx, &input) diff --git a/internal/service/ec2/ebs_snapshot_block_public_access_test.go b/internal/service/ec2/ebs_snapshot_block_public_access_test.go index 3804057aefc9..aff77260772c 100644 --- a/internal/service/ec2/ebs_snapshot_block_public_access_test.go +++ b/internal/service/ec2/ebs_snapshot_block_public_access_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/plancheck" @@ -47,7 +47,7 @@ func testAccEC2EBSSnapshotBlockPublicAccess_basic(t *testing.T) { Steps: []resource.TestStep{ { ResourceName: resourceName, - Config: testAccEBSSnapshotBlockPublicAccess_basic(string(types.SnapshotBlockPublicAccessStateBlockAllSharing)), + Config: testAccEBSSnapshotBlockPublicAccess_basic(string(awstypes.SnapshotBlockPublicAccessStateBlockAllSharing)), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, names.AttrState, "block-all-sharing"), ), @@ -59,7 +59,7 @@ func testAccEC2EBSSnapshotBlockPublicAccess_basic(t *testing.T) { }, { ResourceName: resourceName, - Config: testAccEBSSnapshotBlockPublicAccess_basic(string(types.SnapshotBlockPublicAccessStateBlockNewSharing)), + Config: testAccEBSSnapshotBlockPublicAccess_basic(string(awstypes.SnapshotBlockPublicAccessStateBlockNewSharing)), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, names.AttrState, "block-new-sharing"), ), @@ -146,8 +146,8 @@ func testAccCheckEBSSnapshotBlockPublicAccessDestroy(ctx context.Context) resour return err } - if response.State != types.SnapshotBlockPublicAccessStateUnblocked { - return fmt.Errorf("EBS encryption by default is not in expected state (%s)", types.SnapshotBlockPublicAccessStateUnblocked) + if response.State != awstypes.SnapshotBlockPublicAccessStateUnblocked { + return fmt.Errorf("EBS encryption by default is not in expected state (%s)", awstypes.SnapshotBlockPublicAccessStateUnblocked) } return nil } diff --git a/internal/service/ec2/ebs_snapshot_import.go b/internal/service/ec2/ebs_snapshot_import.go index 2ccdbade9002..d9adc9b5fda8 100644 --- a/internal/service/ec2/ebs_snapshot_import.go +++ b/internal/service/ec2/ebs_snapshot_import.go @@ -5,12 +5,10 @@ package ec2 import ( "context" - "fmt" "log" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -270,7 +268,8 @@ func resourceEBSSnapshotImportCreate(ctx context.Context, d *schema.ResourceData func resourceEBSSnapshotImportRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) snapshot, err := findSnapshotByID(ctx, conn, d.Id()) @@ -284,13 +283,7 @@ func resourceEBSSnapshotImportRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "reading EBS Snapshot (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - Resource: fmt.Sprintf("snapshot/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, ebsSnapshotARN(ctx, c, d.Id())) d.Set("data_encryption_key_id", snapshot.DataEncryptionKeyId) d.Set(names.AttrDescription, snapshot.Description) d.Set(names.AttrEncrypted, snapshot.Encrypted) diff --git a/internal/service/ec2/ec2_ami.go b/internal/service/ec2/ec2_ami.go index f895b90d43d9..071c282ba618 100644 --- a/internal/service/ec2/ec2_ami.go +++ b/internal/service/ec2/ec2_ami.go @@ -12,7 +12,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -401,9 +400,10 @@ func resourceAMICreate(ctx context.Context, d *schema.ResourceData, meta any) di func resourceAMIRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + image, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.Image, error) { return findImageByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -417,8 +417,6 @@ func resourceAMIRead(ctx context.Context, d *schema.ResourceData, meta any) diag return sdkdiag.AppendErrorf(diags, "reading EC2 AMI (%s): %s", d.Id(), err) } - image := outputRaw.(*awstypes.Image) - if image.State == awstypes.ImageStatePending { // This could happen if a user manually adds an image we didn't create // to the state. We'll wait for the image to become available @@ -433,13 +431,7 @@ func resourceAMIRead(ctx context.Context, d *schema.ResourceData, meta any) diag } d.Set("architecture", image.Architecture) - imageArn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Region: meta.(*conns.AWSClient).Region(ctx), - Resource: fmt.Sprintf("image/%s", d.Id()), - Service: names.EC2, - }.String() - d.Set(names.AttrARN, imageArn) + d.Set(names.AttrARN, amiARN(ctx, c, d.Id())) d.Set("boot_mode", image.BootMode) d.Set(names.AttrDescription, image.Description) d.Set("deprecation_time", image.DeprecationTime) @@ -897,3 +889,6 @@ func waitImageDeprecationTimeDisabled(ctx context.Context, conn *ec2.Client, ima }, ) } +func amiARN(ctx context.Context, c *conns.AWSClient, imageID string) string { + return c.RegionalARNNoAccount(ctx, names.EC2, "image/"+imageID) +} diff --git a/internal/service/ec2/ec2_ami_data_source.go b/internal/service/ec2/ec2_ami_data_source.go index 0e63d1f28951..3c88da876bb4 100644 --- a/internal/service/ec2/ec2_ami_data_source.go +++ b/internal/service/ec2/ec2_ami_data_source.go @@ -5,13 +5,11 @@ package ec2 import ( "context" - "fmt" "slices" "time" "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -243,7 +241,8 @@ func dataSourceAMI() *schema.Resource { func dataSourceAMIRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) describeImagesInput := ec2.DescribeImagesInput{ IncludeDeprecated: aws.Bool(d.Get("include_deprecated").(bool)), @@ -306,13 +305,7 @@ func dataSourceAMIRead(ctx context.Context, d *schema.ResourceData, meta any) di d.SetId(aws.ToString(image.ImageId)) d.Set("architecture", image.Architecture) - imageArn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Region: meta.(*conns.AWSClient).Region(ctx), - Service: names.EC2, - Resource: fmt.Sprintf("image/%s", d.Id()), - }.String() - d.Set(names.AttrARN, imageArn) + d.Set(names.AttrARN, amiARN(ctx, c, d.Id())) if err := d.Set("block_device_mappings", flattenAMIBlockDeviceMappings(image.BlockDeviceMappings)); err != nil { return sdkdiag.AppendErrorf(diags, "setting block_device_mappings: %s", err) } diff --git a/internal/service/ec2/ec2_eip.go b/internal/service/ec2/ec2_eip.go index 569ac56d29ab..d0ac6df09610 100644 --- a/internal/service/ec2/ec2_eip.go +++ b/internal/service/ec2/ec2_eip.go @@ -13,7 +13,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -86,7 +86,7 @@ func resourceEIP() *schema.Resource { ForceNew: true, Optional: true, Computed: true, - ValidateDiagFunc: enum.Validate[types.DomainType](), + ValidateDiagFunc: enum.Validate[awstypes.DomainType](), }, "instance": { Type: schema.TypeString, @@ -147,7 +147,7 @@ func resourceEIPCreate(ctx context.Context, d *schema.ResourceData, meta any) di conn := meta.(*conns.AWSClient).EC2Client(ctx) input := ec2.AllocateAddressInput{ - TagSpecifications: getTagSpecificationsIn(ctx, types.ResourceTypeElasticIp), + TagSpecifications: getTagSpecificationsIn(ctx, awstypes.ResourceTypeElasticIp), } if v, ok := d.GetOk(names.AttrAddress); ok { @@ -159,7 +159,7 @@ func resourceEIPCreate(ctx context.Context, d *schema.ResourceData, meta any) di } if v := d.Get(names.AttrDomain); v != nil && v.(string) != "" { - input.Domain = types.DomainType(v.(string)) + input.Domain = awstypes.DomainType(v.(string)) } if v, ok := d.GetOk("ipam_pool_id"); ok { @@ -209,10 +209,10 @@ func resourceEIPRead(ctx context.Context, d *schema.ResourceData, meta any) diag conn := meta.(*conns.AWSClient).EC2Client(ctx) if !eipID(d.Id()).IsVPC() { - return sdkdiag.AppendErrorf(diags, `with the retirement of EC2-Classic %s domain EC2 EIPs are no longer supported`, types.DomainTypeStandard) + return sdkdiag.AppendErrorf(diags, `with the retirement of EC2-Classic %s domain EC2 EIPs are no longer supported`, awstypes.DomainTypeStandard) } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + address, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.Address, error) { return findEIPByAllocationID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -226,7 +226,6 @@ func resourceEIPRead(ctx context.Context, d *schema.ResourceData, meta any) diag return sdkdiag.AppendErrorf(diags, "reading EC2 EIP (%s): %s", d.Id(), err) } - address := outputRaw.(*types.Address) allocationID := aws.ToString(address.AllocationId) d.Set("allocation_id", allocationID) d.Set(names.AttrARN, eipARN(ctx, meta.(*conns.AWSClient), allocationID)) @@ -253,7 +252,7 @@ func resourceEIPRead(ctx context.Context, d *schema.ResourceData, meta any) diag // Force ID to be an Allocation ID if we're on a VPC. // This allows users to import the EIP based on the IP if they are in a VPC. - if address.Domain == types.DomainTypeVpc && net.ParseIP(d.Id()) != nil { + if address.Domain == awstypes.DomainTypeVpc && net.ParseIP(d.Id()) != nil { d.SetId(aws.ToString(address.AllocationId)) } @@ -304,7 +303,7 @@ func resourceEIPDelete(ctx context.Context, d *schema.ResourceData, meta any) di conn := meta.(*conns.AWSClient).EC2Client(ctx) if !eipID(d.Id()).IsVPC() { - return sdkdiag.AppendErrorf(diags, `with the retirement of EC2-Classic %s domain EC2 EIPs are no longer supported`, types.DomainTypeStandard) + return sdkdiag.AppendErrorf(diags, `with the retirement of EC2-Classic %s domain EC2 EIPs are no longer supported`, awstypes.DomainTypeStandard) } // If we are attached to an instance or interface, detach first. @@ -432,7 +431,7 @@ func eipARN(ctx context.Context, c *conns.AWSClient, allocationID string) string return c.RegionalARN(ctx, names.EC2, "elastic-ip/"+allocationID) } -func findIPAMPoolAllocationsForEIP(ctx context.Context, conn *ec2.Client, ipamPoolID, eipAllocationID string) ([]types.IpamPoolAllocation, error) { +func findIPAMPoolAllocationsForEIP(ctx context.Context, conn *ec2.Client, ipamPoolID, eipAllocationID string) ([]awstypes.IpamPoolAllocation, error) { input := ec2.GetIpamPoolAllocationsInput{ IpamPoolId: aws.String(ipamPoolID), } @@ -443,8 +442,8 @@ func findIPAMPoolAllocationsForEIP(ctx context.Context, conn *ec2.Client, ipamPo return nil, err } - output = tfslices.Filter(output, func(v types.IpamPoolAllocation) bool { - return v.ResourceType == types.IpamPoolAllocationResourceTypeEip && aws.ToString(v.ResourceId) == eipAllocationID + output = tfslices.Filter(output, func(v awstypes.IpamPoolAllocation) bool { + return v.ResourceType == awstypes.IpamPoolAllocationResourceTypeEip && aws.ToString(v.ResourceId) == eipAllocationID }) if len(output) == 0 { diff --git a/internal/service/ec2/ec2_eip_association.go b/internal/service/ec2/ec2_eip_association.go index 9b7e299c9c48..3347dc4cfc77 100644 --- a/internal/service/ec2/ec2_eip_association.go +++ b/internal/service/ec2/ec2_eip_association.go @@ -10,7 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -147,7 +147,7 @@ func resourceEIPAssociationRead(ctx context.Context, d *schema.ResourceData, met conn := meta.(*conns.AWSClient).EC2Client(ctx) if !eipAssociationID(d.Id()).IsVPC() { - return sdkdiag.AppendErrorf(diags, `with the retirement of EC2-Classic %s domain EC2 EIPs are no longer supported`, types.DomainTypeStandard) + return sdkdiag.AppendErrorf(diags, `with the retirement of EC2-Classic %s domain EC2 EIPs are no longer supported`, awstypes.DomainTypeStandard) } address, err := findEIPByAssociationID(ctx, conn, d.Id()) @@ -176,7 +176,7 @@ func resourceEIPAssociationDelete(ctx context.Context, d *schema.ResourceData, m conn := meta.(*conns.AWSClient).EC2Client(ctx) if !eipAssociationID(d.Id()).IsVPC() { - return sdkdiag.AppendErrorf(diags, `with the retirement of EC2-Classic %s domain EC2 EIPs are no longer supported`, types.DomainTypeStandard) + return sdkdiag.AppendErrorf(diags, `with the retirement of EC2-Classic %s domain EC2 EIPs are no longer supported`, awstypes.DomainTypeStandard) } input := ec2.DisassociateAddressInput{ diff --git a/internal/service/ec2/ec2_eip_association_test.go b/internal/service/ec2/ec2_eip_association_test.go index 6e0e0e1250b6..7e9d9ed50696 100644 --- a/internal/service/ec2/ec2_eip_association_test.go +++ b/internal/service/ec2/ec2_eip_association_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccEC2EIPAssociation_basic(t *testing.T) { ctx := acctest.Context(t) - var a types.Address + var a awstypes.Address resourceName := "aws_eip_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -50,7 +50,7 @@ func TestAccEC2EIPAssociation_basic(t *testing.T) { func TestAccEC2EIPAssociation_disappears(t *testing.T) { ctx := acctest.Context(t) - var a types.Address + var a awstypes.Address resourceName := "aws_eip_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -74,7 +74,7 @@ func TestAccEC2EIPAssociation_disappears(t *testing.T) { func TestAccEC2EIPAssociation_instance_basic(t *testing.T) { ctx := acctest.Context(t) - var a types.Address + var a awstypes.Address resourceName := "aws_eip_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -103,7 +103,7 @@ func TestAccEC2EIPAssociation_instance_basic(t *testing.T) { func TestAccEC2EIPAssociation_instance_publicIP(t *testing.T) { ctx := acctest.Context(t) - var a types.Address + var a awstypes.Address resourceName := "aws_eip_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -132,7 +132,7 @@ func TestAccEC2EIPAssociation_instance_publicIP(t *testing.T) { func TestAccEC2EIPAssociation_networkInterface(t *testing.T) { ctx := acctest.Context(t) - var a types.Address + var a awstypes.Address resourceName := "aws_eip_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -166,7 +166,7 @@ func TestAccEC2EIPAssociation_networkInterface(t *testing.T) { func TestAccEC2EIPAssociation_spotInstance(t *testing.T) { ctx := acctest.Context(t) - var a types.Address + var a awstypes.Address resourceName := "aws_eip_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) publicKey, _, err := sdkacctest.RandSSHKeyPair(acctest.DefaultEmailAddress) @@ -202,7 +202,7 @@ func TestAccEC2EIPAssociation_spotInstance(t *testing.T) { }) } -func testAccCheckEIPAssociationExists(ctx context.Context, n string, v *types.Address) resource.TestCheckFunc { +func testAccCheckEIPAssociationExists(ctx context.Context, n string, v *awstypes.Address) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/internal/service/ec2/ec2_eip_data_source.go b/internal/service/ec2/ec2_eip_data_source.go index acb769f6662d..5d72e075d826 100644 --- a/internal/service/ec2/ec2_eip_data_source.go +++ b/internal/service/ec2/ec2_eip_data_source.go @@ -10,7 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -141,7 +141,7 @@ func dataSourceEIPRead(ctx context.Context, d *schema.ResourceData, meta any) di return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("EC2 EIP", err)) } - if eip.Domain == types.DomainTypeVpc { + if eip.Domain == awstypes.DomainTypeVpc { allocationID := aws.ToString(eip.AllocationId) d.SetId(allocationID) d.Set(names.AttrARN, eipARN(ctx, meta.(*conns.AWSClient), allocationID)) diff --git a/internal/service/ec2/ec2_eip_test.go b/internal/service/ec2/ec2_eip_test.go index bd9482419894..c4643e812723 100644 --- a/internal/service/ec2/ec2_eip_test.go +++ b/internal/service/ec2/ec2_eip_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/plancheck" @@ -24,7 +24,7 @@ import ( func TestAccEC2EIP_basic(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" resource.ParallelTest(t, resource.TestCase{ @@ -55,7 +55,7 @@ func TestAccEC2EIP_basic(t *testing.T) { func TestAccEC2EIP_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" resource.ParallelTest(t, resource.TestCase{ @@ -83,7 +83,7 @@ func TestAccEC2EIP_disappears(t *testing.T) { func TestAccEC2EIP_migrateVPCToDomain(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" resource.ParallelTest(t, resource.TestCase{ @@ -124,7 +124,7 @@ func TestAccEC2EIP_migrateVPCToDomain(t *testing.T) { func TestAccEC2EIP_noVPC(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" resource.ParallelTest(t, resource.TestCase{ @@ -153,7 +153,7 @@ func TestAccEC2EIP_noVPC(t *testing.T) { func TestAccEC2EIP_tags(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" resource.ParallelTest(t, resource.TestCase{ @@ -198,7 +198,7 @@ func TestAccEC2EIP_tags(t *testing.T) { func TestAccEC2EIP_instance(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address instanceResourceName := "aws_instance.test" resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -230,7 +230,7 @@ func TestAccEC2EIP_instance(t *testing.T) { // https://github.com/hashicorp/terraform-provider-aws/issues/42) func TestAccEC2EIP_Instance_reassociate(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address instanceResourceName := "aws_instance.test" resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -264,7 +264,7 @@ func TestAccEC2EIP_Instance_reassociate(t *testing.T) { // associated Private EIPs of two instances func TestAccEC2EIP_Instance_associatedUserPrivateIP(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address instance1ResourceName := "aws_instance.test.1" instance2ResourceName := "aws_instance.test.0" resourceName := "aws_eip.test" @@ -306,7 +306,7 @@ func TestAccEC2EIP_Instance_associatedUserPrivateIP(t *testing.T) { func TestAccEC2EIP_Instance_notAssociated(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address instanceResourceName := "aws_instance.test" resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -346,7 +346,7 @@ func TestAccEC2EIP_Instance_notAssociated(t *testing.T) { func TestAccEC2EIP_networkInterface(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -377,7 +377,7 @@ func TestAccEC2EIP_networkInterface(t *testing.T) { func TestAccEC2EIP_NetworkInterface_twoEIPsOneInterface(t *testing.T) { ctx := acctest.Context(t) - var one, two types.Address + var one, two awstypes.Address resource1Name := "aws_eip.test.0" resource2Name := "aws_eip.test.1" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -406,7 +406,7 @@ func TestAccEC2EIP_NetworkInterface_twoEIPsOneInterface(t *testing.T) { func TestAccEC2EIP_association(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address instanceResourceName := "aws_instance.test" eniResourceName := "aws_network_interface.test" resourceName := "aws_eip.test" @@ -454,7 +454,7 @@ func TestAccEC2EIP_association(t *testing.T) { func TestAccEC2EIP_PublicIPv4Pool_default(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -489,7 +489,7 @@ func TestAccEC2EIP_PublicIPv4Pool_custom(t *testing.T) { t.Skipf("Environment variable %s is not set", key) } - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -518,7 +518,7 @@ func TestAccEC2EIP_PublicIPv4Pool_custom(t *testing.T) { func TestAccEC2EIP_PublicIPv4Pool_IPAMPoolId(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" ipamPoolDataSourceName := "aws_vpc_ipam_pool.test_pool" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -543,7 +543,7 @@ func TestAccEC2EIP_PublicIPv4Pool_IPAMPoolId(t *testing.T) { func TestAccEC2EIP_customerOwnedIPv4Pool(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -572,7 +572,7 @@ func TestAccEC2EIP_customerOwnedIPv4Pool(t *testing.T) { func TestAccEC2EIP_networkBorderGroup(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -602,7 +602,7 @@ func TestAccEC2EIP_networkBorderGroup(t *testing.T) { func TestAccEC2EIP_carrierIP(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -632,7 +632,7 @@ func TestAccEC2EIP_carrierIP(t *testing.T) { func TestAccEC2EIP_BYOIPAddress_default(t *testing.T) { ctx := acctest.Context(t) - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -661,7 +661,7 @@ func TestAccEC2EIP_BYOIPAddress_custom(t *testing.T) { t.Skipf("Environment variable %s is not set", key) } - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -696,7 +696,7 @@ func TestAccEC2EIP_BYOIPAddress_customWithPublicIPv4Pool(t *testing.T) { t.Skipf("Environment variable %s is not set", key) } - var conf types.Address + var conf awstypes.Address resourceName := "aws_eip.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -718,7 +718,7 @@ func TestAccEC2EIP_BYOIPAddress_customWithPublicIPv4Pool(t *testing.T) { }) } -func testAccCheckEIPExists(ctx context.Context, n string, v *types.Address) resource.TestCheckFunc { +func testAccCheckEIPExists(ctx context.Context, n string, v *awstypes.Address) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/internal/service/ec2/ec2_eips_data_source.go b/internal/service/ec2/ec2_eips_data_source.go index c28793b73837..278cbd1b689d 100644 --- a/internal/service/ec2/ec2_eips_data_source.go +++ b/internal/service/ec2/ec2_eips_data_source.go @@ -9,7 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -77,7 +77,7 @@ func dataSourceEIPsRead(ctx context.Context, d *schema.ResourceData, meta any) d for _, v := range output { publicIPs = append(publicIPs, aws.ToString(v.PublicIp)) - if v.Domain == types.DomainTypeVpc { + if v.Domain == awstypes.DomainTypeVpc { allocationIDs = append(allocationIDs, aws.ToString(v.AllocationId)) } } diff --git a/internal/service/ec2/ec2_fleet.go b/internal/service/ec2/ec2_fleet.go index 07b8e397bd13..735f1bc6c32e 100644 --- a/internal/service/ec2/ec2_fleet.go +++ b/internal/service/ec2/ec2_fleet.go @@ -6,13 +6,11 @@ package ec2 import ( "context" "errors" - "fmt" "log" "strconv" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -808,7 +806,8 @@ func resourceFleetCreate(ctx context.Context, d *schema.ResourceData, meta any) func resourceFleetRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) fleet, err := findFleetByID(ctx, conn, d.Id()) @@ -822,14 +821,7 @@ func resourceFleetRead(ctx context.Context, d *schema.ResourceData, meta any) di return sdkdiag.AppendErrorf(diags, "reading EC2 Fleet (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("fleet/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, fleetARN(ctx, c, d.Id())) d.Set("context", fleet.Context) d.Set("excess_capacity_termination_policy", fleet.ExcessCapacityTerminationPolicy) if fleet.Instances != nil { @@ -1626,3 +1618,6 @@ func flattenTargetCapacitySpecification(apiObject *awstypes.TargetCapacitySpecif return tfMap } +func fleetARN(ctx context.Context, c *conns.AWSClient, fleetID string) string { + return c.RegionalARN(ctx, names.EC2, "fleet/"+fleetID) +} diff --git a/internal/service/ec2/ec2_host.go b/internal/service/ec2/ec2_host.go index aab08293a773..e5a3f31479a3 100644 --- a/internal/service/ec2/ec2_host.go +++ b/internal/service/ec2/ec2_host.go @@ -5,12 +5,10 @@ package ec2 import ( "context" - "fmt" "log" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -145,7 +143,8 @@ func resourceHostCreate(ctx context.Context, d *schema.ResourceData, meta any) d func resourceHostRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) host, err := findHostByID(ctx, conn, d.Id()) @@ -159,14 +158,7 @@ func resourceHostRead(ctx context.Context, d *schema.ResourceData, meta any) dia return sdkdiag.AppendErrorf(diags, "reading EC2 Host (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: aws.ToString(host.OwnerId), - Resource: fmt.Sprintf("dedicated-host/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, hostARN(ctx, c, aws.ToString(host.OwnerId), d.Id())) d.Set("asset_id", host.AssetId) d.Set("auto_placement", host.AutoPlacement) d.Set(names.AttrAvailabilityZone, host.AvailabilityZone) @@ -252,3 +244,6 @@ func resourceHostDelete(ctx context.Context, d *schema.ResourceData, meta any) d return diags } +func hostARN(ctx context.Context, c *conns.AWSClient, ownerID, hostID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, ownerID, "dedicated-host/"+hostID) +} diff --git a/internal/service/ec2/ec2_host_data_source.go b/internal/service/ec2/ec2_host_data_source.go index 7a54386e5bb0..d17fe7b9cda9 100644 --- a/internal/service/ec2/ec2_host_data_source.go +++ b/internal/service/ec2/ec2_host_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -93,7 +91,8 @@ func dataSourceHost() *schema.Resource { func dataSourceHostRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := ec2.DescribeHostsInput{ Filter: newCustomFilterList(d.Get(names.AttrFilter).(*schema.Set)), @@ -115,14 +114,7 @@ func dataSourceHostRead(ctx context.Context, d *schema.ResourceData, meta any) d } d.SetId(aws.ToString(host.HostId)) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: aws.ToString(host.OwnerId), - Resource: fmt.Sprintf("dedicated-host/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, hostARN(ctx, c, aws.ToString(host.OwnerId), d.Id())) d.Set("asset_id", host.AssetId) d.Set("auto_placement", host.AutoPlacement) d.Set(names.AttrAvailabilityZone, host.AvailabilityZone) diff --git a/internal/service/ec2/ec2_image_block_public_access.go b/internal/service/ec2/ec2_image_block_public_access.go index 290e7d881935..619174714a4e 100644 --- a/internal/service/ec2/ec2_image_block_public_access.go +++ b/internal/service/ec2/ec2_image_block_public_access.go @@ -10,7 +10,7 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -58,7 +58,7 @@ func resourceImageBlockPublicAccessPut(ctx context.Context, d *schema.ResourceDa if slices.Contains(imageBlockPublicAccessEnabledState_Values(), state) { input := ec2.EnableImageBlockPublicAccessInput{ - ImageBlockPublicAccessState: types.ImageBlockPublicAccessEnabledState(state), + ImageBlockPublicAccessState: awstypes.ImageBlockPublicAccessEnabledState(state), } _, err := conn.EnableImageBlockPublicAccess(ctx, &input) @@ -109,11 +109,11 @@ func resourceImageBlockPublicAccessRead(ctx context.Context, d *schema.ResourceD } func imageBlockPublicAccessDisabledState_Values() []string { - return enum.Values[types.ImageBlockPublicAccessDisabledState]() + return enum.Values[awstypes.ImageBlockPublicAccessDisabledState]() } func imageBlockPublicAccessEnabledState_Values() []string { - return enum.Values[types.ImageBlockPublicAccessEnabledState]() + return enum.Values[awstypes.ImageBlockPublicAccessEnabledState]() } func imageBlockPublicAccessState_Values() []string { diff --git a/internal/service/ec2/ec2_instance.go b/internal/service/ec2/ec2_instance.go index c326912e663d..d1a817409a2d 100644 --- a/internal/service/ec2/ec2_instance.go +++ b/internal/service/ec2/ec2_instance.go @@ -19,7 +19,6 @@ import ( "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -1155,7 +1154,8 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta an func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) instance, err := findInstanceByID(ctx, conn, d.Id()) @@ -1396,14 +1396,7 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta any) // ARN - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Region: meta.(*conns.AWSClient).Region(ctx), - Service: names.EC2, - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("instance/%s", d.Id()), - } - d.Set(names.AttrARN, arn.String()) + d.Set(names.AttrARN, instanceARN(ctx, c, d.Id())) // Instance attributes { @@ -4121,3 +4114,6 @@ func hasCommonElement(slice1 []awstypes.ArchitectureType, slice2 []awstypes.Arch } return false } +func instanceARN(ctx context.Context, c *conns.AWSClient, instanceID string) string { + return c.RegionalARN(ctx, names.EC2, "instance/"+instanceID) +} diff --git a/internal/service/ec2/ec2_instance_data_source.go b/internal/service/ec2/ec2_instance_data_source.go index 00943041fab6..e84540d0a89b 100644 --- a/internal/service/ec2/ec2_instance_data_source.go +++ b/internal/service/ec2/ec2_instance_data_source.go @@ -11,7 +11,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -408,7 +407,8 @@ func dataSourceInstance() *schema.Resource { // dataSourceInstanceRead performs the instanceID lookup func dataSourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) // Build up search parameters input := ec2.DescribeInstancesInput{} @@ -451,14 +451,7 @@ func dataSourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta an } // ARN - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Region: meta.(*conns.AWSClient).Region(ctx), - Service: names.EC2, - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("instance/%s", d.Id()), - } - d.Set(names.AttrARN, arn.String()) + d.Set(names.AttrARN, instanceARN(ctx, c, d.Id())) return diags } diff --git a/internal/service/ec2/ec2_key_pair.go b/internal/service/ec2/ec2_key_pair.go index 124b52ba7234..63370f54150b 100644 --- a/internal/service/ec2/ec2_key_pair.go +++ b/internal/service/ec2/ec2_key_pair.go @@ -10,9 +10,8 @@ import ( "strings" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -104,7 +103,7 @@ func resourceKeyPairCreate(ctx context.Context, d *schema.ResourceData, meta any input := ec2.ImportKeyPairInput{ KeyName: aws.String(keyName), PublicKeyMaterial: []byte(d.Get(names.AttrPublicKey).(string)), - TagSpecifications: getTagSpecificationsIn(ctx, types.ResourceTypeKeyPair), + TagSpecifications: getTagSpecificationsIn(ctx, awstypes.ResourceTypeKeyPair), } output, err := conn.ImportKeyPair(ctx, &input) @@ -120,7 +119,8 @@ func resourceKeyPairCreate(ctx context.Context, d *schema.ResourceData, meta any func resourceKeyPairRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) keyPair, err := findKeyPairByName(ctx, conn, d.Id()) @@ -134,14 +134,7 @@ func resourceKeyPairRead(ctx context.Context, d *schema.ResourceData, meta any) return sdkdiag.AppendErrorf(diags, "reading EC2 Key Pair (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: "key-pair/" + d.Id(), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, keyPairARN(ctx, c, d.Id())) d.Set("fingerprint", keyPair.KeyFingerprint) d.Set("key_name", keyPair.KeyName) d.Set("key_name_prefix", create.NamePrefixFromName(aws.ToString(keyPair.KeyName))) @@ -195,3 +188,6 @@ func openSSHPublicKeysEqual(v1, v2 string) bool { return key1.Type() == key2.Type() && bytes.Equal(key1.Marshal(), key2.Marshal()) } +func keyPairARN(ctx context.Context, c *conns.AWSClient, keyName string) string { + return c.RegionalARN(ctx, names.EC2, "key-pair/"+keyName) +} diff --git a/internal/service/ec2/ec2_key_pair_data_source.go b/internal/service/ec2/ec2_key_pair_data_source.go index efb1b56cbf97..f1c05aa670d2 100644 --- a/internal/service/ec2/ec2_key_pair_data_source.go +++ b/internal/service/ec2/ec2_key_pair_data_source.go @@ -8,7 +8,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -72,7 +71,8 @@ func dataSourceKeyPair() *schema.Resource { func dataSourceKeyPairRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := ec2.DescribeKeyPairsInput{} @@ -100,14 +100,7 @@ func dataSourceKeyPairRead(ctx context.Context, d *schema.ResourceData, meta any d.SetId(aws.ToString(keyPair.KeyPairId)) keyName := aws.ToString(keyPair.KeyName) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: "ec2", - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: "key-pair/" + keyName, - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, keyPairARN(ctx, c, keyName)) d.Set(names.AttrCreateTime, aws.ToTime(keyPair.CreateTime).Format(time.RFC3339)) d.Set("fingerprint", keyPair.KeyFingerprint) d.Set("include_public_key", input.IncludePublicKey) diff --git a/internal/service/ec2/ec2_key_pair_test.go b/internal/service/ec2/ec2_key_pair_test.go index b9b0484dc76e..b376dbac5bff 100644 --- a/internal/service/ec2/ec2_key_pair_test.go +++ b/internal/service/ec2/ec2_key_pair_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccEC2KeyPair_basic(t *testing.T) { ctx := acctest.Context(t) - var keyPair types.KeyPairInfo + var keyPair awstypes.KeyPairInfo resourceName := "aws_key_pair.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -60,7 +60,7 @@ func TestAccEC2KeyPair_basic(t *testing.T) { func TestAccEC2KeyPair_tags(t *testing.T) { ctx := acctest.Context(t) - var keyPair types.KeyPairInfo + var keyPair awstypes.KeyPairInfo resourceName := "aws_key_pair.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -112,7 +112,7 @@ func TestAccEC2KeyPair_tags(t *testing.T) { func TestAccEC2KeyPair_nameGenerated(t *testing.T) { ctx := acctest.Context(t) - var keyPair types.KeyPairInfo + var keyPair awstypes.KeyPairInfo resourceName := "aws_key_pair.test" publicKey, _, err := sdkacctest.RandSSHKeyPair(acctest.DefaultEmailAddress) @@ -146,7 +146,7 @@ func TestAccEC2KeyPair_nameGenerated(t *testing.T) { func TestAccEC2KeyPair_namePrefix(t *testing.T) { ctx := acctest.Context(t) - var keyPair types.KeyPairInfo + var keyPair awstypes.KeyPairInfo resourceName := "aws_key_pair.test" publicKey, _, err := sdkacctest.RandSSHKeyPair(acctest.DefaultEmailAddress) @@ -180,7 +180,7 @@ func TestAccEC2KeyPair_namePrefix(t *testing.T) { func TestAccEC2KeyPair_disappears(t *testing.T) { ctx := acctest.Context(t) - var keyPair types.KeyPairInfo + var keyPair awstypes.KeyPairInfo resourceName := "aws_key_pair.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -233,7 +233,7 @@ func testAccCheckKeyPairDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckKeyPairExists(ctx context.Context, n string, v *types.KeyPairInfo) resource.TestCheckFunc { +func testAccCheckKeyPairExists(ctx context.Context, n string, v *awstypes.KeyPairInfo) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/internal/service/ec2/ec2_launch_template.go b/internal/service/ec2/ec2_launch_template.go index e7b8760bcdd3..a9ffc2cd5caf 100644 --- a/internal/service/ec2/ec2_launch_template.go +++ b/internal/service/ec2/ec2_launch_template.go @@ -10,7 +10,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -1059,7 +1058,8 @@ func resourceLaunchTemplateCreate(ctx context.Context, d *schema.ResourceData, m func resourceLaunchTemplateRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) lt, err := findLaunchTemplateByID(ctx, conn, d.Id()) @@ -1079,14 +1079,7 @@ func resourceLaunchTemplateRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading EC2 Launch Template (%s) Version (%s): %s", d.Id(), version, err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("launch-template/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, launchTemplateARN(ctx, c, d.Id())) d.Set("default_version", lt.DefaultVersionNumber) d.Set(names.AttrDescription, ltv.VersionDescription) d.Set("latest_version", lt.LatestVersionNumber) @@ -3234,3 +3227,6 @@ func flattenLaunchTemplateEnaSrdUdpSpecification(apiObject *awstypes.LaunchTempl return tfMap } +func launchTemplateARN(ctx context.Context, c *conns.AWSClient, templateID string) string { + return c.RegionalARN(ctx, names.EC2, "launch-template/"+templateID) +} diff --git a/internal/service/ec2/ec2_launch_template_data_source.go b/internal/service/ec2/ec2_launch_template_data_source.go index f2e4f96c22dd..1fee63c40e68 100644 --- a/internal/service/ec2/ec2_launch_template_data_source.go +++ b/internal/service/ec2/ec2_launch_template_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -791,7 +789,8 @@ func dataSourceLaunchTemplate() *schema.Resource { func dataSourceLaunchTemplateRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := ec2.DescribeLaunchTemplatesInput{} @@ -828,14 +827,7 @@ func dataSourceLaunchTemplateRead(ctx context.Context, d *schema.ResourceData, m return sdkdiag.AppendErrorf(diags, "reading EC2 Launch Template (%s) Version (%s): %s", d.Id(), version, err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("launch-template/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, launchTemplateARN(ctx, c, d.Id())) d.Set("default_version", lt.DefaultVersionNumber) d.Set(names.AttrDescription, ltv.VersionDescription) d.Set("latest_version", lt.LatestVersionNumber) diff --git a/internal/service/ec2/ec2_placement_group.go b/internal/service/ec2/ec2_placement_group.go index d62308221e26..2b9928c705c3 100644 --- a/internal/service/ec2/ec2_placement_group.go +++ b/internal/service/ec2/ec2_placement_group.go @@ -9,7 +9,6 @@ import ( "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -119,7 +118,8 @@ func resourcePlacementGroupCreate(ctx context.Context, d *schema.ResourceData, m func resourcePlacementGroupRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) pg, err := findPlacementGroupByName(ctx, conn, d.Id()) @@ -133,14 +133,7 @@ func resourcePlacementGroupRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading EC2 Placement Group (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("placement-group/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, placementGroupARN(ctx, c, d.Id())) d.Set(names.AttrName, pg.GroupName) d.Set("partition_count", pg.PartitionCount) d.Set("placement_group_id", pg.GroupId) @@ -202,3 +195,6 @@ func resourcePlacementGroupCustomizeDiff(_ context.Context, diff *schema.Resourc return nil } +func placementGroupARN(ctx context.Context, c *conns.AWSClient, groupName string) string { + return c.RegionalARN(ctx, names.EC2, "placement-group/"+groupName) +} diff --git a/internal/service/ec2/ec2_spot_instance_request.go b/internal/service/ec2/ec2_spot_instance_request.go index 45042f5d4b0d..984accdb13d1 100644 --- a/internal/service/ec2/ec2_spot_instance_request.go +++ b/internal/service/ec2/ec2_spot_instance_request.go @@ -229,7 +229,7 @@ func resourceSpotInstanceRequestRead(ctx context.Context, d *schema.ResourceData var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + request, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.SpotInstanceRequest, error) { return findSpotInstanceRequestByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -243,8 +243,6 @@ func resourceSpotInstanceRequestRead(ctx context.Context, d *schema.ResourceData return sdkdiag.AppendErrorf(diags, "reading EC2 Spot Instance Request (%s): %s", d.Id(), err) } - request := outputRaw.(*awstypes.SpotInstanceRequest) - d.Set("spot_bid_status", request.Status.Code) // Instance ID is not set if the request is still pending if request.InstanceId != nil { diff --git a/internal/service/ec2/outposts_local_gateway_route.go b/internal/service/ec2/outposts_local_gateway_route.go index ee135c0d380e..927163038190 100644 --- a/internal/service/ec2/outposts_local_gateway_route.go +++ b/internal/service/ec2/outposts_local_gateway_route.go @@ -90,7 +90,7 @@ func resourceLocalGatewayRouteRead(ctx context.Context, d *schema.ResourceData, const ( timeout = 1 * time.Minute ) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, timeout, func() (any, error) { + localGatewayRoute, err := tfresource.RetryWhenNewResourceNotFound(ctx, timeout, func(ctx context.Context) (*awstypes.LocalGatewayRoute, error) { return findLocalGatewayRouteByTwoPartKey(ctx, conn, localGatewayRouteTableID, destination) }, d.IsNewResource()) @@ -104,8 +104,6 @@ func resourceLocalGatewayRouteRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "reading EC2 Local Gateway Route (%s): %s", d.Id(), err) } - localGatewayRoute := outputRaw.(*awstypes.LocalGatewayRoute) - d.Set("destination_cidr_block", localGatewayRoute.DestinationCidrBlock) d.Set("local_gateway_virtual_interface_group_id", localGatewayRoute.LocalGatewayVirtualInterfaceGroupId) d.Set("local_gateway_route_table_id", localGatewayRoute.LocalGatewayRouteTableId) diff --git a/internal/service/ec2/transitgateway_attachment_data_source.go b/internal/service/ec2/transitgateway_attachment_data_source.go index a7b9e14b0562..a3148c941049 100644 --- a/internal/service/ec2/transitgateway_attachment_data_source.go +++ b/internal/service/ec2/transitgateway_attachment_data_source.go @@ -5,10 +5,8 @@ package ec2 import ( "context" - "fmt" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -76,7 +74,8 @@ func dataSourceTransitGatewayAttachment() *schema.Resource { func dataSourceTransitGatewayAttachmentRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeTransitGatewayAttachmentsInput{} @@ -103,14 +102,7 @@ func dataSourceTransitGatewayAttachmentRead(ctx context.Context, d *schema.Resou d.SetId(transitGatewayAttachmentID) resourceOwnerID := aws.ToString(transitGatewayAttachment.ResourceOwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: resourceOwnerID, - Resource: fmt.Sprintf("transit-gateway-attachment/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayAttachmentARN(ctx, c, resourceOwnerID, d.Id())) if v := transitGatewayAttachment.Association; v != nil { d.Set("association_state", v.State) d.Set("association_transit_gateway_route_table_id", v.TransitGatewayRouteTableId) diff --git a/internal/service/ec2/transitgateway_connect_peer.go b/internal/service/ec2/transitgateway_connect_peer.go index aec2ae4ce636..9bf281c828b5 100644 --- a/internal/service/ec2/transitgateway_connect_peer.go +++ b/internal/service/ec2/transitgateway_connect_peer.go @@ -5,14 +5,12 @@ package ec2 import ( "context" - "fmt" "log" "strconv" "time" "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -161,7 +159,8 @@ func resourceTransitGatewayConnectPeerCreate(ctx context.Context, d *schema.Reso func resourceTransitGatewayConnectPeerRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) transitGatewayConnectPeer, err := findTransitGatewayConnectPeerByID(ctx, conn, d.Id()) @@ -175,15 +174,8 @@ func resourceTransitGatewayConnectPeerRead(ctx context.Context, d *schema.Resour return sdkdiag.AppendErrorf(diags, "reading EC2 Transit Gateway Connect Peer (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("transit-gateway-connect-peer/%s", d.Id()), - }.String() bgpConfigurations := transitGatewayConnectPeer.ConnectPeerConfiguration.BgpConfigurations - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayConnectPeerARN(ctx, c, d.Id())) d.Set("bgp_asn", strconv.FormatInt(aws.ToInt64(bgpConfigurations[0].PeerAsn), 10)) d.Set("bgp_peer_address", bgpConfigurations[0].PeerAddress) d.Set("bgp_transit_gateway_addresses", slices.ApplyToAll(bgpConfigurations, func(v awstypes.TransitGatewayAttachmentBgpConfiguration) string { @@ -229,3 +221,7 @@ func resourceTransitGatewayConnectPeerDelete(ctx context.Context, d *schema.Reso return diags } + +func transitGatewayConnectPeerARN(ctx context.Context, c *conns.AWSClient, connectPeerID string) string { + return c.RegionalARN(ctx, names.EC2, "transit-gateway-connect-peer/"+connectPeerID) +} diff --git a/internal/service/ec2/transitgateway_connect_peer_data_source.go b/internal/service/ec2/transitgateway_connect_peer_data_source.go index 36bb52ad70f2..aa11772ca687 100644 --- a/internal/service/ec2/transitgateway_connect_peer_data_source.go +++ b/internal/service/ec2/transitgateway_connect_peer_data_source.go @@ -5,12 +5,10 @@ package ec2 import ( "context" - "fmt" "strconv" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -82,7 +80,8 @@ func dataSourceTransitGatewayConnectPeer() *schema.Resource { func dataSourceTransitGatewayConnectPeerRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeTransitGatewayConnectPeersInput{} @@ -102,15 +101,8 @@ func dataSourceTransitGatewayConnectPeerRead(ctx context.Context, d *schema.Reso d.SetId(aws.ToString(transitGatewayConnectPeer.TransitGatewayConnectPeerId)) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("transit-gateway-connect-peer/%s", d.Id()), - }.String() bgpConfigurations := transitGatewayConnectPeer.ConnectPeerConfiguration.BgpConfigurations - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayConnectPeerARN(ctx, c, d.Id())) d.Set("bgp_asn", strconv.FormatInt(aws.ToInt64(bgpConfigurations[0].PeerAsn), 10)) d.Set("bgp_peer_address", bgpConfigurations[0].PeerAddress) d.Set("bgp_transit_gateway_addresses", slices.ApplyToAll(bgpConfigurations, func(v awstypes.TransitGatewayAttachmentBgpConfiguration) string { diff --git a/internal/service/ec2/transitgateway_dx_gateway_attachment_data_source.go b/internal/service/ec2/transitgateway_dx_gateway_attachment_data_source.go index 4fadcac83cee..b7340fcf059c 100644 --- a/internal/service/ec2/transitgateway_dx_gateway_attachment_data_source.go +++ b/internal/service/ec2/transitgateway_dx_gateway_attachment_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -53,7 +51,8 @@ func dataSourceTransitGatewayDxGatewayAttachment() *schema.Resource { func dataSourceTransitGatewayDxGatewayAttachmentRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeTransitGatewayAttachmentsInput{ Filters: newAttributeFilterList(map[string]string{ @@ -92,14 +91,7 @@ func dataSourceTransitGatewayDxGatewayAttachmentRead(ctx context.Context, d *sch d.SetId(aws.ToString(transitGatewayAttachment.TransitGatewayAttachmentId)) resourceOwnerID := aws.ToString(transitGatewayAttachment.ResourceOwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: resourceOwnerID, - Resource: fmt.Sprintf("transit-gateway-attachment/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayAttachmentARN(ctx, c, resourceOwnerID, d.Id())) d.Set("dx_gateway_id", transitGatewayAttachment.ResourceId) d.Set(names.AttrTransitGatewayID, transitGatewayAttachment.TransitGatewayId) diff --git a/internal/service/ec2/transitgateway_multicast_group_member.go b/internal/service/ec2/transitgateway_multicast_group_member.go index 77c811f35bdf..89396d327056 100644 --- a/internal/service/ec2/transitgateway_multicast_group_member.go +++ b/internal/service/ec2/transitgateway_multicast_group_member.go @@ -85,7 +85,7 @@ func resourceTransitGatewayMulticastGroupMemberRead(ctx context.Context, d *sche return sdkdiag.AppendFromErr(diags, err) } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + multicastGroup, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.TransitGatewayMulticastGroup, error) { return findTransitGatewayMulticastGroupMemberByThreePartKey(ctx, conn, multicastDomainID, groupIPAddress, eniID) }, d.IsNewResource()) @@ -99,8 +99,6 @@ func resourceTransitGatewayMulticastGroupMemberRead(ctx context.Context, d *sche return sdkdiag.AppendErrorf(diags, "reading EC2 Transit Gateway Multicast Group Member (%s): %s", d.Id(), err) } - multicastGroup := outputRaw.(*awstypes.TransitGatewayMulticastGroup) - d.Set("group_ip_address", multicastGroup.GroupIpAddress) d.Set(names.AttrNetworkInterfaceID, multicastGroup.NetworkInterfaceId) d.Set("transit_gateway_multicast_domain_id", multicastDomainID) diff --git a/internal/service/ec2/transitgateway_multicast_group_source.go b/internal/service/ec2/transitgateway_multicast_group_source.go index fdf328ef0226..44eb3a50302a 100644 --- a/internal/service/ec2/transitgateway_multicast_group_source.go +++ b/internal/service/ec2/transitgateway_multicast_group_source.go @@ -87,7 +87,7 @@ func resourceTransitGatewayMulticastGroupSourceRead(ctx context.Context, d *sche return sdkdiag.AppendFromErr(diags, err) } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + multicastGroup, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.TransitGatewayMulticastGroup, error) { return findTransitGatewayMulticastGroupSourceByThreePartKey(ctx, conn, multicastDomainID, groupIPAddress, eniID) }, d.IsNewResource()) @@ -101,8 +101,6 @@ func resourceTransitGatewayMulticastGroupSourceRead(ctx context.Context, d *sche return sdkdiag.AppendErrorf(diags, "reading EC2 Transit Gateway Multicast Group Source (%s): %s", d.Id(), err) } - multicastGroup := outputRaw.(*awstypes.TransitGatewayMulticastGroup) - d.Set("group_ip_address", multicastGroup.GroupIpAddress) d.Set(names.AttrNetworkInterfaceID, multicastGroup.NetworkInterfaceId) d.Set("transit_gateway_multicast_domain_id", multicastDomainID) diff --git a/internal/service/ec2/transitgateway_peering_attachment.go b/internal/service/ec2/transitgateway_peering_attachment.go index 7edac317781c..a4d5726e2954 100644 --- a/internal/service/ec2/transitgateway_peering_attachment.go +++ b/internal/service/ec2/transitgateway_peering_attachment.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -128,7 +126,8 @@ func resourceTransitGatewayPeeringAttachmentCreate(ctx context.Context, d *schem func resourceTransitGatewayPeeringAttachmentRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) transitGatewayPeeringAttachment, err := findTransitGatewayPeeringAttachmentByID(ctx, conn, d.Id()) @@ -143,14 +142,7 @@ func resourceTransitGatewayPeeringAttachmentRead(ctx context.Context, d *schema. } resourceOwnerID := aws.ToString(transitGatewayPeeringAttachment.RequesterTgwInfo.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: resourceOwnerID, - Resource: fmt.Sprintf("transit-gateway-attachment/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayAttachmentARN(ctx, c, resourceOwnerID, d.Id())) d.Set("peer_account_id", transitGatewayPeeringAttachment.AccepterTgwInfo.OwnerId) d.Set("peer_region", transitGatewayPeeringAttachment.AccepterTgwInfo.Region) d.Set("peer_transit_gateway_id", transitGatewayPeeringAttachment.AccepterTgwInfo.TransitGatewayId) diff --git a/internal/service/ec2/transitgateway_peering_attachment_data_source.go b/internal/service/ec2/transitgateway_peering_attachment_data_source.go index f5e6ada76b9d..e68222c908c0 100644 --- a/internal/service/ec2/transitgateway_peering_attachment_data_source.go +++ b/internal/service/ec2/transitgateway_peering_attachment_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -69,7 +67,8 @@ func dataSourceTransitGatewayPeeringAttachment() *schema.Resource { func dataSourceTransitGatewayPeeringAttachmentRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeTransitGatewayPeeringAttachmentsInput{} @@ -109,14 +108,7 @@ func dataSourceTransitGatewayPeeringAttachmentRead(ctx context.Context, d *schem } resourceOwnerID := aws.ToString(local.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: resourceOwnerID, - Resource: fmt.Sprintf("transit-gateway-attachment/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayAttachmentARN(ctx, c, resourceOwnerID, d.Id())) d.Set("peer_account_id", peer.OwnerId) d.Set("peer_region", peer.Region) d.Set("peer_transit_gateway_id", peer.TransitGatewayId) diff --git a/internal/service/ec2/transitgateway_policy_table.go b/internal/service/ec2/transitgateway_policy_table.go index dd3569983c3d..3ceacb773405 100644 --- a/internal/service/ec2/transitgateway_policy_table.go +++ b/internal/service/ec2/transitgateway_policy_table.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -86,7 +84,8 @@ func resourceTransitGatewayPolicyTableCreate(ctx context.Context, d *schema.Reso func resourceTransitGatewayPolicyTableRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) transitGatewayPolicyTable, err := findTransitGatewayPolicyTableByID(ctx, conn, d.Id()) @@ -100,14 +99,7 @@ func resourceTransitGatewayPolicyTableRead(ctx context.Context, d *schema.Resour return sdkdiag.AppendErrorf(diags, "reading EC2 Transit Gateway Policy Table (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("transit-gateway-policy-table/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayPolicyTableARN(ctx, c, d.Id())) d.Set(names.AttrState, transitGatewayPolicyTable.State) d.Set(names.AttrTransitGatewayID, transitGatewayPolicyTable.TransitGatewayId) @@ -148,3 +140,7 @@ func resourceTransitGatewayPolicyTableDelete(ctx context.Context, d *schema.Reso return diags } + +func transitGatewayPolicyTableARN(ctx context.Context, c *conns.AWSClient, policyTableID string) string { + return c.RegionalARN(ctx, names.EC2, "transit-gateway-policy-table/"+policyTableID) +} diff --git a/internal/service/ec2/transitgateway_route.go b/internal/service/ec2/transitgateway_route.go index 325c3ca4520e..c0d306c0d545 100644 --- a/internal/service/ec2/transitgateway_route.go +++ b/internal/service/ec2/transitgateway_route.go @@ -102,7 +102,7 @@ func resourceTransitGatewayRouteRead(ctx context.Context, d *schema.ResourceData return sdkdiag.AppendFromErr(diags, err) } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + transitGatewayRoute, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.TransitGatewayRoute, error) { return findTransitGatewayStaticRoute(ctx, conn, transitGatewayRouteTableID, destination) }, d.IsNewResource()) @@ -116,8 +116,6 @@ func resourceTransitGatewayRouteRead(ctx context.Context, d *schema.ResourceData return sdkdiag.AppendErrorf(diags, "reading EC2 Transit Gateway Route (%s): %s", d.Id(), err) } - transitGatewayRoute := outputRaw.(*awstypes.TransitGatewayRoute) - d.Set("destination_cidr_block", transitGatewayRoute.DestinationCidrBlock) if len(transitGatewayRoute.TransitGatewayAttachments) > 0 { d.Set(names.AttrTransitGatewayAttachmentID, transitGatewayRoute.TransitGatewayAttachments[0].TransitGatewayAttachmentId) diff --git a/internal/service/ec2/transitgateway_route_table.go b/internal/service/ec2/transitgateway_route_table.go index aa66c21904ba..6eb706e5cd18 100644 --- a/internal/service/ec2/transitgateway_route_table.go +++ b/internal/service/ec2/transitgateway_route_table.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -89,7 +87,8 @@ func resourceTransitGatewayRouteTableCreate(ctx context.Context, d *schema.Resou func resourceTransitGatewayRouteTableRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) transitGatewayRouteTable, err := findTransitGatewayRouteTableByID(ctx, conn, d.Id()) @@ -103,14 +102,7 @@ func resourceTransitGatewayRouteTableRead(ctx context.Context, d *schema.Resourc return sdkdiag.AppendErrorf(diags, "reading EC2 Transit Gateway Route Table (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("transit-gateway-route-table/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayRouteTableARN(ctx, c, d.Id())) d.Set("default_association_route_table", transitGatewayRouteTable.DefaultAssociationRouteTable) d.Set("default_propagation_route_table", transitGatewayRouteTable.DefaultPropagationRouteTable) d.Set(names.AttrTransitGatewayID, transitGatewayRouteTable.TransitGatewayId) @@ -152,3 +144,7 @@ func resourceTransitGatewayRouteTableDelete(ctx context.Context, d *schema.Resou return diags } + +func transitGatewayRouteTableARN(ctx context.Context, c *conns.AWSClient, routeTableID string) string { + return c.RegionalARN(ctx, names.EC2, "transit-gateway-route-table/"+routeTableID) +} diff --git a/internal/service/ec2/transitgateway_route_table_data_source.go b/internal/service/ec2/transitgateway_route_table_data_source.go index 27be56b4ccd0..ce28b4d0d566 100644 --- a/internal/service/ec2/transitgateway_route_table_data_source.go +++ b/internal/service/ec2/transitgateway_route_table_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -61,7 +59,8 @@ func dataSourceTransitGatewayRouteTable() *schema.Resource { func dataSourceTransitGatewayRouteTableRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeTransitGatewayRouteTablesInput{} @@ -85,14 +84,7 @@ func dataSourceTransitGatewayRouteTableRead(ctx context.Context, d *schema.Resou } d.SetId(aws.ToString(transitGatewayRouteTable.TransitGatewayRouteTableId)) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("transit-gateway-route-table/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayRouteTableARN(ctx, c, d.Id())) d.Set("default_association_route_table", transitGatewayRouteTable.DefaultAssociationRouteTable) d.Set("default_propagation_route_table", transitGatewayRouteTable.DefaultPropagationRouteTable) d.Set(names.AttrTransitGatewayID, transitGatewayRouteTable.TransitGatewayId) diff --git a/internal/service/ec2/transitgateway_vpc_attachment.go b/internal/service/ec2/transitgateway_vpc_attachment.go index daee00b93d17..25a5cb859a4e 100644 --- a/internal/service/ec2/transitgateway_vpc_attachment.go +++ b/internal/service/ec2/transitgateway_vpc_attachment.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -172,7 +170,8 @@ func resourceTransitGatewayVPCAttachmentCreate(ctx context.Context, d *schema.Re func resourceTransitGatewayVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) transitGatewayVPCAttachment, err := findTransitGatewayVPCAttachmentByID(ctx, conn, d.Id()) @@ -225,14 +224,7 @@ func resourceTransitGatewayVPCAttachmentRead(ctx context.Context, d *schema.Reso d.Set("appliance_mode_support", transitGatewayVPCAttachment.Options.ApplianceModeSupport) vpcOwnerID := aws.ToString(transitGatewayVPCAttachment.VpcOwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: vpcOwnerID, - Resource: fmt.Sprintf("transit-gateway-attachment/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayAttachmentARN(ctx, c, vpcOwnerID, d.Id())) d.Set("dns_support", transitGatewayVPCAttachment.Options.DnsSupport) d.Set("ipv6_support", transitGatewayVPCAttachment.Options.Ipv6Support) d.Set("security_group_referencing_support", transitGatewayVPCAttachment.Options.SecurityGroupReferencingSupport) @@ -332,3 +324,7 @@ func resourceTransitGatewayVPCAttachmentDelete(ctx context.Context, d *schema.Re return diags } + +func transitGatewayAttachmentARN(ctx context.Context, c *conns.AWSClient, accountID, attachmentID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "transit-gateway-attachment/"+attachmentID) +} diff --git a/internal/service/ec2/transitgateway_vpc_attachment_data_source.go b/internal/service/ec2/transitgateway_vpc_attachment_data_source.go index 2575cc586276..4ad20d103a39 100644 --- a/internal/service/ec2/transitgateway_vpc_attachment_data_source.go +++ b/internal/service/ec2/transitgateway_vpc_attachment_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -82,7 +80,8 @@ func dataSourceTransitGatewayVPCAttachment() *schema.Resource { func dataSourceTransitGatewayVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeTransitGatewayVpcAttachmentsInput{} @@ -108,14 +107,7 @@ func dataSourceTransitGatewayVPCAttachmentRead(ctx context.Context, d *schema.Re d.SetId(aws.ToString(transitGatewayVPCAttachment.TransitGatewayAttachmentId)) d.Set("appliance_mode_support", transitGatewayVPCAttachment.Options.ApplianceModeSupport) vpcOwnerID := aws.ToString(transitGatewayVPCAttachment.VpcOwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: vpcOwnerID, - Resource: fmt.Sprintf("transit-gateway-attachment/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, transitGatewayAttachmentARN(ctx, c, vpcOwnerID, d.Id())) d.Set("dns_support", transitGatewayVPCAttachment.Options.DnsSupport) d.Set("ipv6_support", transitGatewayVPCAttachment.Options.Ipv6Support) d.Set("security_group_referencing_support", transitGatewayVPCAttachment.Options.SecurityGroupReferencingSupport) diff --git a/internal/service/ec2/verifiedaccess_endpoint.go b/internal/service/ec2/verifiedaccess_endpoint.go index 53acef40e740..6c8d9c8e49cc 100644 --- a/internal/service/ec2/verifiedaccess_endpoint.go +++ b/internal/service/ec2/verifiedaccess_endpoint.go @@ -10,7 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" sdkid "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -57,7 +57,7 @@ func resourceVerifiedAccessEndpoint() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: enum.Validate[types.VerifiedAccessEndpointAttachmentType](), + ValidateDiagFunc: enum.Validate[awstypes.VerifiedAccessEndpointAttachmentType](), }, "cidr_options": { Type: schema.TypeList, @@ -93,7 +93,7 @@ func resourceVerifiedAccessEndpoint() *schema.Resource { Type: schema.TypeString, ForceNew: true, Optional: true, - ValidateFunc: validation.StringInSlice(enum.Slice(types.VerifiedAccessEndpointProtocolTcp), false), + ValidateFunc: validation.StringInSlice(enum.Slice(awstypes.VerifiedAccessEndpointProtocolTcp), false), }, names.AttrSubnetIDs: { Type: schema.TypeSet, @@ -131,7 +131,7 @@ func resourceVerifiedAccessEndpoint() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: enum.Validate[types.VerifiedAccessEndpointType](), + ValidateDiagFunc: enum.Validate[awstypes.VerifiedAccessEndpointType](), }, "load_balancer_options": { Type: schema.TypeList, @@ -171,7 +171,7 @@ func resourceVerifiedAccessEndpoint() *schema.Resource { names.AttrProtocol: { Type: schema.TypeString, Optional: true, - ValidateDiagFunc: enum.Validate[types.VerifiedAccessEndpointProtocol](), + ValidateDiagFunc: enum.Validate[awstypes.VerifiedAccessEndpointProtocol](), }, names.AttrSubnetIDs: { Type: schema.TypeSet, @@ -218,7 +218,7 @@ func resourceVerifiedAccessEndpoint() *schema.Resource { names.AttrProtocol: { Type: schema.TypeString, Optional: true, - ValidateDiagFunc: enum.Validate[types.VerifiedAccessEndpointProtocol](), + ValidateDiagFunc: enum.Validate[awstypes.VerifiedAccessEndpointProtocol](), }, }, }, @@ -241,7 +241,7 @@ func resourceVerifiedAccessEndpoint() *schema.Resource { names.AttrProtocol: { Type: schema.TypeString, Optional: true, - ValidateFunc: validation.StringInSlice(enum.Slice(types.VerifiedAccessEndpointProtocolTcp), false), + ValidateFunc: validation.StringInSlice(enum.Slice(awstypes.VerifiedAccessEndpointProtocolTcp), false), }, "rds_db_cluster_arn": { Type: schema.TypeString, @@ -318,10 +318,10 @@ func resourceVerifiedAccessEndpointCreate(ctx context.Context, d *schema.Resourc conn := meta.(*conns.AWSClient).EC2Client(ctx) input := ec2.CreateVerifiedAccessEndpointInput{ - AttachmentType: types.VerifiedAccessEndpointAttachmentType(d.Get("attachment_type").(string)), + AttachmentType: awstypes.VerifiedAccessEndpointAttachmentType(d.Get("attachment_type").(string)), ClientToken: aws.String(sdkid.UniqueId()), - EndpointType: types.VerifiedAccessEndpointType(d.Get(names.AttrEndpointType).(string)), - TagSpecifications: getTagSpecificationsIn(ctx, types.ResourceTypeVerifiedAccessEndpoint), + EndpointType: awstypes.VerifiedAccessEndpointType(d.Get(names.AttrEndpointType).(string)), + TagSpecifications: getTagSpecificationsIn(ctx, awstypes.ResourceTypeVerifiedAccessEndpoint), VerifiedAccessGroupId: aws.String(d.Get("verified_access_group_id").(string)), } @@ -538,7 +538,7 @@ func resourceVerifiedAccessEndpointDelete(ctx context.Context, d *schema.Resourc return diags } -func flattenVerifiedAccessEndpointPortRanges(apiObjects []types.VerifiedAccessEndpointPortRange) []any { +func flattenVerifiedAccessEndpointPortRanges(apiObjects []awstypes.VerifiedAccessEndpointPortRange) []any { if len(apiObjects) == 0 { return nil } @@ -562,7 +562,7 @@ func flattenVerifiedAccessEndpointPortRanges(apiObjects []types.VerifiedAccessEn return tfList } -func flattenVerifiedAccessEndpointCIDROptions(apiObject *types.VerifiedAccessEndpointCidrOptions) []any { +func flattenVerifiedAccessEndpointCIDROptions(apiObject *awstypes.VerifiedAccessEndpointCidrOptions) []any { if apiObject == nil { return nil } @@ -588,7 +588,7 @@ func flattenVerifiedAccessEndpointCIDROptions(apiObject *types.VerifiedAccessEnd return []any{tfMap} } -func flattenVerifiedAccessEndpointLoadBalancerOptions(apiObject *types.VerifiedAccessEndpointLoadBalancerOptions) []any { +func flattenVerifiedAccessEndpointLoadBalancerOptions(apiObject *awstypes.VerifiedAccessEndpointLoadBalancerOptions) []any { if apiObject == nil { return nil } @@ -618,7 +618,7 @@ func flattenVerifiedAccessEndpointLoadBalancerOptions(apiObject *types.VerifiedA return []any{tfMap} } -func flattenVerifiedAccessEndpointENIOptions(apiObject *types.VerifiedAccessEndpointEniOptions) []any { +func flattenVerifiedAccessEndpointENIOptions(apiObject *awstypes.VerifiedAccessEndpointEniOptions) []any { if apiObject == nil { return nil } @@ -644,7 +644,7 @@ func flattenVerifiedAccessEndpointENIOptions(apiObject *types.VerifiedAccessEndp return []any{tfMap} } -func flattenVerifiedAccessEndpointRDSOptions(apiObject *types.VerifiedAccessEndpointRdsOptions) []any { +func flattenVerifiedAccessEndpointRDSOptions(apiObject *awstypes.VerifiedAccessEndpointRdsOptions) []any { if apiObject == nil { return nil } @@ -682,7 +682,7 @@ func flattenVerifiedAccessEndpointRDSOptions(apiObject *types.VerifiedAccessEndp return []any{tfMap} } -func flattenVerifiedAccessSSESpecificationResponse(apiObject *types.VerifiedAccessSseSpecificationResponse) []any { +func flattenVerifiedAccessSSESpecificationResponse(apiObject *awstypes.VerifiedAccessSseSpecificationResponse) []any { if apiObject == nil { return nil } @@ -700,12 +700,12 @@ func flattenVerifiedAccessSSESpecificationResponse(apiObject *types.VerifiedAcce return []any{tfMap} } -func expandCreateVerifiedAccessEndpointCIDROptions(tfMap map[string]any) *types.CreateVerifiedAccessEndpointCidrOptions { +func expandCreateVerifiedAccessEndpointCIDROptions(tfMap map[string]any) *awstypes.CreateVerifiedAccessEndpointCidrOptions { if tfMap == nil { return nil } - apiObject := &types.CreateVerifiedAccessEndpointCidrOptions{} + apiObject := &awstypes.CreateVerifiedAccessEndpointCidrOptions{} if v, ok := tfMap["cidr"].(string); ok && v != "" { apiObject.Cidr = aws.String(v) @@ -716,7 +716,7 @@ func expandCreateVerifiedAccessEndpointCIDROptions(tfMap map[string]any) *types. } if v, ok := tfMap[names.AttrProtocol].(string); ok && v != "" { - apiObject.Protocol = types.VerifiedAccessEndpointProtocol(v) + apiObject.Protocol = awstypes.VerifiedAccessEndpointProtocol(v) } if v, ok := tfMap[names.AttrSubnetIDs].(*schema.Set); ok && v.Len() > 0 { @@ -726,19 +726,19 @@ func expandCreateVerifiedAccessEndpointCIDROptions(tfMap map[string]any) *types. return apiObject } -func expandCreateVerifiedAccessEndpointRDSOptions(tfMap map[string]any) *types.CreateVerifiedAccessEndpointRdsOptions { +func expandCreateVerifiedAccessEndpointRDSOptions(tfMap map[string]any) *awstypes.CreateVerifiedAccessEndpointRdsOptions { if tfMap == nil { return nil } - apiObject := &types.CreateVerifiedAccessEndpointRdsOptions{} + apiObject := &awstypes.CreateVerifiedAccessEndpointRdsOptions{} if v, ok := tfMap[names.AttrPort].(int); ok { apiObject.Port = aws.Int32(int32(v)) } if v, ok := tfMap[names.AttrProtocol].(string); ok && v != "" { - apiObject.Protocol = types.VerifiedAccessEndpointProtocol(v) + apiObject.Protocol = awstypes.VerifiedAccessEndpointProtocol(v) } if v, ok := tfMap["rds_db_cluster_arn"].(string); ok && v != "" { @@ -764,16 +764,16 @@ func expandCreateVerifiedAccessEndpointRDSOptions(tfMap map[string]any) *types.C return apiObject } -func expandVerifiedAccessEndpointPortRanges(tfList []any) []types.VerifiedAccessEndpointPortRange { +func expandVerifiedAccessEndpointPortRanges(tfList []any) []awstypes.VerifiedAccessEndpointPortRange { if len(tfList) == 0 || tfList[0] == nil { return nil } - apiObjects := make([]types.VerifiedAccessEndpointPortRange, len(tfList)) + apiObjects := make([]awstypes.VerifiedAccessEndpointPortRange, len(tfList)) for i, tfElem := range tfList { tfMap := tfElem.(map[string]any) - apiObjects[i] = types.VerifiedAccessEndpointPortRange{ + apiObjects[i] = awstypes.VerifiedAccessEndpointPortRange{ FromPort: aws.Int32(int32(tfMap["from_port"].(int))), ToPort: aws.Int32(int32(tfMap["to_port"].(int))), } @@ -782,42 +782,42 @@ func expandVerifiedAccessEndpointPortRanges(tfList []any) []types.VerifiedAccess return apiObjects } -func expandCreateVerifiedAccessEndpointPortRanges(tfList []any) []types.CreateVerifiedAccessEndpointPortRange { +func expandCreateVerifiedAccessEndpointPortRanges(tfList []any) []awstypes.CreateVerifiedAccessEndpointPortRange { apiObjects := expandVerifiedAccessEndpointPortRanges(tfList) if apiObjects == nil { return nil } - return tfslices.ApplyToAll(apiObjects, func(v types.VerifiedAccessEndpointPortRange) types.CreateVerifiedAccessEndpointPortRange { - return types.CreateVerifiedAccessEndpointPortRange{ + return tfslices.ApplyToAll(apiObjects, func(v awstypes.VerifiedAccessEndpointPortRange) awstypes.CreateVerifiedAccessEndpointPortRange { + return awstypes.CreateVerifiedAccessEndpointPortRange{ FromPort: v.FromPort, ToPort: v.ToPort, } }) } -func expandModifyVerifiedAccessEndpointPortRanges(tfList []any) []types.ModifyVerifiedAccessEndpointPortRange { +func expandModifyVerifiedAccessEndpointPortRanges(tfList []any) []awstypes.ModifyVerifiedAccessEndpointPortRange { apiObjects := expandVerifiedAccessEndpointPortRanges(tfList) if apiObjects == nil { return nil } - return tfslices.ApplyToAll(apiObjects, func(v types.VerifiedAccessEndpointPortRange) types.ModifyVerifiedAccessEndpointPortRange { - return types.ModifyVerifiedAccessEndpointPortRange{ + return tfslices.ApplyToAll(apiObjects, func(v awstypes.VerifiedAccessEndpointPortRange) awstypes.ModifyVerifiedAccessEndpointPortRange { + return awstypes.ModifyVerifiedAccessEndpointPortRange{ FromPort: v.FromPort, ToPort: v.ToPort, } }) } -func expandCreateVerifiedAccessEndpointLoadBalancerOptions(tfMap map[string]any) *types.CreateVerifiedAccessEndpointLoadBalancerOptions { +func expandCreateVerifiedAccessEndpointLoadBalancerOptions(tfMap map[string]any) *awstypes.CreateVerifiedAccessEndpointLoadBalancerOptions { if tfMap == nil { return nil } - apiObject := &types.CreateVerifiedAccessEndpointLoadBalancerOptions{} + apiObject := &awstypes.CreateVerifiedAccessEndpointLoadBalancerOptions{} if v, ok := tfMap["load_balancer_arn"].(string); ok && v != "" { apiObject.LoadBalancerArn = aws.String(v) @@ -832,7 +832,7 @@ func expandCreateVerifiedAccessEndpointLoadBalancerOptions(tfMap map[string]any) } if v, ok := tfMap[names.AttrProtocol].(string); ok && v != "" { - apiObject.Protocol = types.VerifiedAccessEndpointProtocol(v) + apiObject.Protocol = awstypes.VerifiedAccessEndpointProtocol(v) } if v, ok := tfMap[names.AttrSubnetIDs].(*schema.Set); ok && v.Len() > 0 { @@ -842,12 +842,12 @@ func expandCreateVerifiedAccessEndpointLoadBalancerOptions(tfMap map[string]any) return apiObject } -func expandCreateVerifiedAccessEndpointENIOptions(tfMap map[string]any) *types.CreateVerifiedAccessEndpointEniOptions { +func expandCreateVerifiedAccessEndpointENIOptions(tfMap map[string]any) *awstypes.CreateVerifiedAccessEndpointEniOptions { if tfMap == nil { return nil } - apiObject := &types.CreateVerifiedAccessEndpointEniOptions{} + apiObject := &awstypes.CreateVerifiedAccessEndpointEniOptions{} if v, ok := tfMap[names.AttrNetworkInterfaceID].(string); ok && v != "" { apiObject.NetworkInterfaceId = aws.String(v) @@ -862,17 +862,17 @@ func expandCreateVerifiedAccessEndpointENIOptions(tfMap map[string]any) *types.C } if v, ok := tfMap[names.AttrProtocol].(string); ok && v != "" { - apiObject.Protocol = types.VerifiedAccessEndpointProtocol(v) + apiObject.Protocol = awstypes.VerifiedAccessEndpointProtocol(v) } return apiObject } -func expandModifyVerifiedAccessEndpointCIDROptions(tfMap map[string]any) *types.ModifyVerifiedAccessEndpointCidrOptions { +func expandModifyVerifiedAccessEndpointCIDROptions(tfMap map[string]any) *awstypes.ModifyVerifiedAccessEndpointCidrOptions { if tfMap == nil { return nil } - apiObject := &types.ModifyVerifiedAccessEndpointCidrOptions{} + apiObject := &awstypes.ModifyVerifiedAccessEndpointCidrOptions{} if v, ok := tfMap["port_range"].(*schema.Set); ok { apiObject.PortRanges = expandModifyVerifiedAccessEndpointPortRanges(v.List()) @@ -881,12 +881,12 @@ func expandModifyVerifiedAccessEndpointCIDROptions(tfMap map[string]any) *types. return apiObject } -func expandModifyVerifiedAccessEndpointRDSOptions(tfMap map[string]any) *types.ModifyVerifiedAccessEndpointRdsOptions { +func expandModifyVerifiedAccessEndpointRDSOptions(tfMap map[string]any) *awstypes.ModifyVerifiedAccessEndpointRdsOptions { if tfMap == nil { return nil } - apiObject := &types.ModifyVerifiedAccessEndpointRdsOptions{} + apiObject := &awstypes.ModifyVerifiedAccessEndpointRdsOptions{} if v, ok := tfMap[names.AttrPort].(int); ok { apiObject.Port = aws.Int32(int32(v)) @@ -903,12 +903,12 @@ func expandModifyVerifiedAccessEndpointRDSOptions(tfMap map[string]any) *types.M return apiObject } -func expandModifyVerifiedAccessEndpointLoadBalancerOptions(tfMap map[string]any) *types.ModifyVerifiedAccessEndpointLoadBalancerOptions { +func expandModifyVerifiedAccessEndpointLoadBalancerOptions(tfMap map[string]any) *awstypes.ModifyVerifiedAccessEndpointLoadBalancerOptions { if tfMap == nil { return nil } - apiObject := &types.ModifyVerifiedAccessEndpointLoadBalancerOptions{} + apiObject := &awstypes.ModifyVerifiedAccessEndpointLoadBalancerOptions{} if v, ok := tfMap[names.AttrPort].(int); ok && v != 0 { apiObject.Port = aws.Int32(int32(v)) @@ -919,7 +919,7 @@ func expandModifyVerifiedAccessEndpointLoadBalancerOptions(tfMap map[string]any) } if v, ok := tfMap[names.AttrProtocol].(string); ok && v != "" { - apiObject.Protocol = types.VerifiedAccessEndpointProtocol(v) + apiObject.Protocol = awstypes.VerifiedAccessEndpointProtocol(v) } if v, ok := tfMap[names.AttrSubnetIDs].(*schema.Set); ok && v.Len() > 0 { @@ -929,12 +929,12 @@ func expandModifyVerifiedAccessEndpointLoadBalancerOptions(tfMap map[string]any) return apiObject } -func expandModifyVerifiedAccessEndpointENIOptions(tfMap map[string]any) *types.ModifyVerifiedAccessEndpointEniOptions { +func expandModifyVerifiedAccessEndpointENIOptions(tfMap map[string]any) *awstypes.ModifyVerifiedAccessEndpointEniOptions { if tfMap == nil { return nil } - apiObject := &types.ModifyVerifiedAccessEndpointEniOptions{} + apiObject := &awstypes.ModifyVerifiedAccessEndpointEniOptions{} if v, ok := tfMap[names.AttrPort].(int); ok { apiObject.Port = aws.Int32(int32(v)) @@ -945,18 +945,18 @@ func expandModifyVerifiedAccessEndpointENIOptions(tfMap map[string]any) *types.M } if v, ok := tfMap[names.AttrProtocol].(string); ok && v != "" { - apiObject.Protocol = types.VerifiedAccessEndpointProtocol(v) + apiObject.Protocol = awstypes.VerifiedAccessEndpointProtocol(v) } return apiObject } -func expandVerifiedAccessSSESpecificationRequest(tfMap map[string]any) *types.VerifiedAccessSseSpecificationRequest { +func expandVerifiedAccessSSESpecificationRequest(tfMap map[string]any) *awstypes.VerifiedAccessSseSpecificationRequest { if tfMap == nil { return nil } - apiObject := &types.VerifiedAccessSseSpecificationRequest{} + apiObject := &awstypes.VerifiedAccessSseSpecificationRequest{} if v, ok := tfMap["customer_managed_key_enabled"].(bool); ok { apiObject.CustomerManagedKeyEnabled = aws.Bool(v) diff --git a/internal/service/ec2/verifiedaccess_endpoint_test.go b/internal/service/ec2/verifiedaccess_endpoint_test.go index e77ba1b7de49..a170b3d53109 100644 --- a/internal/service/ec2/verifiedaccess_endpoint_test.go +++ b/internal/service/ec2/verifiedaccess_endpoint_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func testAccVerifiedAccessEndpoint_basic(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") @@ -73,7 +73,7 @@ func testAccVerifiedAccessEndpoint_basic(t *testing.T, semaphore tfsync.Semaphor func testAccVerifiedAccessEndpoint_networkInterface(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") @@ -120,7 +120,7 @@ func testAccVerifiedAccessEndpoint_networkInterface(t *testing.T, semaphore tfsy func testAccVerifiedAccessEndpoint_tags(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") @@ -175,7 +175,7 @@ func testAccVerifiedAccessEndpoint_tags(t *testing.T, semaphore tfsync.Semaphore func testAccVerifiedAccessEndpoint_disappears(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") @@ -205,7 +205,7 @@ func testAccVerifiedAccessEndpoint_disappears(t *testing.T, semaphore tfsync.Sem func testAccVerifiedAccessEndpoint_policyDocument(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") @@ -257,7 +257,7 @@ func testAccVerifiedAccessEndpoint_policyDocument(t *testing.T, semaphore tfsync // Ref: https://github.com/hashicorp/terraform-provider-aws/issues/39186 func testAccVerifiedAccessEndpoint_subnetIDs(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") @@ -303,7 +303,7 @@ func testAccVerifiedAccessEndpoint_subnetIDs(t *testing.T, semaphore tfsync.Sema func testAccVerifiedAccessEndpoint_cidr(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") @@ -349,7 +349,7 @@ func testAccVerifiedAccessEndpoint_cidr(t *testing.T, semaphore tfsync.Semaphore func testAccVerifiedAccessEndpoint_rds(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") @@ -395,7 +395,7 @@ func testAccVerifiedAccessEndpoint_rds(t *testing.T, semaphore tfsync.Semaphore) func testAccVerifiedAccessEndpoint_portRangeTCP(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -432,7 +432,7 @@ func testAccVerifiedAccessEndpoint_portRangeTCP(t *testing.T, semaphore tfsync.S func testAccVerifiedAccessEndpoint_portTCP(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -469,7 +469,7 @@ func testAccVerifiedAccessEndpoint_portTCP(t *testing.T, semaphore tfsync.Semaph func testAccVerifiedAccessEndpoint_portHTTP(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) key := acctest.TLSRSAPrivateKeyPEM(t, 2048) @@ -509,7 +509,7 @@ func testAccVerifiedAccessEndpoint_portHTTP(t *testing.T, semaphore tfsync.Semap func testAccVerifiedAccessEndpoint_portHTTPS(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessEndpoint + var v awstypes.VerifiedAccessEndpoint resourceName := "aws_verifiedaccess_endpoint.test" key := acctest.TLSRSAPrivateKeyPEM(t, 2048) cert := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") @@ -573,7 +573,7 @@ func testAccCheckVerifiedAccessEndpointDestroy(ctx context.Context) resource.Tes } } -func testAccCheckVerifiedAccessEndpointExists(ctx context.Context, n string, v *types.VerifiedAccessEndpoint) resource.TestCheckFunc { +func testAccCheckVerifiedAccessEndpointExists(ctx context.Context, n string, v *awstypes.VerifiedAccessEndpoint) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/internal/service/ec2/verifiedaccess_group.go b/internal/service/ec2/verifiedaccess_group.go index af4c55d1c45c..0a93eabd8487 100644 --- a/internal/service/ec2/verifiedaccess_group.go +++ b/internal/service/ec2/verifiedaccess_group.go @@ -9,7 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -105,7 +105,7 @@ func resourceVerifiedAccessGroupCreate(ctx context.Context, d *schema.ResourceDa input := &ec2.CreateVerifiedAccessGroupInput{ ClientToken: aws.String(id.UniqueId()), - TagSpecifications: getTagSpecificationsIn(ctx, types.ResourceTypeVerifiedAccessGroup), + TagSpecifications: getTagSpecificationsIn(ctx, awstypes.ResourceTypeVerifiedAccessGroup), VerifiedAccessInstanceId: aws.String(d.Get("verifiedaccess_instance_id").(string)), } @@ -257,12 +257,12 @@ func resourceVerifiedAccessGroupDelete(ctx context.Context, d *schema.ResourceDa return diags } -func expandVerifiedAccessSseSpecificationRequest(tfMap map[string]any) *types.VerifiedAccessSseSpecificationRequest { +func expandVerifiedAccessSseSpecificationRequest(tfMap map[string]any) *awstypes.VerifiedAccessSseSpecificationRequest { if tfMap == nil { return nil } - apiObject := &types.VerifiedAccessSseSpecificationRequest{} + apiObject := &awstypes.VerifiedAccessSseSpecificationRequest{} if v, ok := tfMap[names.AttrKMSKeyARN].(string); ok && v != "" { apiObject.KmsKeyArn = aws.String(v) @@ -275,7 +275,7 @@ func expandVerifiedAccessSseSpecificationRequest(tfMap map[string]any) *types.Ve return apiObject } -func flattenVerifiedAccessSseSpecificationResponse(apiObject *types.VerifiedAccessSseSpecificationResponse) []any { +func flattenVerifiedAccessSseSpecificationResponse(apiObject *awstypes.VerifiedAccessSseSpecificationResponse) []any { if apiObject == nil { return nil } diff --git a/internal/service/ec2/verifiedaccess_group_test.go b/internal/service/ec2/verifiedaccess_group_test.go index 6add55bad01c..738cf2e00608 100644 --- a/internal/service/ec2/verifiedaccess_group_test.go +++ b/internal/service/ec2/verifiedaccess_group_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func testAccVerifiedAccessGroup_basic(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessGroup + var v awstypes.VerifiedAccessGroup resourceName := "aws_verifiedaccess_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -65,7 +65,7 @@ func testAccVerifiedAccessGroup_basic(t *testing.T, semaphore tfsync.Semaphore) func testAccVerifiedAccessGroup_kms(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessGroup + var v awstypes.VerifiedAccessGroup resourceName := "aws_verifiedaccess_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) policyDoc := "permit(principal, action, resource) \nwhen {\ncontext.http_request.method == \"GET\"\n};" @@ -101,7 +101,7 @@ func testAccVerifiedAccessGroup_kms(t *testing.T, semaphore tfsync.Semaphore) { func testAccVerifiedAccessGroup_updateKMS(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessGroup + var v awstypes.VerifiedAccessGroup resourceName := "aws_verifiedaccess_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) policyDoc := "permit(principal, action, resource) \nwhen {\ncontext.http_request.method == \"GET\"\n};" @@ -161,7 +161,7 @@ func testAccVerifiedAccessGroup_updateKMS(t *testing.T, semaphore tfsync.Semapho func testAccVerifiedAccessGroup_disappears(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessGroup + var v awstypes.VerifiedAccessGroup resourceName := "aws_verifiedaccess_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -189,7 +189,7 @@ func testAccVerifiedAccessGroup_disappears(t *testing.T, semaphore tfsync.Semaph func testAccVerifiedAccessGroup_tags(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessGroup + var v awstypes.VerifiedAccessGroup resourceName := "aws_verifiedaccess_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -240,7 +240,7 @@ func testAccVerifiedAccessGroup_tags(t *testing.T, semaphore tfsync.Semaphore) { func testAccVerifiedAccessGroup_policy(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessGroup + var v awstypes.VerifiedAccessGroup resourceName := "aws_verifiedaccess_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) description := sdkacctest.RandString(100) @@ -276,7 +276,7 @@ func testAccVerifiedAccessGroup_policy(t *testing.T, semaphore tfsync.Semaphore) func testAccVerifiedAccessGroup_updatePolicy(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessGroup + var v awstypes.VerifiedAccessGroup resourceName := "aws_verifiedaccess_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) description := sdkacctest.RandString(100) @@ -326,7 +326,7 @@ func testAccVerifiedAccessGroup_updatePolicy(t *testing.T, semaphore tfsync.Sema } func testAccVerifiedAccessGroup_setPolicy(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessGroup + var v awstypes.VerifiedAccessGroup resourceName := "aws_verifiedaccess_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) description := sdkacctest.RandString(100) @@ -382,7 +382,7 @@ func testAccVerifiedAccessGroup_setPolicy(t *testing.T, semaphore tfsync.Semapho }) } -func testAccCheckVerifiedAccessGroupExists(ctx context.Context, n string, v *types.VerifiedAccessGroup) resource.TestCheckFunc { +func testAccCheckVerifiedAccessGroupExists(ctx context.Context, n string, v *awstypes.VerifiedAccessGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/internal/service/ec2/verifiedaccess_instance.go b/internal/service/ec2/verifiedaccess_instance.go index 84c706d75825..e12732025b81 100644 --- a/internal/service/ec2/verifiedaccess_instance.go +++ b/internal/service/ec2/verifiedaccess_instance.go @@ -9,7 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" sdkid "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -102,7 +102,7 @@ func resourceVerifiedAccessInstanceCreate(ctx context.Context, d *schema.Resourc input := ec2.CreateVerifiedAccessInstanceInput{ ClientToken: aws.String(sdkid.UniqueId()), - TagSpecifications: getTagSpecificationsIn(ctx, types.ResourceTypeVerifiedAccessInstance), + TagSpecifications: getTagSpecificationsIn(ctx, awstypes.ResourceTypeVerifiedAccessInstance), } if v, ok := d.GetOk("cidr_endpoints_custom_subdomain"); ok { @@ -215,7 +215,7 @@ func resourceVerifiedAccessInstanceDelete(ctx context.Context, d *schema.Resourc return diags } -func flattenVerifiedAccessTrustProviders(apiObjects []types.VerifiedAccessTrustProviderCondensed) []any { +func flattenVerifiedAccessTrustProviders(apiObjects []awstypes.VerifiedAccessTrustProviderCondensed) []any { if len(apiObjects) == 0 { return nil } @@ -233,7 +233,7 @@ func flattenVerifiedAccessTrustProviders(apiObjects []types.VerifiedAccessTrustP return tfList } -func flattenVerifiedAccessTrustProvider(apiObject types.VerifiedAccessTrustProviderCondensed) map[string]any { +func flattenVerifiedAccessTrustProvider(apiObject awstypes.VerifiedAccessTrustProviderCondensed) map[string]any { tfMap := map[string]any{ "device_trust_provider_type": apiObject.DeviceTrustProviderType, "trust_provider_type": apiObject.TrustProviderType, diff --git a/internal/service/ec2/verifiedaccess_instance_logging_configuration.go b/internal/service/ec2/verifiedaccess_instance_logging_configuration.go index e72f598a80e7..f07fdf714b5e 100644 --- a/internal/service/ec2/verifiedaccess_instance_logging_configuration.go +++ b/internal/service/ec2/verifiedaccess_instance_logging_configuration.go @@ -9,7 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -223,14 +223,14 @@ func resourceVerifiedAccessInstanceLoggingConfigurationDelete(ctx context.Contex vaiID := d.Id() // create structure for reset - resetObject := &types.VerifiedAccessLogOptions{ - CloudWatchLogs: &types.VerifiedAccessLogCloudWatchLogsDestinationOptions{ + resetObject := &awstypes.VerifiedAccessLogOptions{ + CloudWatchLogs: &awstypes.VerifiedAccessLogCloudWatchLogsDestinationOptions{ Enabled: aws.Bool(false), }, - KinesisDataFirehose: &types.VerifiedAccessLogKinesisDataFirehoseDestinationOptions{ + KinesisDataFirehose: &awstypes.VerifiedAccessLogKinesisDataFirehoseDestinationOptions{ Enabled: aws.Bool(false), }, - S3: &types.VerifiedAccessLogS3DestinationOptions{ + S3: &awstypes.VerifiedAccessLogS3DestinationOptions{ Enabled: aws.Bool(false), }, IncludeTrustContext: aws.Bool(false), @@ -265,7 +265,7 @@ func resourceVerifiedAccessInstanceLoggingConfigurationDelete(ctx context.Contex return diags } -func expandVerifiedAccessInstanceAccessLogs(accessLogs []any) *types.VerifiedAccessLogOptions { +func expandVerifiedAccessInstanceAccessLogs(accessLogs []any) *awstypes.VerifiedAccessLogOptions { if len(accessLogs) == 0 || accessLogs[0] == nil { return nil } @@ -275,7 +275,7 @@ func expandVerifiedAccessInstanceAccessLogs(accessLogs []any) *types.VerifiedAcc return nil } - result := &types.VerifiedAccessLogOptions{} + result := &awstypes.VerifiedAccessLogOptions{} if v, ok := tfMap[names.AttrCloudWatchLogs].([]any); ok && len(v) > 0 { result.CloudWatchLogs = expandVerifiedAccessLogCloudWatchLogs(v) @@ -300,7 +300,7 @@ func expandVerifiedAccessInstanceAccessLogs(accessLogs []any) *types.VerifiedAcc return result } -func expandVerifiedAccessLogCloudWatchLogs(cloudWatchLogs []any) *types.VerifiedAccessLogCloudWatchLogsDestinationOptions { +func expandVerifiedAccessLogCloudWatchLogs(cloudWatchLogs []any) *awstypes.VerifiedAccessLogCloudWatchLogsDestinationOptions { if len(cloudWatchLogs) == 0 || cloudWatchLogs[0] == nil { return nil } @@ -310,7 +310,7 @@ func expandVerifiedAccessLogCloudWatchLogs(cloudWatchLogs []any) *types.Verified return nil } - result := &types.VerifiedAccessLogCloudWatchLogsDestinationOptions{ + result := &awstypes.VerifiedAccessLogCloudWatchLogsDestinationOptions{ Enabled: aws.Bool(tfMap[names.AttrEnabled].(bool)), } @@ -321,7 +321,7 @@ func expandVerifiedAccessLogCloudWatchLogs(cloudWatchLogs []any) *types.Verified return result } -func expandVerifiedAccessLogKinesisDataFirehose(kinesisDataFirehose []any) *types.VerifiedAccessLogKinesisDataFirehoseDestinationOptions { +func expandVerifiedAccessLogKinesisDataFirehose(kinesisDataFirehose []any) *awstypes.VerifiedAccessLogKinesisDataFirehoseDestinationOptions { if len(kinesisDataFirehose) == 0 || kinesisDataFirehose[0] == nil { return nil } @@ -331,7 +331,7 @@ func expandVerifiedAccessLogKinesisDataFirehose(kinesisDataFirehose []any) *type return nil } - result := &types.VerifiedAccessLogKinesisDataFirehoseDestinationOptions{ + result := &awstypes.VerifiedAccessLogKinesisDataFirehoseDestinationOptions{ Enabled: aws.Bool(tfMap[names.AttrEnabled].(bool)), } @@ -342,7 +342,7 @@ func expandVerifiedAccessLogKinesisDataFirehose(kinesisDataFirehose []any) *type return result } -func expandVerifiedAccessLogS3(s3 []any) *types.VerifiedAccessLogS3DestinationOptions { +func expandVerifiedAccessLogS3(s3 []any) *awstypes.VerifiedAccessLogS3DestinationOptions { if len(s3) == 0 || s3[0] == nil { return nil } @@ -352,7 +352,7 @@ func expandVerifiedAccessLogS3(s3 []any) *types.VerifiedAccessLogS3DestinationOp return nil } - result := &types.VerifiedAccessLogS3DestinationOptions{ + result := &awstypes.VerifiedAccessLogS3DestinationOptions{ Enabled: aws.Bool(tfMap[names.AttrEnabled].(bool)), } @@ -375,7 +375,7 @@ func expandVerifiedAccessLogS3(s3 []any) *types.VerifiedAccessLogS3DestinationOp return result } -func flattenVerifiedAccessInstanceAccessLogs(apiObject *types.VerifiedAccessLogs) []any { +func flattenVerifiedAccessInstanceAccessLogs(apiObject *awstypes.VerifiedAccessLogs) []any { tfMap := map[string]any{} if v := apiObject.CloudWatchLogs; v != nil { @@ -401,7 +401,7 @@ func flattenVerifiedAccessInstanceAccessLogs(apiObject *types.VerifiedAccessLogs return []any{tfMap} } -func flattenVerifiedAccessLogCloudWatchLogs(apiObject *types.VerifiedAccessLogCloudWatchLogsDestination) []any { +func flattenVerifiedAccessLogCloudWatchLogs(apiObject *awstypes.VerifiedAccessLogCloudWatchLogsDestination) []any { tfMap := map[string]any{ names.AttrEnabled: apiObject.Enabled, } @@ -413,7 +413,7 @@ func flattenVerifiedAccessLogCloudWatchLogs(apiObject *types.VerifiedAccessLogCl return []any{tfMap} } -func flattenVerifiedAccessLogKinesisDataFirehose(apiObject *types.VerifiedAccessLogKinesisDataFirehoseDestination) []any { +func flattenVerifiedAccessLogKinesisDataFirehose(apiObject *awstypes.VerifiedAccessLogKinesisDataFirehoseDestination) []any { tfMap := map[string]any{ names.AttrEnabled: apiObject.Enabled, } @@ -425,7 +425,7 @@ func flattenVerifiedAccessLogKinesisDataFirehose(apiObject *types.VerifiedAccess return []any{tfMap} } -func flattenVerifiedAccessLogS3(apiObject *types.VerifiedAccessLogS3Destination) []any { +func flattenVerifiedAccessLogS3(apiObject *awstypes.VerifiedAccessLogS3Destination) []any { tfMap := map[string]any{ names.AttrEnabled: apiObject.Enabled, } diff --git a/internal/service/ec2/verifiedaccess_instance_logging_configuration_test.go b/internal/service/ec2/verifiedaccess_instance_logging_configuration_test.go index 5047831de909..5fc732f42c46 100644 --- a/internal/service/ec2/verifiedaccess_instance_logging_configuration_test.go +++ b/internal/service/ec2/verifiedaccess_instance_logging_configuration_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -24,7 +24,7 @@ import ( func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsIncludeTrustContext(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessInstanceLoggingConfiguration + var v awstypes.VerifiedAccessInstanceLoggingConfiguration resourceName := "aws_verifiedaccess_instance_logging_configuration.test" instanceResourceName := "aws_verifiedaccess_instance.test" include_trust_context_original := true @@ -70,7 +70,7 @@ func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsIncludeTrustCon func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsLogVersion(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessInstanceLoggingConfiguration + var v awstypes.VerifiedAccessInstanceLoggingConfiguration resourceName := "aws_verifiedaccess_instance_logging_configuration.test" instanceResourceName := "aws_verifiedaccess_instance.test" log_version_original := "ocsf-0.1" @@ -116,7 +116,7 @@ func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsLogVersion(t *t func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsCloudWatchLogs(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessInstanceLoggingConfiguration + var v awstypes.VerifiedAccessInstanceLoggingConfiguration resourceName := "aws_verifiedaccess_instance_logging_configuration.test" instanceResourceName := "aws_verifiedaccess_instance.test" logGroupName := "aws_cloudwatch_log_group.test" @@ -166,7 +166,7 @@ func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsCloudWatchLogs( func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsKinesisDataFirehose(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessInstanceLoggingConfiguration + var v awstypes.VerifiedAccessInstanceLoggingConfiguration resourceName := "aws_verifiedaccess_instance_logging_configuration.test" instanceResourceName := "aws_verifiedaccess_instance.test" kinesisStreamName := "aws_kinesis_firehose_delivery_stream.test" @@ -219,7 +219,7 @@ func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsKinesisDataFire func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsS3(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessInstanceLoggingConfiguration + var v awstypes.VerifiedAccessInstanceLoggingConfiguration resourceName := "aws_verifiedaccess_instance_logging_configuration.test" instanceResourceName := "aws_verifiedaccess_instance.test" bucketName := "aws_s3_bucket.test" @@ -277,7 +277,7 @@ func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsS3(t *testing.T func testAccVerifiedAccessInstanceLoggingConfiguration_accessLogsCloudWatchLogsKinesisDataFirehoseS3(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessInstanceLoggingConfiguration + var v awstypes.VerifiedAccessInstanceLoggingConfiguration resourceName := "aws_verifiedaccess_instance_logging_configuration.test" instanceResourceName := "aws_verifiedaccess_instance.test" logGroupName := "aws_cloudwatch_log_group.test" @@ -380,7 +380,7 @@ func testAccVerifiedAccessInstanceLoggingConfiguration_disappears(t *testing.T, // note: disappears test does not test the logging configuration since the instance is deleted // the logging configuration cannot be deleted, rather, the boolean flags and logging version are reset to the default values ctx := acctest.Context(t) - var v types.VerifiedAccessInstanceLoggingConfiguration + var v awstypes.VerifiedAccessInstanceLoggingConfiguration resourceName := "aws_verifiedaccess_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -405,7 +405,7 @@ func testAccVerifiedAccessInstanceLoggingConfiguration_disappears(t *testing.T, }) } -func testAccCheckVerifiedAccessInstanceLoggingConfigurationExists(ctx context.Context, n string, v *types.VerifiedAccessInstanceLoggingConfiguration) resource.TestCheckFunc { +func testAccCheckVerifiedAccessInstanceLoggingConfigurationExists(ctx context.Context, n string, v *awstypes.VerifiedAccessInstanceLoggingConfiguration) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/internal/service/ec2/verifiedaccess_instance_test.go b/internal/service/ec2/verifiedaccess_instance_test.go index 6dcc9a93311b..58d36dce4ba7 100644 --- a/internal/service/ec2/verifiedaccess_instance_test.go +++ b/internal/service/ec2/verifiedaccess_instance_test.go @@ -11,7 +11,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -24,7 +24,7 @@ import ( func testAccVerifiedAccessInstance_basic(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessInstance + var v awstypes.VerifiedAccessInstance resourceName := "aws_verifiedaccess_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -58,7 +58,7 @@ func testAccVerifiedAccessInstance_basic(t *testing.T, semaphore tfsync.Semaphor func testAccVerifiedAccessInstance_description(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v1, v2 types.VerifiedAccessInstance + var v1, v2 awstypes.VerifiedAccessInstance resourceName := "aws_verifiedaccess_instance.test" originalDescription := "original description" updatedDescription := "updated description" @@ -100,7 +100,7 @@ func testAccVerifiedAccessInstance_description(t *testing.T, semaphore tfsync.Se func testAccVerifiedAccessInstance_fipsEnabled(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v1, v2 types.VerifiedAccessInstance + var v1, v2 awstypes.VerifiedAccessInstance resourceName := "aws_verifiedaccess_instance.test" originalFipsEnabled := true updatedFipsEnabled := false @@ -142,7 +142,7 @@ func testAccVerifiedAccessInstance_fipsEnabled(t *testing.T, semaphore tfsync.Se func testAccVerifiedAccessInstance_disappears(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v types.VerifiedAccessInstance + var v awstypes.VerifiedAccessInstance resourceName := "aws_verifiedaccess_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -169,7 +169,7 @@ func testAccVerifiedAccessInstance_disappears(t *testing.T, semaphore tfsync.Sem func testAccVerifiedAccessInstance_tags(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v1, v2, v3 types.VerifiedAccessInstance + var v1, v2, v3 awstypes.VerifiedAccessInstance resourceName := "aws_verifiedaccess_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -221,7 +221,7 @@ func testAccVerifiedAccessInstance_tags(t *testing.T, semaphore tfsync.Semaphore func testAccVerifiedAccessInstance_cidrEndpointsCustomSubDomain(t *testing.T, semaphore tfsync.Semaphore) { ctx := acctest.Context(t) - var v1 types.VerifiedAccessInstance + var v1 awstypes.VerifiedAccessInstance resourceName := "aws_verifiedaccess_instance.test" subDomainName := "test.demo.com" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -252,7 +252,7 @@ func testAccVerifiedAccessInstance_cidrEndpointsCustomSubDomain(t *testing.T, se }) } -func testAccCheckVerifiedAccessInstanceNotRecreated(before, after *types.VerifiedAccessInstance) resource.TestCheckFunc { +func testAccCheckVerifiedAccessInstanceNotRecreated(before, after *awstypes.VerifiedAccessInstance) resource.TestCheckFunc { return func(s *terraform.State) error { if before, after := aws.ToString(before.VerifiedAccessInstanceId), aws.ToString(after.VerifiedAccessInstanceId); before != after { return fmt.Errorf("Verified Access Instance (%s/%s) recreated", before, after) @@ -262,7 +262,7 @@ func testAccCheckVerifiedAccessInstanceNotRecreated(before, after *types.Verifie } } -func testAccCheckVerifiedAccessInstanceRecreated(before, after *types.VerifiedAccessInstance) resource.TestCheckFunc { +func testAccCheckVerifiedAccessInstanceRecreated(before, after *awstypes.VerifiedAccessInstance) resource.TestCheckFunc { return func(s *terraform.State) error { if before, after := aws.ToString(before.VerifiedAccessInstanceId), aws.ToString(after.VerifiedAccessInstanceId); before == after { return fmt.Errorf("Verified Access Instance (%s) not recreated", before) @@ -272,7 +272,7 @@ func testAccCheckVerifiedAccessInstanceRecreated(before, after *types.VerifiedAc } } -func testAccCheckVerifiedAccessInstanceExists(ctx context.Context, n string, v *types.VerifiedAccessInstance) resource.TestCheckFunc { +func testAccCheckVerifiedAccessInstanceExists(ctx context.Context, n string, v *awstypes.VerifiedAccessInstance) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/internal/service/ec2/verifiedaccess_trust_provider.go b/internal/service/ec2/verifiedaccess_trust_provider.go index 613da5d3f236..d92b905c7657 100644 --- a/internal/service/ec2/verifiedaccess_trust_provider.go +++ b/internal/service/ec2/verifiedaccess_trust_provider.go @@ -10,7 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" sdkid "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -68,7 +68,7 @@ func resourceVerifiedAccessTrustProvider() *schema.Resource { Type: schema.TypeString, ForceNew: true, Optional: true, - ValidateDiagFunc: enum.Validate[types.DeviceTrustProviderType](), + ValidateDiagFunc: enum.Validate[awstypes.DeviceTrustProviderType](), }, "native_application_oidc_options": { Type: schema.TypeList, @@ -200,13 +200,13 @@ func resourceVerifiedAccessTrustProvider() *schema.Resource { Type: schema.TypeString, ForceNew: true, Required: true, - ValidateDiagFunc: enum.Validate[types.TrustProviderType](), + ValidateDiagFunc: enum.Validate[awstypes.TrustProviderType](), }, "user_trust_provider_type": { Type: schema.TypeString, ForceNew: true, Optional: true, - ValidateDiagFunc: enum.Validate[types.UserTrustProviderType](), + ValidateDiagFunc: enum.Validate[awstypes.UserTrustProviderType](), }, }, } @@ -219,8 +219,8 @@ func resourceVerifiedAccessTrustProviderCreate(ctx context.Context, d *schema.Re input := ec2.CreateVerifiedAccessTrustProviderInput{ ClientToken: aws.String(sdkid.UniqueId()), PolicyReferenceName: aws.String(d.Get("policy_reference_name").(string)), - TagSpecifications: getTagSpecificationsIn(ctx, types.ResourceTypeVerifiedAccessTrustProvider), - TrustProviderType: types.TrustProviderType(d.Get("trust_provider_type").(string)), + TagSpecifications: getTagSpecificationsIn(ctx, awstypes.ResourceTypeVerifiedAccessTrustProvider), + TrustProviderType: awstypes.TrustProviderType(d.Get("trust_provider_type").(string)), } if v, ok := d.GetOk(names.AttrDescription); ok { @@ -232,7 +232,7 @@ func resourceVerifiedAccessTrustProviderCreate(ctx context.Context, d *schema.Re } if v, ok := d.GetOk("device_trust_provider_type"); ok { - input.DeviceTrustProviderType = types.DeviceTrustProviderType(v.(string)) + input.DeviceTrustProviderType = awstypes.DeviceTrustProviderType(v.(string)) } if v, ok := d.GetOk("native_application_oidc_options"); ok && len(v.([]any)) > 0 && v.([]any)[0] != nil { @@ -248,7 +248,7 @@ func resourceVerifiedAccessTrustProviderCreate(ctx context.Context, d *schema.Re } if v, ok := d.GetOk("user_trust_provider_type"); ok { - input.UserTrustProviderType = types.UserTrustProviderType(v.(string)) + input.UserTrustProviderType = awstypes.UserTrustProviderType(v.(string)) } output, err := conn.CreateVerifiedAccessTrustProvider(ctx, &input) @@ -372,7 +372,7 @@ func resourceVerifiedAccessTrustProviderDelete(ctx context.Context, d *schema.Re return diags } -func flattenDeviceOptions(apiObject *types.DeviceOptions) []any { +func flattenDeviceOptions(apiObject *awstypes.DeviceOptions) []any { if apiObject == nil { return nil } @@ -386,7 +386,7 @@ func flattenDeviceOptions(apiObject *types.DeviceOptions) []any { return []any{tfMap} } -func flattenNativeApplicationOIDCOptions(apiObject *types.NativeApplicationOidcOptions, clientSecret string) []any { +func flattenNativeApplicationOIDCOptions(apiObject *awstypes.NativeApplicationOidcOptions, clientSecret string) []any { if apiObject == nil { return nil } @@ -426,7 +426,7 @@ func flattenNativeApplicationOIDCOptions(apiObject *types.NativeApplicationOidcO return []any{tfMap} } -func flattenOIDCOptions(apiObject *types.OidcOptions, clientSecret string) []any { +func flattenOIDCOptions(apiObject *awstypes.OidcOptions, clientSecret string) []any { if apiObject == nil { return nil } @@ -462,12 +462,12 @@ func flattenOIDCOptions(apiObject *types.OidcOptions, clientSecret string) []any return []any{tfMap} } -func expandCreateVerifiedAccessTrustProviderDeviceOptions(tfMap map[string]any) *types.CreateVerifiedAccessTrustProviderDeviceOptions { +func expandCreateVerifiedAccessTrustProviderDeviceOptions(tfMap map[string]any) *awstypes.CreateVerifiedAccessTrustProviderDeviceOptions { if tfMap == nil { return nil } - apiObject := &types.CreateVerifiedAccessTrustProviderDeviceOptions{} + apiObject := &awstypes.CreateVerifiedAccessTrustProviderDeviceOptions{} if v, ok := tfMap["tenant_id"].(string); ok && v != "" { apiObject.TenantId = aws.String(v) @@ -476,12 +476,12 @@ func expandCreateVerifiedAccessTrustProviderDeviceOptions(tfMap map[string]any) return apiObject } -func expandCreateVerifiedAccessTrustProviderOIDCOptions(tfMap map[string]any) *types.CreateVerifiedAccessTrustProviderOidcOptions { +func expandCreateVerifiedAccessTrustProviderOIDCOptions(tfMap map[string]any) *awstypes.CreateVerifiedAccessTrustProviderOidcOptions { if tfMap == nil { return nil } - apiObject := &types.CreateVerifiedAccessTrustProviderOidcOptions{} + apiObject := &awstypes.CreateVerifiedAccessTrustProviderOidcOptions{} if v, ok := tfMap["authorization_endpoint"].(string); ok && v != "" { apiObject.AuthorizationEndpoint = aws.String(v) @@ -514,12 +514,12 @@ func expandCreateVerifiedAccessTrustProviderOIDCOptions(tfMap map[string]any) *t return apiObject } -func expandCreateVerifiedAccessTrustProviderNativeApplicationOIDCOptions(tfMap map[string]any) *types.CreateVerifiedAccessNativeApplicationOidcOptions { +func expandCreateVerifiedAccessTrustProviderNativeApplicationOIDCOptions(tfMap map[string]any) *awstypes.CreateVerifiedAccessNativeApplicationOidcOptions { if tfMap == nil { return nil } - apiObject := &types.CreateVerifiedAccessNativeApplicationOidcOptions{} + apiObject := &awstypes.CreateVerifiedAccessNativeApplicationOidcOptions{} if v, ok := tfMap["authorization_endpoint"].(string); ok && v != "" { apiObject.AuthorizationEndpoint = aws.String(v) @@ -556,12 +556,12 @@ func expandCreateVerifiedAccessTrustProviderNativeApplicationOIDCOptions(tfMap m return apiObject } -func expandModifyVerifiedAccessTrustProviderNativeApplicationOIDCOptions(tfMap map[string]any) *types.ModifyVerifiedAccessNativeApplicationOidcOptions { +func expandModifyVerifiedAccessTrustProviderNativeApplicationOIDCOptions(tfMap map[string]any) *awstypes.ModifyVerifiedAccessNativeApplicationOidcOptions { if tfMap == nil { return nil } - apiObject := &types.ModifyVerifiedAccessNativeApplicationOidcOptions{} + apiObject := &awstypes.ModifyVerifiedAccessNativeApplicationOidcOptions{} if v, ok := tfMap[names.AttrScope].(string); ok && v != "" { apiObject.Scope = aws.String(v) @@ -570,12 +570,12 @@ func expandModifyVerifiedAccessTrustProviderNativeApplicationOIDCOptions(tfMap m return apiObject } -func expandModifyVerifiedAccessTrustProviderOIDCOptions(tfMap map[string]any) *types.ModifyVerifiedAccessTrustProviderOidcOptions { +func expandModifyVerifiedAccessTrustProviderOIDCOptions(tfMap map[string]any) *awstypes.ModifyVerifiedAccessTrustProviderOidcOptions { if tfMap == nil { return nil } - apiObject := &types.ModifyVerifiedAccessTrustProviderOidcOptions{} + apiObject := &awstypes.ModifyVerifiedAccessTrustProviderOidcOptions{} if v, ok := tfMap[names.AttrScope].(string); ok && v != "" { apiObject.Scope = aws.String(v) diff --git a/internal/service/ec2/verifiedaccess_trust_provider_test.go b/internal/service/ec2/verifiedaccess_trust_provider_test.go index 7c3b42af458e..3eadd9f2646a 100644 --- a/internal/service/ec2/verifiedaccess_trust_provider_test.go +++ b/internal/service/ec2/verifiedaccess_trust_provider_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccVerifiedAccessTrustProvider_basic(t *testing.T) { ctx := acctest.Context(t) - var v types.VerifiedAccessTrustProvider + var v awstypes.VerifiedAccessTrustProvider resourceName := "aws_verifiedaccess_trust_provider.test" trustProviderType := "user" @@ -62,7 +62,7 @@ func TestAccVerifiedAccessTrustProvider_basic(t *testing.T) { func TestAccVerifiedAccessTrustProvider_deviceOptions(t *testing.T) { ctx := acctest.Context(t) - var v types.VerifiedAccessTrustProvider + var v awstypes.VerifiedAccessTrustProvider resourceName := "aws_verifiedaccess_trust_provider.test" trustProviderType := "device" @@ -101,7 +101,7 @@ func TestAccVerifiedAccessTrustProvider_deviceOptions(t *testing.T) { func TestAccVerifiedAccessTrustProvider_disappears(t *testing.T) { ctx := acctest.Context(t) - var v types.VerifiedAccessTrustProvider + var v awstypes.VerifiedAccessTrustProvider resourceName := "aws_verifiedaccess_trust_provider.test" trustProviderType := "user" @@ -133,7 +133,7 @@ func TestAccVerifiedAccessTrustProvider_disappears(t *testing.T) { func TestAccVerifiedAccessTrustProvider_oidcOptions(t *testing.T) { ctx := acctest.Context(t) - var v types.VerifiedAccessTrustProvider + var v awstypes.VerifiedAccessTrustProvider resourceName := "aws_verifiedaccess_trust_provider.test" trustProviderType := "user" @@ -184,7 +184,7 @@ func TestAccVerifiedAccessTrustProvider_oidcOptions(t *testing.T) { func TestAccVerifiedAccessTrustProvider_tags(t *testing.T) { ctx := acctest.Context(t) - var v types.VerifiedAccessTrustProvider + var v awstypes.VerifiedAccessTrustProvider resourceName := "aws_verifiedaccess_trust_provider.test" trustProviderType := "user" @@ -236,7 +236,7 @@ func TestAccVerifiedAccessTrustProvider_tags(t *testing.T) { }) } -func testAccCheckVerifiedAccessTrustProviderExists(ctx context.Context, n string, v *types.VerifiedAccessTrustProvider) resource.TestCheckFunc { +func testAccCheckVerifiedAccessTrustProviderExists(ctx context.Context, n string, v *awstypes.VerifiedAccessTrustProvider) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/internal/service/ec2/vpc_.go b/internal/service/ec2/vpc_.go index e9644b0e36d9..b4cdaf23d8ce 100644 --- a/internal/service/ec2/vpc_.go +++ b/internal/service/ec2/vpc_.go @@ -12,9 +12,8 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -123,8 +122,8 @@ func resourceVPC() *schema.Resource { "instance_tenancy": { Type: schema.TypeString, Optional: true, - Default: types.TenancyDefault, - ValidateFunc: validation.StringInSlice(enum.Slice(types.TenancyDefault, types.TenancyDedicated), false), + Default: awstypes.TenancyDefault, + ValidateFunc: validation.StringInSlice(enum.Slice(awstypes.TenancyDefault, awstypes.TenancyDedicated), false), }, "ipv4_ipam_pool_id": { Type: schema.TypeString, @@ -189,8 +188,8 @@ func resourceVPCCreate(ctx context.Context, d *schema.ResourceData, meta any) di input := &ec2.CreateVpcInput{ AmazonProvidedIpv6CidrBlock: aws.Bool(d.Get("assign_generated_ipv6_cidr_block").(bool)), - InstanceTenancy: types.Tenancy(d.Get("instance_tenancy").(string)), - TagSpecifications: getTagSpecificationsIn(ctx, types.ResourceTypeVpc), + InstanceTenancy: awstypes.Tenancy(d.Get("instance_tenancy").(string)), + TagSpecifications: getTagSpecificationsIn(ctx, awstypes.ResourceTypeVpc), } if v, ok := d.GetOk(names.AttrCIDRBlock); ok { @@ -264,9 +263,10 @@ func resourceVPCCreate(ctx context.Context, d *schema.ResourceData, meta any) di func resourceVPCRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + vpc, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.Vpc, error) { return findVPCByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -280,42 +280,33 @@ func resourceVPCRead(ctx context.Context, d *schema.ResourceData, meta any) diag return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s): %s", d.Id(), err) } - vpc := outputRaw.(*types.Vpc) - ownerID := aws.ToString(vpc.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("vpc/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, vpcARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrCIDRBlock, vpc.CidrBlock) d.Set("dhcp_options_id", vpc.DhcpOptionsId) d.Set("instance_tenancy", vpc.InstanceTenancy) d.Set(names.AttrOwnerID, ownerID) - if v, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { - return findVPCAttribute(ctx, conn, d.Id(), types.VpcAttributeNameEnableDnsHostnames) + if v, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (bool, error) { + return findVPCAttribute(ctx, conn, d.Id(), awstypes.VpcAttributeNameEnableDnsHostnames) }, d.IsNewResource()); err != nil { - return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), types.VpcAttributeNameEnableDnsHostnames, err) + return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), awstypes.VpcAttributeNameEnableDnsHostnames, err) } else { d.Set("enable_dns_hostnames", v) } - if v, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { - return findVPCAttribute(ctx, conn, d.Id(), types.VpcAttributeNameEnableDnsSupport) + if v, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (bool, error) { + return findVPCAttribute(ctx, conn, d.Id(), awstypes.VpcAttributeNameEnableDnsSupport) }, d.IsNewResource()); err != nil { - return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), types.VpcAttributeNameEnableDnsSupport, err) + return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), awstypes.VpcAttributeNameEnableDnsSupport, err) } else { d.Set("enable_dns_support", v) } - if v, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { - return findVPCAttribute(ctx, conn, d.Id(), types.VpcAttributeNameEnableNetworkAddressUsageMetrics) + if v, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (bool, error) { + return findVPCAttribute(ctx, conn, d.Id(), awstypes.VpcAttributeNameEnableNetworkAddressUsageMetrics) }, d.IsNewResource()); err != nil { - return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), types.VpcAttributeNameEnableNetworkAddressUsageMetrics, err) + return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), awstypes.VpcAttributeNameEnableNetworkAddressUsageMetrics, err) } else { d.Set("enable_network_address_usage_metrics", v) } @@ -521,7 +512,7 @@ func resourceVPCCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v an if diff.HasChange("instance_tenancy") { old, new := diff.GetChange("instance_tenancy") - if old.(string) != string(types.TenancyDedicated) || new.(string) != string(types.TenancyDefault) { + if old.(string) != string(awstypes.TenancyDedicated) || new.(string) != string(awstypes.TenancyDefault) { diff.ForceNew("instance_tenancy") } } @@ -541,21 +532,21 @@ func resourceVPCCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v an // defaultIPv6CIDRBlockAssociation returns the "default" IPv6 CIDR block. // Try and find IPv6 CIDR block information, first by any stored association ID. // Then if no IPv6 CIDR block information is available, use the first associated IPv6 CIDR block. -func defaultIPv6CIDRBlockAssociation(vpc *types.Vpc, associationID string) *types.VpcIpv6CidrBlockAssociation { - var ipv6CIDRBlockAssociation types.VpcIpv6CidrBlockAssociation +func defaultIPv6CIDRBlockAssociation(vpc *awstypes.Vpc, associationID string) *awstypes.VpcIpv6CidrBlockAssociation { + var ipv6CIDRBlockAssociation awstypes.VpcIpv6CidrBlockAssociation if associationID != "" { for _, v := range vpc.Ipv6CidrBlockAssociationSet { - if state := v.Ipv6CidrBlockState.State; state == types.VpcCidrBlockStateCodeAssociated && aws.ToString(v.AssociationId) == associationID { + if state := v.Ipv6CidrBlockState.State; state == awstypes.VpcCidrBlockStateCodeAssociated && aws.ToString(v.AssociationId) == associationID { ipv6CIDRBlockAssociation = v break } } } - if ipv6CIDRBlockAssociation == (types.VpcIpv6CidrBlockAssociation{}) { + if ipv6CIDRBlockAssociation == (awstypes.VpcIpv6CidrBlockAssociation{}) { for _, v := range vpc.Ipv6CidrBlockAssociationSet { - if v.Ipv6CidrBlockState.State == types.VpcCidrBlockStateCodeAssociated { + if v.Ipv6CidrBlockState.State == awstypes.VpcCidrBlockStateCodeAssociated { ipv6CIDRBlockAssociation = v } } @@ -565,7 +556,7 @@ func defaultIPv6CIDRBlockAssociation(vpc *types.Vpc, associationID string) *type } type vpcInfo struct { - vpc *types.Vpc + vpc *awstypes.Vpc enableDnsHostnames bool enableDnsSupport bool enableNetworkAddressUsageMetrics bool @@ -597,7 +588,7 @@ func modifyVPCAttributesOnCreate(ctx context.Context, conn *ec2.Client, d *schem func modifyVPCDNSHostnames(ctx context.Context, conn *ec2.Client, vpcID string, v bool) error { input := &ec2.ModifyVpcAttributeInput{ - EnableDnsHostnames: &types.AttributeBooleanValue{ + EnableDnsHostnames: &awstypes.AttributeBooleanValue{ Value: aws.Bool(v), }, VpcId: aws.String(vpcID), @@ -607,7 +598,7 @@ func modifyVPCDNSHostnames(ctx context.Context, conn *ec2.Client, vpcID string, return fmt.Errorf("modifying EnableDnsHostnames: %w", err) } - if _, err := waitVPCAttributeUpdated(ctx, conn, vpcID, types.VpcAttributeNameEnableDnsHostnames, v); err != nil { + if _, err := waitVPCAttributeUpdated(ctx, conn, vpcID, awstypes.VpcAttributeNameEnableDnsHostnames, v); err != nil { return fmt.Errorf("modifying EnableDnsHostnames: waiting for completion: %w", err) } @@ -616,7 +607,7 @@ func modifyVPCDNSHostnames(ctx context.Context, conn *ec2.Client, vpcID string, func modifyVPCDNSSupport(ctx context.Context, conn *ec2.Client, vpcID string, v bool) error { input := &ec2.ModifyVpcAttributeInput{ - EnableDnsSupport: &types.AttributeBooleanValue{ + EnableDnsSupport: &awstypes.AttributeBooleanValue{ Value: aws.Bool(v), }, VpcId: aws.String(vpcID), @@ -626,7 +617,7 @@ func modifyVPCDNSSupport(ctx context.Context, conn *ec2.Client, vpcID string, v return fmt.Errorf("modifying EnableDnsSupport: %w", err) } - if _, err := waitVPCAttributeUpdated(ctx, conn, vpcID, types.VpcAttributeNameEnableDnsSupport, v); err != nil { + if _, err := waitVPCAttributeUpdated(ctx, conn, vpcID, awstypes.VpcAttributeNameEnableDnsSupport, v); err != nil { return fmt.Errorf("modifying EnableDnsSupport: waiting for completion: %w", err) } @@ -635,7 +626,7 @@ func modifyVPCDNSSupport(ctx context.Context, conn *ec2.Client, vpcID string, v func modifyVPCNetworkAddressUsageMetrics(ctx context.Context, conn *ec2.Client, vpcID string, v bool) error { input := &ec2.ModifyVpcAttributeInput{ - EnableNetworkAddressUsageMetrics: &types.AttributeBooleanValue{ + EnableNetworkAddressUsageMetrics: &awstypes.AttributeBooleanValue{ Value: aws.Bool(v), }, VpcId: aws.String(vpcID), @@ -645,7 +636,7 @@ func modifyVPCNetworkAddressUsageMetrics(ctx context.Context, conn *ec2.Client, return fmt.Errorf("modifying EnableNetworkAddressUsageMetrics: %w", err) } - if _, err := waitVPCAttributeUpdated(ctx, conn, vpcID, types.VpcAttributeNameEnableNetworkAddressUsageMetrics, v); err != nil { + if _, err := waitVPCAttributeUpdated(ctx, conn, vpcID, awstypes.VpcAttributeNameEnableNetworkAddressUsageMetrics, v); err != nil { return fmt.Errorf("modifying EnableNetworkAddressUsageMetrics: waiting for completion: %w", err) } @@ -714,7 +705,7 @@ func modifyVPCIPv6CIDRBlockAssociation(ctx context.Context, conn *ec2.Client, vp func modifyVPCTenancy(ctx context.Context, conn *ec2.Client, vpcID string, v string) error { input := &ec2.ModifyVpcTenancyInput{ - InstanceTenancy: types.VpcTenancy(v), + InstanceTenancy: awstypes.VpcTenancy(v), VpcId: aws.String(vpcID), } @@ -725,7 +716,7 @@ func modifyVPCTenancy(ctx context.Context, conn *ec2.Client, vpcID string, v str return nil } -func findIPAMPoolAllocationsForVPC(ctx context.Context, conn *ec2.Client, poolID, vpcID string) ([]types.IpamPoolAllocation, error) { +func findIPAMPoolAllocationsForVPC(ctx context.Context, conn *ec2.Client, poolID, vpcID string) ([]awstypes.IpamPoolAllocation, error) { input := &ec2.GetIpamPoolAllocationsInput{ IpamPoolId: aws.String(poolID), } @@ -736,8 +727,8 @@ func findIPAMPoolAllocationsForVPC(ctx context.Context, conn *ec2.Client, poolID return nil, err } - output = tfslices.Filter(output, func(v types.IpamPoolAllocation) bool { - return v.ResourceType == types.IpamPoolAllocationResourceTypeVpc && aws.ToString(v.ResourceId) == vpcID + output = tfslices.Filter(output, func(v awstypes.IpamPoolAllocation) bool { + return v.ResourceType == awstypes.IpamPoolAllocationResourceTypeVpc && aws.ToString(v.ResourceId) == vpcID }) if len(output) == 0 { @@ -746,3 +737,7 @@ func findIPAMPoolAllocationsForVPC(ctx context.Context, conn *ec2.Client, poolID return output, nil } + +func vpcARN(ctx context.Context, c *conns.AWSClient, accountID, vpcID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "vpc/"+vpcID) +} diff --git a/internal/service/ec2/vpc_data_source.go b/internal/service/ec2/vpc_data_source.go index aac6f93ec5a6..6e9344039256 100644 --- a/internal/service/ec2/vpc_data_source.go +++ b/internal/service/ec2/vpc_data_source.go @@ -9,9 +9,8 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -123,7 +122,8 @@ func dataSourceVPC() *schema.Resource { func dataSourceVPCRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) // We specify "default" as boolean, but EC2 filters want // it to be serialized as a string. Note that setting it to @@ -164,36 +164,28 @@ func dataSourceVPCRead(ctx context.Context, d *schema.ResourceData, meta any) di } d.SetId(aws.ToString(vpc.VpcId)) - ownerID := aws.String(aws.ToString(vpc.OwnerId)) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: aws.ToString(ownerID), - Resource: "vpc/" + d.Id(), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, vpcARN(ctx, c, aws.ToString(ownerID), d.Id())) d.Set(names.AttrCIDRBlock, vpc.CidrBlock) d.Set("default", vpc.IsDefault) d.Set("dhcp_options_id", vpc.DhcpOptionsId) d.Set("instance_tenancy", vpc.InstanceTenancy) d.Set(names.AttrOwnerID, ownerID) - if v, err := findVPCAttribute(ctx, conn, d.Id(), types.VpcAttributeNameEnableDnsHostnames); err != nil { - return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), types.VpcAttributeNameEnableDnsHostnames, err) + if v, err := findVPCAttribute(ctx, conn, d.Id(), awstypes.VpcAttributeNameEnableDnsHostnames); err != nil { + return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), awstypes.VpcAttributeNameEnableDnsHostnames, err) } else { d.Set("enable_dns_hostnames", v) } - if v, err := findVPCAttribute(ctx, conn, d.Id(), types.VpcAttributeNameEnableDnsSupport); err != nil { - return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), types.VpcAttributeNameEnableDnsSupport, err) + if v, err := findVPCAttribute(ctx, conn, d.Id(), awstypes.VpcAttributeNameEnableDnsSupport); err != nil { + return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), awstypes.VpcAttributeNameEnableDnsSupport, err) } else { d.Set("enable_dns_support", v) } - if v, err := findVPCAttribute(ctx, conn, d.Id(), types.VpcAttributeNameEnableNetworkAddressUsageMetrics); err != nil { - return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), types.VpcAttributeNameEnableNetworkAddressUsageMetrics, err) + if v, err := findVPCAttribute(ctx, conn, d.Id(), awstypes.VpcAttributeNameEnableNetworkAddressUsageMetrics); err != nil { + return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), awstypes.VpcAttributeNameEnableNetworkAddressUsageMetrics, err) } else { d.Set("enable_network_address_usage_metrics", v) } diff --git a/internal/service/ec2/vpc_default_network_acl_test.go b/internal/service/ec2/vpc_default_network_acl_test.go index 21ddf315fe12..e3b638351456 100644 --- a/internal/service/ec2/vpc_default_network_acl_test.go +++ b/internal/service/ec2/vpc_default_network_acl_test.go @@ -10,7 +10,7 @@ import ( "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccVPCDefaultNetworkACL_basic(t *testing.T) { ctx := acctest.Context(t) - var v types.NetworkAcl + var v awstypes.NetworkAcl resourceName := "aws_default_network_acl.test" vpcResourceName := "aws_vpc.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -57,7 +57,7 @@ func TestAccVPCDefaultNetworkACL_basic(t *testing.T) { func TestAccVPCDefaultNetworkACL_basicIPv6VPC(t *testing.T) { ctx := acctest.Context(t) - var v types.NetworkAcl + var v awstypes.NetworkAcl resourceName := "aws_default_network_acl.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -86,7 +86,7 @@ func TestAccVPCDefaultNetworkACL_basicIPv6VPC(t *testing.T) { func TestAccVPCDefaultNetworkACL_tags(t *testing.T) { ctx := acctest.Context(t) - var v types.NetworkAcl + var v awstypes.NetworkAcl resourceName := "aws_default_network_acl.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -132,7 +132,7 @@ func TestAccVPCDefaultNetworkACL_tags(t *testing.T) { func TestAccVPCDefaultNetworkACL_Deny_ingress(t *testing.T) { ctx := acctest.Context(t) - var v types.NetworkAcl + var v awstypes.NetworkAcl resourceName := "aws_default_network_acl.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -164,7 +164,7 @@ func TestAccVPCDefaultNetworkACL_Deny_ingress(t *testing.T) { func TestAccVPCDefaultNetworkACL_withIPv6Ingress(t *testing.T) { ctx := acctest.Context(t) - var v types.NetworkAcl + var v awstypes.NetworkAcl resourceName := "aws_default_network_acl.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -196,7 +196,7 @@ func TestAccVPCDefaultNetworkACL_withIPv6Ingress(t *testing.T) { func TestAccVPCDefaultNetworkACL_subnetRemoval(t *testing.T) { ctx := acctest.Context(t) - var v types.NetworkAcl + var v awstypes.NetworkAcl resourceName := "aws_default_network_acl.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -231,7 +231,7 @@ func TestAccVPCDefaultNetworkACL_subnetRemoval(t *testing.T) { func TestAccVPCDefaultNetworkACL_subnetReassign(t *testing.T) { ctx := acctest.Context(t) - var v types.NetworkAcl + var v awstypes.NetworkAcl resourceName := "aws_default_network_acl.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -288,7 +288,7 @@ func testAccCheckDefaultNetworkACLDestroy(s *terraform.State) error { return nil } -func testAccCheckDefaultNetworkACLExists(ctx context.Context, n string, v *types.NetworkAcl) resource.TestCheckFunc { +func testAccCheckDefaultNetworkACLExists(ctx context.Context, n string, v *awstypes.NetworkAcl) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/internal/service/ec2/vpc_dhcp_options.go b/internal/service/ec2/vpc_dhcp_options.go index 5b98fba1b099..7ca9cfcf484d 100644 --- a/internal/service/ec2/vpc_dhcp_options.go +++ b/internal/service/ec2/vpc_dhcp_options.go @@ -9,7 +9,6 @@ import ( "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -131,9 +130,10 @@ func resourceVPCDHCPOptionsCreate(ctx context.Context, d *schema.ResourceData, m func resourceVPCDHCPOptionsRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + opts, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.DhcpOptions, error) { return findDHCPOptionsByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -147,17 +147,8 @@ func resourceVPCDHCPOptionsRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading EC2 DHCP Options (%s): %s", d.Id(), err) } - opts := outputRaw.(*awstypes.DhcpOptions) - ownerID := aws.ToString(opts.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("dhcp-options/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, dhcpOptionsARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrOwnerID, ownerID) err = optionsMap.dhcpConfigurationsToResourceData(opts.DhcpConfigurations, d) @@ -320,3 +311,7 @@ func (m *dhcpOptionsMap) resourceDataToDHCPConfigurations(d *schema.ResourceData return output, nil } + +func dhcpOptionsARN(ctx context.Context, c *conns.AWSClient, accountID, dhcpOptionsID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "dhcp-options/"+dhcpOptionsID) +} diff --git a/internal/service/ec2/vpc_dhcp_options_association.go b/internal/service/ec2/vpc_dhcp_options_association.go index 7e4742fc1c42..3683c7238e04 100644 --- a/internal/service/ec2/vpc_dhcp_options_association.go +++ b/internal/service/ec2/vpc_dhcp_options_association.go @@ -80,7 +80,7 @@ func resourceVPCDHCPOptionsAssociationRead(ctx context.Context, d *schema.Resour return sdkdiag.AppendErrorf(diags, "reading EC2 VPC DHCP Options Set Association (%s): %s", d.Id(), err) } - _, err = tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + _, err = tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (any, error) { return nil, findVPCDHCPOptionsAssociation(ctx, conn, vpcID, dhcpOptionsID) }, d.IsNewResource()) diff --git a/internal/service/ec2/vpc_dhcp_options_data_source.go b/internal/service/ec2/vpc_dhcp_options_data_source.go index 7141b61af765..13df940762c8 100644 --- a/internal/service/ec2/vpc_dhcp_options_data_source.go +++ b/internal/service/ec2/vpc_dhcp_options_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -78,7 +76,8 @@ func dataSourceVPCDHCPOptions() *schema.Resource { func dataSourceVPCDHCPOptionsRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig(ctx) input := &ec2.DescribeDhcpOptionsInput{} @@ -104,14 +103,7 @@ func dataSourceVPCDHCPOptionsRead(ctx context.Context, d *schema.ResourceData, m d.SetId(aws.ToString(opts.DhcpOptionsId)) ownerID := aws.ToString(opts.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("dhcp-options/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, dhcpOptionsARN(ctx, c, ownerID, d.Id())) d.Set("dhcp_options_id", d.Id()) d.Set(names.AttrOwnerID, ownerID) diff --git a/internal/service/ec2/vpc_egress_only_internet_gateway.go b/internal/service/ec2/vpc_egress_only_internet_gateway.go index cf7cf5f1a232..db1e16538f61 100644 --- a/internal/service/ec2/vpc_egress_only_internet_gateway.go +++ b/internal/service/ec2/vpc_egress_only_internet_gateway.go @@ -72,7 +72,7 @@ func resourceEgressOnlyInternetGatewayRead(ctx context.Context, d *schema.Resour var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + ig, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.EgressOnlyInternetGateway, error) { return findEgressOnlyInternetGatewayByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -86,8 +86,6 @@ func resourceEgressOnlyInternetGatewayRead(ctx context.Context, d *schema.Resour return sdkdiag.AppendErrorf(diags, "reading EC2 Egress-only Internet Gateway (%s): %s", d.Id(), err) } - ig := outputRaw.(*awstypes.EgressOnlyInternetGateway) - if len(ig.Attachments) == 1 && ig.Attachments[0].State == awstypes.AttachmentStatusAttached { d.Set(names.AttrVPCID, ig.Attachments[0].VpcId) } else { diff --git a/internal/service/ec2/vpc_endpoint_route_table_association.go b/internal/service/ec2/vpc_endpoint_route_table_association.go index 5f29bcf47139..c2995cff4bc3 100644 --- a/internal/service/ec2/vpc_endpoint_route_table_association.go +++ b/internal/service/ec2/vpc_endpoint_route_table_association.go @@ -85,7 +85,7 @@ func resourceVPCEndpointRouteTableAssociationRead(ctx context.Context, d *schema // Human friendly ID for error messages since d.Id() is non-descriptive id := fmt.Sprintf("%s/%s", endpointID, routeTableID) - _, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + _, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (any, error) { return nil, findVPCEndpointRouteTableAssociationExists(ctx, conn, endpointID, routeTableID) }, d.IsNewResource()) diff --git a/internal/service/ec2/vpc_endpoint_service.go b/internal/service/ec2/vpc_endpoint_service.go index 52179cba00d8..e6f45cfb6fae 100644 --- a/internal/service/ec2/vpc_endpoint_service.go +++ b/internal/service/ec2/vpc_endpoint_service.go @@ -5,12 +5,10 @@ package ec2 import ( "context" - "fmt" "log" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -217,7 +215,8 @@ func resourceVPCEndpointServiceCreate(ctx context.Context, d *schema.ResourceDat func resourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) svcCfg, err := findVPCEndpointServiceConfigurationByID(ctx, conn, d.Id()) @@ -232,14 +231,7 @@ func resourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceData, } d.Set("acceptance_required", svcCfg.AcceptanceRequired) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("vpc-endpoint-service/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, vpcEndpointServiceARN(ctx, c, d.Id())) d.Set(names.AttrAvailabilityZones, svcCfg.AvailabilityZones) d.Set("base_endpoint_dns_names", svcCfg.BaseEndpointDnsNames) d.Set("gateway_load_balancer_arns", svcCfg.GatewayLoadBalancerArns) @@ -404,3 +396,11 @@ func flattenSupportedRegionDetails(apiObjects []awstypes.SupportedRegionDetail) return aws.ToString(v.Region) }) } + +func vpcEndpointServiceARN(ctx context.Context, c *conns.AWSClient, serviceID string) string { + return c.RegionalARN(ctx, names.EC2, "vpc-endpoint-service/"+serviceID) +} + +func vpcEndpointServiceARNWithRegion(ctx context.Context, c *conns.AWSClient, region, serviceID string) string { + return c.RegionalARNWithRegion(ctx, names.EC2, region, "vpc-endpoint-service/"+serviceID) +} diff --git a/internal/service/ec2/vpc_endpoint_service_data_source.go b/internal/service/ec2/vpc_endpoint_service_data_source.go index 7b126f99916a..4d6895d06cc6 100644 --- a/internal/service/ec2/vpc_endpoint_service_data_source.go +++ b/internal/service/ec2/vpc_endpoint_service_data_source.go @@ -10,7 +10,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -125,7 +124,8 @@ func dataSourceVPCEndpointService() *schema.Resource { func dataSourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeVpcEndpointServicesInput{ Filters: newAttributeFilterList( @@ -199,16 +199,8 @@ func dataSourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceDat serviceRegion := aws.ToString(sd.ServiceRegion) d.SetId(strconv.Itoa(create.StringHashcode(serviceName))) - d.Set("acceptance_required", sd.AcceptanceRequired) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: serviceRegion, - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("vpc-endpoint-service/%s", serviceID), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, vpcEndpointServiceARNWithRegion(ctx, c, serviceRegion, serviceID)) d.Set(names.AttrAvailabilityZones, sd.AvailabilityZones) d.Set("base_endpoint_dns_names", sd.BaseEndpointDnsNames) d.Set("manages_vpc_endpoints", sd.ManagesVpcEndpoints) diff --git a/internal/service/ec2/vpc_flow_log.go b/internal/service/ec2/vpc_flow_log.go index 536d00f817b1..3b0920c623c9 100644 --- a/internal/service/ec2/vpc_flow_log.go +++ b/internal/service/ec2/vpc_flow_log.go @@ -5,12 +5,10 @@ package ec2 import ( "context" - "fmt" "log" "strings" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -252,7 +250,8 @@ func resourceLogFlowCreate(ctx context.Context, d *schema.ResourceData, meta any func resourceLogFlowRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) fl, err := findFlowLogByID(ctx, conn, d.Id()) @@ -266,14 +265,7 @@ func resourceLogFlowRead(ctx context.Context, d *schema.ResourceData, meta any) return sdkdiag.AppendErrorf(diags, "reading Flow Log (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("vpc-flow-log/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, flowLogARN(ctx, c, d.Id())) d.Set("deliver_cross_account_role", fl.DeliverCrossAccountRole) if fl.DestinationOptions != nil { if err := d.Set("destination_options", []any{flattenDestinationOptionsResponse(fl.DestinationOptions)}); err != nil { @@ -380,3 +372,7 @@ func flattenDestinationOptionsResponse(apiObject *awstypes.DestinationOptionsRes return tfMap } + +func flowLogARN(ctx context.Context, c *conns.AWSClient, flowLogID string) string { + return c.RegionalARN(ctx, names.EC2, "vpc-flow-log/"+flowLogID) +} diff --git a/internal/service/ec2/vpc_internet_gateway.go b/internal/service/ec2/vpc_internet_gateway.go index 8e19d0f7d43a..518591daadd0 100644 --- a/internal/service/ec2/vpc_internet_gateway.go +++ b/internal/service/ec2/vpc_internet_gateway.go @@ -10,7 +10,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -92,9 +91,10 @@ func resourceInternetGatewayCreate(ctx context.Context, d *schema.ResourceData, func resourceInternetGatewayRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + ig, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.InternetGateway, error) { return findInternetGatewayByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -108,17 +108,8 @@ func resourceInternetGatewayRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "reading EC2 Internet Gateway (%s): %s", d.Id(), err) } - ig := outputRaw.(*awstypes.InternetGateway) - ownerID := aws.ToString(ig.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("internet-gateway/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, internetGatewayARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrOwnerID, ownerID) if len(ig.Attachments) == 0 { // Gateway exists but not attached to the VPC. @@ -242,3 +233,7 @@ func detachInternetGateway(ctx context.Context, conn *ec2.Client, internetGatewa return nil } + +func internetGatewayARN(ctx context.Context, c *conns.AWSClient, accountID, internetGatewayID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "internet-gateway/"+internetGatewayID) +} diff --git a/internal/service/ec2/vpc_internet_gateway_attachment.go b/internal/service/ec2/vpc_internet_gateway_attachment.go index 133ae63b933f..b92b333d15e0 100644 --- a/internal/service/ec2/vpc_internet_gateway_attachment.go +++ b/internal/service/ec2/vpc_internet_gateway_attachment.go @@ -76,7 +76,7 @@ func resourceInternetGatewayAttachmentRead(ctx context.Context, d *schema.Resour return sdkdiag.AppendFromErr(diags, err) } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + igw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.InternetGatewayAttachment, error) { return findInternetGatewayAttachment(ctx, conn, igwID, vpcID) }, d.IsNewResource()) @@ -90,8 +90,6 @@ func resourceInternetGatewayAttachmentRead(ctx context.Context, d *schema.Resour return sdkdiag.AppendErrorf(diags, "reading EC2 Internet Gateway Attachment (%s): %s", d.Id(), err) } - igw := outputRaw.(*awstypes.InternetGatewayAttachment) - d.Set("internet_gateway_id", igwID) d.Set(names.AttrVPCID, igw.VpcId) diff --git a/internal/service/ec2/vpc_internet_gateway_data_source.go b/internal/service/ec2/vpc_internet_gateway_data_source.go index 767b4e46a223..3de3be6dec8e 100644 --- a/internal/service/ec2/vpc_internet_gateway_data_source.go +++ b/internal/service/ec2/vpc_internet_gateway_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -68,7 +66,8 @@ func dataSourceInternetGateway() *schema.Resource { func dataSourceInternetGatewayRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig(ctx) internetGatewayId, internetGatewayIdOk := d.GetOk("internet_gateway_id") @@ -99,14 +98,7 @@ func dataSourceInternetGatewayRead(ctx context.Context, d *schema.ResourceData, d.SetId(aws.ToString(igw.InternetGatewayId)) ownerID := aws.ToString(igw.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("internet-gateway/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, internetGatewayARN(ctx, c, ownerID, d.Id())) if err := d.Set("attachments", flattenInternetGatewayAttachments(igw.Attachments)); err != nil { return sdkdiag.AppendErrorf(diags, "setting attachments: %s", err) diff --git a/internal/service/ec2/vpc_managed_prefix_list_entry.go b/internal/service/ec2/vpc_managed_prefix_list_entry.go index dcb602411447..3a64df8165e5 100644 --- a/internal/service/ec2/vpc_managed_prefix_list_entry.go +++ b/internal/service/ec2/vpc_managed_prefix_list_entry.go @@ -115,7 +115,7 @@ func resourceManagedPrefixListEntryRead(ctx context.Context, d *schema.ResourceD return sdkdiag.AppendFromErr(diags, err) } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, managedPrefixListEntryCreateTimeout, func() (any, error) { + entry, err := tfresource.RetryWhenNewResourceNotFound(ctx, managedPrefixListEntryCreateTimeout, func(ctx context.Context) (*awstypes.PrefixListEntry, error) { return findManagedPrefixListEntryByIDAndCIDR(ctx, conn, plID, cidr) }, d.IsNewResource()) @@ -129,8 +129,6 @@ func resourceManagedPrefixListEntryRead(ctx context.Context, d *schema.ResourceD return sdkdiag.AppendErrorf(diags, "reading VPC Managed Prefix List Entry (%s): %s", d.Id(), err) } - entry := outputRaw.(*awstypes.PrefixListEntry) - d.Set("cidr", entry.Cidr) d.Set(names.AttrDescription, entry.Description) diff --git a/internal/service/ec2/vpc_network_acl.go b/internal/service/ec2/vpc_network_acl.go index e96e4c8b4f7a..2fa5f757d66a 100644 --- a/internal/service/ec2/vpc_network_acl.go +++ b/internal/service/ec2/vpc_network_acl.go @@ -12,7 +12,6 @@ import ( "strings" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -192,9 +191,10 @@ func resourceNetworkACLCreate(ctx context.Context, d *schema.ResourceData, meta func resourceNetworkACLRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + nacl, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.NetworkAcl, error) { return findNetworkACLByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -208,17 +208,8 @@ func resourceNetworkACLRead(ctx context.Context, d *schema.ResourceData, meta an return sdkdiag.AppendErrorf(diags, "reading EC2 Network ACL (%s): %s", d.Id(), err) } - nacl := outputRaw.(*awstypes.NetworkAcl) - ownerID := aws.ToString(nacl.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("network-acl/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, networkACLARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrOwnerID, ownerID) var subnetIDs []string @@ -831,3 +822,7 @@ var ( }) ianaProtocolIToA = ianaProtocolAToI.invert() ) + +func networkACLARN(ctx context.Context, c *conns.AWSClient, accountID, networkACLID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "network-acl/"+networkACLID) +} diff --git a/internal/service/ec2/vpc_network_acl_association.go b/internal/service/ec2/vpc_network_acl_association.go index 68259f4af755..946e2f2b304a 100644 --- a/internal/service/ec2/vpc_network_acl_association.go +++ b/internal/service/ec2/vpc_network_acl_association.go @@ -64,7 +64,7 @@ func resourceNetworkACLAssociationRead(ctx context.Context, d *schema.ResourceDa var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + association, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.NetworkAclAssociation, error) { return findNetworkACLAssociationByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -78,8 +78,6 @@ func resourceNetworkACLAssociationRead(ctx context.Context, d *schema.ResourceDa return sdkdiag.AppendErrorf(diags, "reading EC2 Network ACL Association (%s): %s", d.Id(), err) } - association := outputRaw.(*awstypes.NetworkAclAssociation) - d.Set("network_acl_id", association.NetworkAclId) d.Set(names.AttrSubnetID, association.SubnetId) diff --git a/internal/service/ec2/vpc_network_acl_rule.go b/internal/service/ec2/vpc_network_acl_rule.go index e3301bcb99f8..0976af3a04e6 100644 --- a/internal/service/ec2/vpc_network_acl_rule.go +++ b/internal/service/ec2/vpc_network_acl_rule.go @@ -195,7 +195,7 @@ func resourceNetworkACLRuleRead(ctx context.Context, d *schema.ResourceData, met naclID := d.Get("network_acl_id").(string) ruleNumber := d.Get("rule_number").(int) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + naclEntry, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.NetworkAclEntry, error) { return findNetworkACLEntryByThreePartKey(ctx, conn, naclID, egress, ruleNumber) }, d.IsNewResource()) @@ -209,8 +209,6 @@ func resourceNetworkACLRuleRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading EC2 Network ACL Rule (%s): %s", d.Id(), err) } - naclEntry := outputRaw.(*awstypes.NetworkAclEntry) - d.Set(names.AttrCIDRBlock, naclEntry.CidrBlock) d.Set("egress", naclEntry.Egress) d.Set("ipv6_cidr_block", naclEntry.Ipv6CidrBlock) diff --git a/internal/service/ec2/vpc_network_interface.go b/internal/service/ec2/vpc_network_interface.go index 06cd0944dbe3..12f69bfba217 100644 --- a/internal/service/ec2/vpc_network_interface.go +++ b/internal/service/ec2/vpc_network_interface.go @@ -11,9 +11,8 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -86,7 +85,7 @@ func resourceNetworkInterface() *schema.Resource { Optional: true, Computed: true, ForceNew: true, - ValidateDiagFunc: enum.Validate[types.NetworkInterfaceCreationType](), + ValidateDiagFunc: enum.Validate[awstypes.NetworkInterfaceCreationType](), }, "ipv4_prefixes": { Type: schema.TypeSet, @@ -364,7 +363,7 @@ func resourceNetworkInterfaceCreate(ctx context.Context, d *schema.ResourceData, } if v, ok := d.GetOk("interface_type"); ok { - input.InterfaceType = types.NetworkInterfaceCreationType(v.(string)) + input.InterfaceType = awstypes.NetworkInterfaceCreationType(v.(string)) } if v, ok := d.GetOk("ipv4_prefixes"); ok && v.(*schema.Set).Len() > 0 { @@ -432,7 +431,7 @@ func resourceNetworkInterfaceCreate(ctx context.Context, d *schema.ResourceData, // If IPv4 or IPv6 prefixes are specified, tag after create. // Otherwise "An error occurred (InternalError) when calling the CreateNetworkInterface operation". if !(ipv4PrefixesSpecified || ipv6PrefixesSpecified) { - input.TagSpecifications = getTagSpecificationsIn(ctx, types.ResourceTypeNetworkInterface) + input.TagSpecifications = getTagSpecificationsIn(ctx, awstypes.ResourceTypeNetworkInterface) } output, err := conn.CreateNetworkInterface(ctx, input) @@ -478,7 +477,7 @@ func resourceNetworkInterfaceCreate(ctx context.Context, d *schema.ResourceData, if !d.Get("source_dest_check").(bool) { input := &ec2.ModifyNetworkInterfaceAttributeInput{ NetworkInterfaceId: aws.String(d.Id()), - SourceDestCheck: &types.AttributeBooleanValue{Value: aws.Bool(false)}, + SourceDestCheck: &awstypes.AttributeBooleanValue{Value: aws.Bool(false)}, } _, err := conn.ModifyNetworkInterfaceAttribute(ctx, input) @@ -503,9 +502,10 @@ func resourceNetworkInterfaceCreate(ctx context.Context, d *schema.ResourceData, func resourceNetworkInterfaceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + eni, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.NetworkInterface, error) { return findNetworkInterfaceByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -519,17 +519,8 @@ func resourceNetworkInterfaceRead(ctx context.Context, d *schema.ResourceData, m return sdkdiag.AppendErrorf(diags, "reading EC2 Network Interface (%s): %s", d.Id(), err) } - eni := outputRaw.(*types.NetworkInterface) - ownerID := aws.ToString(eni.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: "ec2", - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: "network-interface/" + d.Id(), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, networkInterfaceARN(ctx, c, ownerID, d.Id())) if eni.Attachment != nil { if err := d.Set("attachment", []any{flattenNetworkInterfaceAttachment(eni.Attachment)}); err != nil { return sdkdiag.AppendErrorf(diags, "setting attachment: %s", err) @@ -1026,7 +1017,7 @@ func resourceNetworkInterfaceUpdate(ctx context.Context, d *schema.ResourceData, if d.HasChange("source_dest_check") { input := &ec2.ModifyNetworkInterfaceAttributeInput{ NetworkInterfaceId: aws.String(d.Id()), - SourceDestCheck: &types.AttributeBooleanValue{Value: aws.Bool(d.Get("source_dest_check").(bool))}, + SourceDestCheck: &awstypes.AttributeBooleanValue{Value: aws.Bool(d.Get("source_dest_check").(bool))}, } _, err := conn.ModifyNetworkInterfaceAttribute(ctx, input) @@ -1052,7 +1043,7 @@ func resourceNetworkInterfaceUpdate(ctx context.Context, d *schema.ResourceData, if d.HasChange(names.AttrDescription) { input := &ec2.ModifyNetworkInterfaceAttributeInput{ NetworkInterfaceId: aws.String(d.Id()), - Description: &types.AttributeValue{Value: aws.String(d.Get(names.AttrDescription).(string))}, + Description: &awstypes.AttributeValue{Value: aws.String(d.Get(names.AttrDescription).(string))}, } _, err := conn.ModifyNetworkInterfaceAttribute(ctx, input) @@ -1156,7 +1147,7 @@ func detachNetworkInterface(ctx context.Context, conn *ec2.Client, networkInterf return nil } -func flattenNetworkInterfaceAssociation(apiObject *types.NetworkInterfaceAssociation) map[string]any { +func flattenNetworkInterfaceAssociation(apiObject *awstypes.NetworkInterfaceAssociation) map[string]any { if apiObject == nil { return nil } @@ -1194,7 +1185,7 @@ func flattenNetworkInterfaceAssociation(apiObject *types.NetworkInterfaceAssocia return tfMap } -func flattenNetworkInterfaceAttachment(apiObject *types.NetworkInterfaceAttachment) map[string]any { +func flattenNetworkInterfaceAttachment(apiObject *awstypes.NetworkInterfaceAttachment) map[string]any { if apiObject == nil { return nil } @@ -1216,24 +1207,24 @@ func flattenNetworkInterfaceAttachment(apiObject *types.NetworkInterfaceAttachme return tfMap } -func expandPrivateIPAddressSpecification(tfString string) *types.PrivateIpAddressSpecification { +func expandPrivateIPAddressSpecification(tfString string) *awstypes.PrivateIpAddressSpecification { if tfString == "" { return nil } - apiObject := &types.PrivateIpAddressSpecification{ + apiObject := &awstypes.PrivateIpAddressSpecification{ PrivateIpAddress: aws.String(tfString), } return apiObject } -func expandPrivateIPAddressSpecifications(tfList []any) []types.PrivateIpAddressSpecification { +func expandPrivateIPAddressSpecifications(tfList []any) []awstypes.PrivateIpAddressSpecification { if len(tfList) == 0 { return nil } - var apiObjects []types.PrivateIpAddressSpecification + var apiObjects []awstypes.PrivateIpAddressSpecification for i, tfMapRaw := range tfList { tfString, ok := tfMapRaw.(string) @@ -1258,24 +1249,24 @@ func expandPrivateIPAddressSpecifications(tfList []any) []types.PrivateIpAddress return apiObjects } -func expandInstanceIPv6Address(tfString string) *types.InstanceIpv6Address { +func expandInstanceIPv6Address(tfString string) *awstypes.InstanceIpv6Address { if tfString == "" { return nil } - apiObject := &types.InstanceIpv6Address{ + apiObject := &awstypes.InstanceIpv6Address{ Ipv6Address: aws.String(tfString), } return apiObject } -func expandInstanceIPv6Addresses(tfList []any) []types.InstanceIpv6Address { +func expandInstanceIPv6Addresses(tfList []any) []awstypes.InstanceIpv6Address { if len(tfList) == 0 { return nil } - var apiObjects []types.InstanceIpv6Address + var apiObjects []awstypes.InstanceIpv6Address for _, tfMapRaw := range tfList { tfString, ok := tfMapRaw.(string) @@ -1296,7 +1287,7 @@ func expandInstanceIPv6Addresses(tfList []any) []types.InstanceIpv6Address { return apiObjects } -func flattenNetworkInterfacePrivateIPAddress(apiObject *types.NetworkInterfacePrivateIpAddress) string { +func flattenNetworkInterfacePrivateIPAddress(apiObject *awstypes.NetworkInterfacePrivateIpAddress) string { if apiObject == nil { return "" } @@ -1310,7 +1301,7 @@ func flattenNetworkInterfacePrivateIPAddress(apiObject *types.NetworkInterfacePr return tfString } -func flattenNetworkInterfacePrivateIPAddresses(apiObjects []types.NetworkInterfacePrivateIpAddress) []string { +func flattenNetworkInterfacePrivateIPAddresses(apiObjects []awstypes.NetworkInterfacePrivateIpAddress) []string { if len(apiObjects) == 0 { return nil } @@ -1324,7 +1315,7 @@ func flattenNetworkInterfacePrivateIPAddresses(apiObjects []types.NetworkInterfa return tfList } -func flattenNetworkInterfaceIPv6Address(apiObject *types.NetworkInterfaceIpv6Address) string { +func flattenNetworkInterfaceIPv6Address(apiObject *awstypes.NetworkInterfaceIpv6Address) string { if apiObject == nil { return "" } @@ -1338,7 +1329,7 @@ func flattenNetworkInterfaceIPv6Address(apiObject *types.NetworkInterfaceIpv6Add return tfString } -func flattenNetworkInterfaceIPv6Addresses(apiObjects []types.NetworkInterfaceIpv6Address) []string { +func flattenNetworkInterfaceIPv6Addresses(apiObjects []awstypes.NetworkInterfaceIpv6Address) []string { if len(apiObjects) == 0 { return nil } @@ -1352,24 +1343,24 @@ func flattenNetworkInterfaceIPv6Addresses(apiObjects []types.NetworkInterfaceIpv return tfList } -func expandIPv4PrefixSpecificationRequest(tfString string) *types.Ipv4PrefixSpecificationRequest { +func expandIPv4PrefixSpecificationRequest(tfString string) *awstypes.Ipv4PrefixSpecificationRequest { if tfString == "" { return nil } - apiObject := &types.Ipv4PrefixSpecificationRequest{ + apiObject := &awstypes.Ipv4PrefixSpecificationRequest{ Ipv4Prefix: aws.String(tfString), } return apiObject } -func expandIPv4PrefixSpecificationRequests(tfList []any) []types.Ipv4PrefixSpecificationRequest { +func expandIPv4PrefixSpecificationRequests(tfList []any) []awstypes.Ipv4PrefixSpecificationRequest { if len(tfList) == 0 { return nil } - var apiObjects []types.Ipv4PrefixSpecificationRequest + var apiObjects []awstypes.Ipv4PrefixSpecificationRequest for _, tfMapRaw := range tfList { tfString, ok := tfMapRaw.(string) @@ -1390,24 +1381,24 @@ func expandIPv4PrefixSpecificationRequests(tfList []any) []types.Ipv4PrefixSpeci return apiObjects } -func expandIPv6PrefixSpecificationRequest(tfString string) *types.Ipv6PrefixSpecificationRequest { +func expandIPv6PrefixSpecificationRequest(tfString string) *awstypes.Ipv6PrefixSpecificationRequest { if tfString == "" { return nil } - apiObject := &types.Ipv6PrefixSpecificationRequest{ + apiObject := &awstypes.Ipv6PrefixSpecificationRequest{ Ipv6Prefix: aws.String(tfString), } return apiObject } -func expandIPv6PrefixSpecificationRequests(tfList []any) []types.Ipv6PrefixSpecificationRequest { +func expandIPv6PrefixSpecificationRequests(tfList []any) []awstypes.Ipv6PrefixSpecificationRequest { if len(tfList) == 0 { return nil } - var apiObjects []types.Ipv6PrefixSpecificationRequest + var apiObjects []awstypes.Ipv6PrefixSpecificationRequest for _, tfMapRaw := range tfList { tfString, ok := tfMapRaw.(string) @@ -1428,7 +1419,7 @@ func expandIPv6PrefixSpecificationRequests(tfList []any) []types.Ipv6PrefixSpeci return apiObjects } -func flattenIPv4PrefixSpecification(apiObject *types.Ipv4PrefixSpecification) string { +func flattenIPv4PrefixSpecification(apiObject *awstypes.Ipv4PrefixSpecification) string { if apiObject == nil { return "" } @@ -1442,7 +1433,7 @@ func flattenIPv4PrefixSpecification(apiObject *types.Ipv4PrefixSpecification) st return tfString } -func flattenIPv4PrefixSpecifications(apiObjects []types.Ipv4PrefixSpecification) []string { +func flattenIPv4PrefixSpecifications(apiObjects []awstypes.Ipv4PrefixSpecification) []string { if len(apiObjects) == 0 { return nil } @@ -1456,7 +1447,7 @@ func flattenIPv4PrefixSpecifications(apiObjects []types.Ipv4PrefixSpecification) return tfList } -func flattenIPv6PrefixSpecification(apiObject *types.Ipv6PrefixSpecification) string { +func flattenIPv6PrefixSpecification(apiObject *awstypes.Ipv6PrefixSpecification) string { if apiObject == nil { return "" } @@ -1470,7 +1461,7 @@ func flattenIPv6PrefixSpecification(apiObject *types.Ipv6PrefixSpecification) st return tfString } -func flattenIPv6PrefixSpecifications(apiObjects []types.Ipv6PrefixSpecification) []string { +func flattenIPv6PrefixSpecifications(apiObjects []awstypes.Ipv6PrefixSpecification) []string { if len(apiObjects) == 0 { return nil } @@ -1519,7 +1510,7 @@ func deleteLingeringENIs(ctx context.Context, conn *ec2.Client, filterName, reso return g.Wait().ErrorOrNil() } -func deleteLingeringLambdaENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, eni *types.NetworkInterface, timeout time.Duration) bool { +func deleteLingeringLambdaENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, eni *awstypes.NetworkInterface, timeout time.Duration) bool { // AWS Lambda service team confirms P99 deletion time of ~35 minutes. Buffer for safety. if minimumTimeout := 45 * time.Minute; timeout < minimumTimeout { timeout = minimumTimeout @@ -1560,7 +1551,7 @@ func deleteLingeringLambdaENI(ctx context.Context, g *multierror.Group, conn *ec return true } -func deleteLingeringComprehendENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, eni *types.NetworkInterface, timeout time.Duration) bool { +func deleteLingeringComprehendENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, eni *awstypes.NetworkInterface, timeout time.Duration) bool { // Deletion appears to take approximately 5 minutes if minimumTimeout := 10 * time.Minute; timeout < minimumTimeout { timeout = minimumTimeout @@ -1589,7 +1580,7 @@ func deleteLingeringComprehendENI(ctx context.Context, g *multierror.Group, conn return true } -func deleteLingeringDMSENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, v *types.NetworkInterface, timeout time.Duration) bool { +func deleteLingeringDMSENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, v *awstypes.NetworkInterface, timeout time.Duration) bool { // Deletion appears to take approximately 5 minutes if minimumTimeout := 10 * time.Minute; timeout < minimumTimeout { timeout = minimumTimeout @@ -1618,7 +1609,7 @@ func deleteLingeringDMSENI(ctx context.Context, g *multierror.Group, conn *ec2.C return true } -func deleteLingeringRDSENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, v *types.NetworkInterface, timeout time.Duration) bool { +func deleteLingeringRDSENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, v *awstypes.NetworkInterface, timeout time.Duration) bool { // Deletion appears to take approximately 5 minutes if minimumTimeout := 10 * time.Minute; timeout < minimumTimeout { timeout = minimumTimeout @@ -1647,7 +1638,7 @@ func deleteLingeringRDSENI(ctx context.Context, g *multierror.Group, conn *ec2.C return true } -func deleteLingeringQuickSightENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, v *types.NetworkInterface, timeout time.Duration) bool { +func deleteLingeringQuickSightENI(ctx context.Context, g *multierror.Group, conn *ec2.Client, v *awstypes.NetworkInterface, timeout time.Duration) bool { // Deletion appears to take approximately 5 minutes if minimumTimeout := 10 * time.Minute; timeout < minimumTimeout { timeout = minimumTimeout @@ -1677,7 +1668,7 @@ func deleteLingeringQuickSightENI(ctx context.Context, g *multierror.Group, conn } // Flattens security group identifiers into a []string, where the elements returned are the GroupIDs -func flattenGroupIdentifiers(dtos []types.GroupIdentifier) []string { +func flattenGroupIdentifiers(dtos []awstypes.GroupIdentifier) []string { ids := make([]string, 0, len(dtos)) for _, v := range dtos { group_id := aws.ToString(v.GroupId) @@ -1685,3 +1676,7 @@ func flattenGroupIdentifiers(dtos []types.GroupIdentifier) []string { } return ids } + +func networkInterfaceARN(ctx context.Context, c *conns.AWSClient, accountID, networkInterfaceID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "network-interface/"+networkInterfaceID) +} diff --git a/internal/service/ec2/vpc_network_interface_data_source.go b/internal/service/ec2/vpc_network_interface_data_source.go index 2902e9b294b3..e012b38c7973 100644 --- a/internal/service/ec2/vpc_network_interface_data_source.go +++ b/internal/service/ec2/vpc_network_interface_data_source.go @@ -8,9 +8,8 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -168,7 +167,8 @@ func dataSourceNetworkInterface() *schema.Resource { func dataSourceNetworkInterfaceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeNetworkInterfacesInput{} @@ -188,14 +188,7 @@ func dataSourceNetworkInterfaceRead(ctx context.Context, d *schema.ResourceData, d.SetId(aws.ToString(eni.NetworkInterfaceId)) ownerID := aws.ToString(eni.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: "ec2", - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: "network-interface/" + d.Id(), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, networkInterfaceARN(ctx, c, ownerID, d.Id())) if eni.Association != nil { if err := d.Set("association", []any{flattenNetworkInterfaceAssociation(eni.Association)}); err != nil { return sdkdiag.AppendErrorf(diags, "setting association: %s", err) @@ -230,7 +223,7 @@ func dataSourceNetworkInterfaceRead(ctx context.Context, d *schema.ResourceData, return diags } -func flattenNetworkInterfaceAttachmentForDataSource(apiObject *types.NetworkInterfaceAttachment) map[string]any { +func flattenNetworkInterfaceAttachmentForDataSource(apiObject *awstypes.NetworkInterfaceAttachment) map[string]any { if apiObject == nil { return nil } diff --git a/internal/service/ec2/vpc_network_interface_sg_attachment.go b/internal/service/ec2/vpc_network_interface_sg_attachment.go index b75f7e6e9e3d..95938b4f2b66 100644 --- a/internal/service/ec2/vpc_network_interface_sg_attachment.go +++ b/internal/service/ec2/vpc_network_interface_sg_attachment.go @@ -105,7 +105,7 @@ func resourceNetworkInterfaceSGAttachmentRead(ctx context.Context, d *schema.Res networkInterfaceID := d.Get(names.AttrNetworkInterfaceID).(string) sgID := d.Get("security_group_id").(string) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, maxDuration(ec2PropagationTimeout, d.Timeout(schema.TimeoutRead)), func() (any, error) { + groupIdentifier, err := tfresource.RetryWhenNewResourceNotFound(ctx, max(ec2PropagationTimeout, d.Timeout(schema.TimeoutRead)), func(ctx context.Context) (*awstypes.GroupIdentifier, error) { return findNetworkInterfaceSecurityGroup(ctx, conn, networkInterfaceID, sgID) }, d.IsNewResource()) @@ -119,22 +119,12 @@ func resourceNetworkInterfaceSGAttachmentRead(ctx context.Context, d *schema.Res return sdkdiag.AppendErrorf(diags, "reading EC2 Network Interface (%s) Security Group (%s) Attachment: %s", networkInterfaceID, sgID, err) } - groupIdentifier := outputRaw.(*awstypes.GroupIdentifier) - d.Set(names.AttrNetworkInterfaceID, networkInterfaceID) d.Set("security_group_id", groupIdentifier.GroupId) return diags } -func maxDuration(a, b time.Duration) time.Duration { - if a >= b { - return a - } - - return b -} - func resourceNetworkInterfaceSGAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Client(ctx) diff --git a/internal/service/ec2/vpc_network_interface_test.go b/internal/service/ec2/vpc_network_interface_test.go index 24b169c4839a..e5fe7768166f 100644 --- a/internal/service/ec2/vpc_network_interface_test.go +++ b/internal/service/ec2/vpc_network_interface_test.go @@ -14,7 +14,7 @@ import ( "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/endpoints" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -28,7 +28,7 @@ import ( func TestAccVPCNetworkInterface_basic(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" subnetResourceName := "aws_subnet.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -73,7 +73,7 @@ func TestAccVPCNetworkInterface_basic(t *testing.T) { func TestAccVPCNetworkInterface_ipv6(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -119,7 +119,7 @@ func TestAccVPCNetworkInterface_ipv6(t *testing.T) { func TestAccVPCNetworkInterface_ipv6Primary(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -143,7 +143,7 @@ func TestAccVPCNetworkInterface_ipv6Primary(t *testing.T) { func TestAccVPCNetworkInterface_ipv6PrimaryEnable(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -175,7 +175,7 @@ func TestAccVPCNetworkInterface_ipv6PrimaryEnable(t *testing.T) { func TestAccVPCNetworkInterface_ipv6PrimaryDisable(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -209,7 +209,7 @@ func TestAccVPCNetworkInterface_tags(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -254,7 +254,7 @@ func TestAccVPCNetworkInterface_tags(t *testing.T) { func TestAccVPCNetworkInterface_ipv6Count(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -304,7 +304,7 @@ func TestAccVPCNetworkInterface_ipv6Count(t *testing.T) { func TestAccVPCNetworkInterface_disappears(t *testing.T) { ctx := acctest.Context(t) - var networkInterface types.NetworkInterface + var networkInterface awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -328,7 +328,7 @@ func TestAccVPCNetworkInterface_disappears(t *testing.T) { func TestAccVPCNetworkInterface_description(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" subnetResourceName := "aws_subnet.test" securityGroupResourceName := "aws_security_group.test" @@ -402,7 +402,7 @@ func TestAccVPCNetworkInterface_attachment(t *testing.T) { } ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -437,7 +437,7 @@ func TestAccVPCNetworkInterface_attachment(t *testing.T) { func TestAccVPCNetworkInterface_ignoreExternalAttachment(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface var attachmentId string resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -478,7 +478,7 @@ func TestAccVPCNetworkInterface_ignoreExternalAttachment(t *testing.T) { func TestAccVPCNetworkInterface_sourceDestCheck(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -521,7 +521,7 @@ func TestAccVPCNetworkInterface_sourceDestCheck(t *testing.T) { func TestAccVPCNetworkInterface_privateIPsCount(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -589,7 +589,7 @@ func TestAccVPCNetworkInterface_privateIPsCount(t *testing.T) { func TestAccVPCNetworkInterface_ENIInterfaceType_efa(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -618,7 +618,7 @@ func TestAccVPCNetworkInterface_ENIInterfaceType_efa(t *testing.T) { func TestAccVPCNetworkInterface_ENI_ipv4Prefix(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -664,7 +664,7 @@ func TestAccVPCNetworkInterface_ENI_ipv4Prefix(t *testing.T) { func TestAccVPCNetworkInterface_ENI_ipv4PrefixCount(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -714,7 +714,7 @@ func TestAccVPCNetworkInterface_ENI_ipv4PrefixCount(t *testing.T) { func TestAccVPCNetworkInterface_ENI_ipv6Prefix(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -760,7 +760,7 @@ func TestAccVPCNetworkInterface_ENI_ipv6Prefix(t *testing.T) { func TestAccVPCNetworkInterface_ENI_ipv6PrefixCount(t *testing.T) { ctx := acctest.Context(t) - var conf types.NetworkInterface + var conf awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -810,7 +810,7 @@ func TestAccVPCNetworkInterface_ENI_ipv6PrefixCount(t *testing.T) { func TestAccVPCNetworkInterface_privateIPSet(t *testing.T) { ctx := acctest.Context(t) - var networkInterface, lastInterface types.NetworkInterface + var networkInterface, lastInterface awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -906,7 +906,7 @@ func TestAccVPCNetworkInterface_privateIPList(t *testing.T) { } ctx := acctest.Context(t) - var networkInterface, lastInterface types.NetworkInterface + var networkInterface, lastInterface awstypes.NetworkInterface resourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1073,7 +1073,7 @@ func regionalPrivateDNSSuffix(region string) string { return fmt.Sprintf("%s.compute.internal", region) } -func testAccCheckENIExists(ctx context.Context, n string, v *types.NetworkInterface) resource.TestCheckFunc { +func testAccCheckENIExists(ctx context.Context, n string, v *awstypes.NetworkInterface) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -1124,7 +1124,7 @@ func testAccCheckENIDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckENIMakeExternalAttachment(ctx context.Context, n string, networkInterface *types.NetworkInterface, attachmentId *string) resource.TestCheckFunc { +func testAccCheckENIMakeExternalAttachment(ctx context.Context, n string, networkInterface *awstypes.NetworkInterface, attachmentId *string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok || rs.Primary.ID == "" { @@ -1162,7 +1162,7 @@ func testAccCheckENIRemoveExternalAttachment(ctx context.Context, attachmentId * } } -func testAccCheckENIPrivateIPSet(ips []string, iface *types.NetworkInterface) resource.TestCheckFunc { +func testAccCheckENIPrivateIPSet(ips []string, iface *awstypes.NetworkInterface) resource.TestCheckFunc { return func(s *terraform.State) error { iIPs := tfec2.FlattenNetworkInterfacePrivateIPAddresses(iface.PrivateIpAddresses) @@ -1174,7 +1174,7 @@ func testAccCheckENIPrivateIPSet(ips []string, iface *types.NetworkInterface) re } } -func testAccCheckENIPrivateIPList(ips []string, iface *types.NetworkInterface) resource.TestCheckFunc { +func testAccCheckENIPrivateIPList(ips []string, iface *awstypes.NetworkInterface) resource.TestCheckFunc { return func(s *terraform.State) error { iIPs := tfec2.FlattenNetworkInterfacePrivateIPAddresses(iface.PrivateIpAddresses) @@ -1205,7 +1205,7 @@ func stringSlicesEqual(s1, s2 []string) bool { return reflect.DeepEqual(s1, s2) } -func testAccCheckENISame(iface1 *types.NetworkInterface, iface2 *types.NetworkInterface) resource.TestCheckFunc { +func testAccCheckENISame(iface1 *awstypes.NetworkInterface, iface2 *awstypes.NetworkInterface) resource.TestCheckFunc { return func(s *terraform.State) error { if aws.ToString(iface1.NetworkInterfaceId) != aws.ToString(iface2.NetworkInterfaceId) { return fmt.Errorf("interface %s should not have been replaced with %s", aws.ToString(iface1.NetworkInterfaceId), aws.ToString(iface2.NetworkInterfaceId)) @@ -1214,7 +1214,7 @@ func testAccCheckENISame(iface1 *types.NetworkInterface, iface2 *types.NetworkIn } } -func testAccCheckENIDifferent(iface1 *types.NetworkInterface, iface2 *types.NetworkInterface) resource.TestCheckFunc { +func testAccCheckENIDifferent(iface1 *awstypes.NetworkInterface, iface2 *awstypes.NetworkInterface) resource.TestCheckFunc { return func(s *terraform.State) error { if aws.ToString(iface1.NetworkInterfaceId) == aws.ToString(iface2.NetworkInterfaceId) { return fmt.Errorf("interface %s should have been replaced, have %s", aws.ToString(iface1.NetworkInterfaceId), aws.ToString(iface2.NetworkInterfaceId)) diff --git a/internal/service/ec2/vpc_network_performance_metric_subscription.go b/internal/service/ec2/vpc_network_performance_metric_subscription.go index a97fbf7841b9..bf753beb78b1 100644 --- a/internal/service/ec2/vpc_network_performance_metric_subscription.go +++ b/internal/service/ec2/vpc_network_performance_metric_subscription.go @@ -11,7 +11,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -38,8 +38,8 @@ func resourceNetworkPerformanceMetricSubscription() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, - Default: types.MetricTypeAggregateLatency, - ValidateDiagFunc: enum.Validate[types.MetricType](), + Default: awstypes.MetricTypeAggregateLatency, + ValidateDiagFunc: enum.Validate[awstypes.MetricType](), }, "period": { Type: schema.TypeString, @@ -54,8 +54,8 @@ func resourceNetworkPerformanceMetricSubscription() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, - Default: types.StatisticTypeP50, - ValidateDiagFunc: enum.Validate[types.StatisticType](), + Default: awstypes.StatisticTypeP50, + ValidateDiagFunc: enum.Validate[awstypes.StatisticType](), }, }, } @@ -72,9 +72,9 @@ func resourceNetworkPerformanceMetricSubscriptionCreate(ctx context.Context, d * id := networkPerformanceMetricSubscriptionCreateResourceID(source, destination, metric, statistic) input := &ec2.EnableAwsNetworkPerformanceMetricSubscriptionInput{ Destination: aws.String(destination), - Metric: types.MetricType(metric), + Metric: awstypes.MetricType(metric), Source: aws.String(source), - Statistic: types.StatisticType(statistic), + Statistic: awstypes.StatisticType(statistic), } _, err := conn.EnableAwsNetworkPerformanceMetricSubscription(ctx, input) @@ -130,9 +130,9 @@ func resourceNetworkPerformanceMetricSubscriptionDelete(ctx context.Context, d * log.Printf("[DEBUG] Deleting EC2 AWS Network Performance Metric Subscriptione: %s", d.Id()) input := ec2.DisableAwsNetworkPerformanceMetricSubscriptionInput{ Destination: aws.String(destination), - Metric: types.MetricType(metric), + Metric: awstypes.MetricType(metric), Source: aws.String(source), - Statistic: types.StatisticType(statistic), + Statistic: awstypes.StatisticType(statistic), } _, err = conn.DisableAwsNetworkPerformanceMetricSubscription(ctx, &input) diff --git a/internal/service/ec2/vpc_route.go b/internal/service/ec2/vpc_route.go index 2639f97e346e..437954d1132b 100644 --- a/internal/service/ec2/vpc_route.go +++ b/internal/service/ec2/vpc_route.go @@ -302,7 +302,7 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta any) di } routeTableID := d.Get("route_table_id").(string) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + route, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.Route, error) { return routeFinder(ctx, conn, routeTableID, destination) }, d.IsNewResource()) @@ -316,7 +316,6 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta any) di return sdkdiag.AppendErrorf(diags, "reading Route in Route Table (%s) with destination (%s): %s", routeTableID, destination, err) } - route := outputRaw.(*awstypes.Route) d.Set("carrier_gateway_id", route.CarrierGatewayId) d.Set("core_network_arn", route.CoreNetworkArn) d.Set(routeDestinationCIDRBlock, route.DestinationCidrBlock) diff --git a/internal/service/ec2/vpc_route_table.go b/internal/service/ec2/vpc_route_table.go index 7716787f6b4c..bfaa5ef74d99 100644 --- a/internal/service/ec2/vpc_route_table.go +++ b/internal/service/ec2/vpc_route_table.go @@ -12,7 +12,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -213,9 +212,10 @@ func resourceRouteTableCreate(ctx context.Context, d *schema.ResourceData, meta func resourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + routeTable, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.RouteTable, error) { return findRouteTableByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -229,16 +229,8 @@ func resourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta an return sdkdiag.AppendErrorf(diags, "reading Route Table (%s): %s", d.Id(), err) } - routeTable := outputRaw.(*awstypes.RouteTable) ownerID := aws.ToString(routeTable.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("route-table/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, routeTableARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrOwnerID, ownerID) propagatingVGWs := make([]string, 0, len(routeTable.PropagatingVgws)) for _, v := range routeTable.PropagatingVgws { @@ -939,3 +931,7 @@ func routeTableRouteTargetAttribute(m map[string]any) (string, string) { //nolin return "", "" } + +func routeTableARN(ctx context.Context, c *conns.AWSClient, accountID, routeTableID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "route-table/"+routeTableID) +} diff --git a/internal/service/ec2/vpc_route_table_association.go b/internal/service/ec2/vpc_route_table_association.go index bf28fe29d867..6b5a66d16325 100644 --- a/internal/service/ec2/vpc_route_table_association.go +++ b/internal/service/ec2/vpc_route_table_association.go @@ -101,7 +101,7 @@ func resourceRouteTableAssociationRead(ctx context.Context, d *schema.ResourceDa var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + association, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.RouteTableAssociation, error) { return findRouteTableAssociationByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -115,8 +115,6 @@ func resourceRouteTableAssociationRead(ctx context.Context, d *schema.ResourceDa return sdkdiag.AppendErrorf(diags, "reading Route Table Association (%s): %s", d.Id(), err) } - association := outputRaw.(*awstypes.RouteTableAssociation) - d.Set("gateway_id", association.GatewayId) d.Set("route_table_id", association.RouteTableId) d.Set(names.AttrSubnetID, association.SubnetId) diff --git a/internal/service/ec2/vpc_route_table_data_source.go b/internal/service/ec2/vpc_route_table_data_source.go index 5fe313d096c3..f9bf3bc9699e 100644 --- a/internal/service/ec2/vpc_route_table_data_source.go +++ b/internal/service/ec2/vpc_route_table_data_source.go @@ -5,13 +5,11 @@ package ec2 import ( "context" - "fmt" "log" "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -188,7 +186,8 @@ func dataSourceRouteTable() *schema.Resource { func dataSourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig(ctx) req := &ec2.DescribeRouteTablesInput{} @@ -233,14 +232,7 @@ func dataSourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta d.SetId(aws.ToString(rt.RouteTableId)) ownerID := aws.ToString(rt.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("route-table/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, routeTableARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrOwnerID, ownerID) d.Set("route_table_id", rt.RouteTableId) diff --git a/internal/service/ec2/vpc_security_group.go b/internal/service/ec2/vpc_security_group.go index 90041e2c7e82..9d9710cdc46f 100644 --- a/internal/service/ec2/vpc_security_group.go +++ b/internal/service/ec2/vpc_security_group.go @@ -15,7 +15,6 @@ import ( "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -36,7 +35,7 @@ import ( // @SDKResource("aws_security_group", name="Security Group") // @Tags(identifierAttribute="id") -// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/ec2/types;types.SecurityGroup") +// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/ec2/types;awstypes;awstypes.SecurityGroup") // @Testing(importIgnore="revoke_rules_on_delete") func resourceSecurityGroup() *schema.Resource { //lintignore:R011 @@ -187,7 +186,6 @@ var ( func resourceSecurityGroupCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) @@ -267,8 +265,8 @@ func resourceSecurityGroupCreate(ctx context.Context, d *schema.ResourceData, me func resourceSecurityGroupRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) sg, err := findSecurityGroupByID(ctx, conn, d.Id()) @@ -294,14 +292,7 @@ func resourceSecurityGroupRead(ctx context.Context, d *schema.ResourceData, meta egressRules := matchRules("egress", localEgressRules, remoteEgressRules) ownerID := aws.ToString(sg.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("security-group/%s", d.Id()), - } - d.Set(names.AttrARN, arn.String()) + d.Set(names.AttrARN, securityGroupARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrDescription, sg.Description) d.Set(names.AttrName, sg.GroupName) d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(sg.GroupName))) @@ -323,7 +314,6 @@ func resourceSecurityGroupRead(ctx context.Context, d *schema.ResourceData, meta func resourceSecurityGroupUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) group, err := findSecurityGroupByID(ctx, conn, d.Id()) @@ -354,7 +344,7 @@ func resourceSecurityGroupDelete(ctx context.Context, d *schema.ResourceData, me ctx = tflog.SetField(ctx, logging.KeyResourceId, d.Id()) ctx = tflog.SetField(ctx, names.AttrVPCID, d.Get(names.AttrVPCID)) - if err := deleteLingeringENIs(ctx, meta.(*conns.AWSClient).EC2Client(ctx), "group-id", d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + if err := deleteLingeringENIs(ctx, conn, "group-id", d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { return sdkdiag.AppendErrorf(diags, "deleting ENIs using Security Group (%s): %s", d.Id(), err) } @@ -426,6 +416,10 @@ func resourceSecurityGroupDelete(ctx context.Context, d *schema.ResourceData, me return diags } +func securityGroupARN(ctx context.Context, c *conns.AWSClient, accountID, sgID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "security-group/"+sgID) +} + // forceRevokeSecurityGroupRules revokes all of the security group's ingress & egress rules // AND rules in other security groups that depend on this security group. Trying to delete // this security group with rules that originate in other groups but point here, will cause diff --git a/internal/service/ec2/vpc_security_group_data_source.go b/internal/service/ec2/vpc_security_group_data_source.go index 7776b22e4896..df46c2228ccc 100644 --- a/internal/service/ec2/vpc_security_group_data_source.go +++ b/internal/service/ec2/vpc_security_group_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -63,8 +61,8 @@ func dataSourceSecurityGroup() *schema.Resource { func dataSourceSecurityGroupRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeSecurityGroupsInput{ Filters: newAttributeFilterList( @@ -99,15 +97,8 @@ func dataSourceSecurityGroupRead(ctx context.Context, d *schema.ResourceData, me } d.SetId(aws.ToString(sg.GroupId)) - - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: *sg.OwnerId, - Resource: fmt.Sprintf("security-group/%s", *sg.GroupId), - }.String() - d.Set(names.AttrARN, arn) + ownerID := aws.ToString(sg.OwnerId) + d.Set(names.AttrARN, securityGroupARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrDescription, sg.Description) d.Set(names.AttrName, sg.GroupName) d.Set(names.AttrVPCID, sg.VpcId) diff --git a/internal/service/ec2/vpc_security_group_egress_rule.go b/internal/service/ec2/vpc_security_group_egress_rule.go index 78ddd3798d76..c9336773d31f 100644 --- a/internal/service/ec2/vpc_security_group_egress_rule.go +++ b/internal/service/ec2/vpc_security_group_egress_rule.go @@ -15,7 +15,7 @@ import ( // @FrameworkResource("aws_vpc_security_group_egress_rule", name="Security Group Egress Rule") // @Tags(identifierAttribute="id") -// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/ec2/types;types.SecurityGroupRule") +// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/ec2/types;awstypes;awstypes.SecurityGroupRule") func newSecurityGroupEgressRuleResource(context.Context) (resource.ResourceWithConfigure, error) { r := &securityGroupEgressRuleResource{} r.securityGroupRule = r diff --git a/internal/service/ec2/vpc_security_group_egress_rule_tags_gen_test.go b/internal/service/ec2/vpc_security_group_egress_rule_tags_gen_test.go index d77ef1515901..df87c348efc3 100644 --- a/internal/service/ec2/vpc_security_group_egress_rule_tags_gen_test.go +++ b/internal/service/ec2/vpc_security_group_egress_rule_tags_gen_test.go @@ -5,7 +5,7 @@ package ec2_test import ( "testing" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-testing/config" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" @@ -18,7 +18,7 @@ import ( func TestAccVPCSecurityGroupEgressRule_tags(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -200,7 +200,7 @@ func TestAccVPCSecurityGroupEgressRule_tags(t *testing.T) { func TestAccVPCSecurityGroupEgressRule_tags_null(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -262,7 +262,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_null(t *testing.T) { func TestAccVPCSecurityGroupEgressRule_tags_EmptyMap(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -312,7 +312,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_EmptyMap(t *testing.T) { func TestAccVPCSecurityGroupEgressRule_tags_AddOnUpdate(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -392,7 +392,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_AddOnUpdate(t *testing.T) { func TestAccVPCSecurityGroupEgressRule_tags_EmptyTag_OnCreate(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -482,7 +482,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_EmptyTag_OnCreate(t *testing.T) { func TestAccVPCSecurityGroupEgressRule_tags_EmptyTag_OnUpdate_Add(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -621,7 +621,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_EmptyTag_OnUpdate_Add(t *testing.T) func TestAccVPCSecurityGroupEgressRule_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -711,7 +711,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_EmptyTag_OnUpdate_Replace(t *testing func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_providerOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -892,7 +892,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_providerOnly(t *testing. func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_nonOverlapping(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1052,7 +1052,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_nonOverlapping(t *testin func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_overlapping(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1228,7 +1228,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_overlapping(t *testing.T func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_updateToProviderOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1318,7 +1318,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_updateToProviderOnly(t * func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_updateToResourceOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1407,7 +1407,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_updateToResourceOnly(t * func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_emptyResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1473,7 +1473,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_emptyResourceTag(t *test func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1531,7 +1531,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_emptyProviderOnlyTag(t * func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1600,7 +1600,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_nullOverlappingResourceT func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1671,7 +1671,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_DefaultTags_nullNonOverlappingResour func TestAccVPCSecurityGroupEgressRule_tags_ComputedTag_OnCreate(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1726,7 +1726,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_ComputedTag_OnCreate(t *testing.T) { func TestAccVPCSecurityGroupEgressRule_tags_ComputedTag_OnUpdate_Add(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1823,7 +1823,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_ComputedTag_OnUpdate_Add(t *testing. func TestAccVPCSecurityGroupEgressRule_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1910,7 +1910,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_ComputedTag_OnUpdate_Replace(t *test func TestAccVPCSecurityGroupEgressRule_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -2072,7 +2072,7 @@ func TestAccVPCSecurityGroupEgressRule_tags_IgnoreTags_Overlap_DefaultTag(t *tes func TestAccVPCSecurityGroupEgressRule_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_egress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) diff --git a/internal/service/ec2/vpc_security_group_ingress_rule.go b/internal/service/ec2/vpc_security_group_ingress_rule.go index ab2b26ec5cbd..4d3e2e6fc1c5 100644 --- a/internal/service/ec2/vpc_security_group_ingress_rule.go +++ b/internal/service/ec2/vpc_security_group_ingress_rule.go @@ -43,7 +43,7 @@ import ( // @FrameworkResource("aws_vpc_security_group_ingress_rule", name="Security Group Ingress Rule") // @Tags(identifierAttribute="id") -// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/ec2/types;types.SecurityGroupRule") +// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/ec2/types;awstypes;awstypes.SecurityGroupRule") func newSecurityGroupIngressRuleResource(context.Context) (resource.ResourceWithConfigure, error) { r := &securityGroupIngressRuleResource{} r.securityGroupRule = r diff --git a/internal/service/ec2/vpc_security_group_ingress_rule_tags_gen_test.go b/internal/service/ec2/vpc_security_group_ingress_rule_tags_gen_test.go index 513edb5f9e90..a336b5e413b0 100644 --- a/internal/service/ec2/vpc_security_group_ingress_rule_tags_gen_test.go +++ b/internal/service/ec2/vpc_security_group_ingress_rule_tags_gen_test.go @@ -5,7 +5,7 @@ package ec2_test import ( "testing" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-testing/config" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" @@ -18,7 +18,7 @@ import ( func TestAccVPCSecurityGroupIngressRule_tags(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -200,7 +200,7 @@ func TestAccVPCSecurityGroupIngressRule_tags(t *testing.T) { func TestAccVPCSecurityGroupIngressRule_tags_null(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -262,7 +262,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_null(t *testing.T) { func TestAccVPCSecurityGroupIngressRule_tags_EmptyMap(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -312,7 +312,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_EmptyMap(t *testing.T) { func TestAccVPCSecurityGroupIngressRule_tags_AddOnUpdate(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -392,7 +392,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_AddOnUpdate(t *testing.T) { func TestAccVPCSecurityGroupIngressRule_tags_EmptyTag_OnCreate(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -482,7 +482,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_EmptyTag_OnCreate(t *testing.T) { func TestAccVPCSecurityGroupIngressRule_tags_EmptyTag_OnUpdate_Add(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -621,7 +621,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_EmptyTag_OnUpdate_Add(t *testing.T) func TestAccVPCSecurityGroupIngressRule_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -711,7 +711,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_EmptyTag_OnUpdate_Replace(t *testin func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_providerOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -892,7 +892,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_providerOnly(t *testing func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_nonOverlapping(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1052,7 +1052,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_nonOverlapping(t *testi func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_overlapping(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1228,7 +1228,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_overlapping(t *testing. func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_updateToProviderOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1318,7 +1318,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_updateToProviderOnly(t func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_updateToResourceOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1407,7 +1407,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_updateToResourceOnly(t func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_emptyResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1473,7 +1473,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_emptyResourceTag(t *tes func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1531,7 +1531,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_emptyProviderOnlyTag(t func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1600,7 +1600,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_nullOverlappingResource func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1671,7 +1671,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_DefaultTags_nullNonOverlappingResou func TestAccVPCSecurityGroupIngressRule_tags_ComputedTag_OnCreate(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1726,7 +1726,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_ComputedTag_OnCreate(t *testing.T) func TestAccVPCSecurityGroupIngressRule_tags_ComputedTag_OnUpdate_Add(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1823,7 +1823,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_ComputedTag_OnUpdate_Add(t *testing func TestAccVPCSecurityGroupIngressRule_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1910,7 +1910,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_ComputedTag_OnUpdate_Replace(t *tes func TestAccVPCSecurityGroupIngressRule_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -2072,7 +2072,7 @@ func TestAccVPCSecurityGroupIngressRule_tags_IgnoreTags_Overlap_DefaultTag(t *te func TestAccVPCSecurityGroupIngressRule_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroupRule + var v awstypes.SecurityGroupRule resourceName := "aws_vpc_security_group_ingress_rule.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) diff --git a/internal/service/ec2/vpc_security_group_tags_gen_test.go b/internal/service/ec2/vpc_security_group_tags_gen_test.go index 8a9ae63bf7b4..3dce23c53b9e 100644 --- a/internal/service/ec2/vpc_security_group_tags_gen_test.go +++ b/internal/service/ec2/vpc_security_group_tags_gen_test.go @@ -5,7 +5,7 @@ package ec2_test import ( "testing" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-testing/config" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" @@ -18,7 +18,7 @@ import ( func TestAccVPCSecurityGroup_tags(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -212,7 +212,7 @@ func TestAccVPCSecurityGroup_tags(t *testing.T) { func TestAccVPCSecurityGroup_tags_null(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -282,7 +282,7 @@ func TestAccVPCSecurityGroup_tags_null(t *testing.T) { func TestAccVPCSecurityGroup_tags_EmptyMap(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -348,7 +348,7 @@ func TestAccVPCSecurityGroup_tags_EmptyMap(t *testing.T) { func TestAccVPCSecurityGroup_tags_AddOnUpdate(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -432,7 +432,7 @@ func TestAccVPCSecurityGroup_tags_AddOnUpdate(t *testing.T) { func TestAccVPCSecurityGroup_tags_EmptyTag_OnCreate(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -527,7 +527,7 @@ func TestAccVPCSecurityGroup_tags_EmptyTag_OnCreate(t *testing.T) { func TestAccVPCSecurityGroup_tags_EmptyTag_OnUpdate_Add(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -670,7 +670,7 @@ func TestAccVPCSecurityGroup_tags_EmptyTag_OnUpdate_Add(t *testing.T) { func TestAccVPCSecurityGroup_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -762,7 +762,7 @@ func TestAccVPCSecurityGroup_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { func TestAccVPCSecurityGroup_tags_DefaultTags_providerOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -955,7 +955,7 @@ func TestAccVPCSecurityGroup_tags_DefaultTags_providerOnly(t *testing.T) { func TestAccVPCSecurityGroup_tags_DefaultTags_nonOverlapping(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1124,7 +1124,7 @@ func TestAccVPCSecurityGroup_tags_DefaultTags_nonOverlapping(t *testing.T) { func TestAccVPCSecurityGroup_tags_DefaultTags_overlapping(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1309,7 +1309,7 @@ func TestAccVPCSecurityGroup_tags_DefaultTags_overlapping(t *testing.T) { func TestAccVPCSecurityGroup_tags_DefaultTags_updateToProviderOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1402,7 +1402,7 @@ func TestAccVPCSecurityGroup_tags_DefaultTags_updateToProviderOnly(t *testing.T) func TestAccVPCSecurityGroup_tags_DefaultTags_updateToResourceOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1494,7 +1494,7 @@ func TestAccVPCSecurityGroup_tags_DefaultTags_updateToResourceOnly(t *testing.T) func TestAccVPCSecurityGroup_tags_DefaultTags_emptyResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1562,7 +1562,7 @@ func TestAccVPCSecurityGroup_tags_DefaultTags_emptyResourceTag(t *testing.T) { func TestAccVPCSecurityGroup_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1622,7 +1622,7 @@ func TestAccVPCSecurityGroup_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) func TestAccVPCSecurityGroup_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1687,7 +1687,7 @@ func TestAccVPCSecurityGroup_tags_DefaultTags_nullOverlappingResourceTag(t *test func TestAccVPCSecurityGroup_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1752,7 +1752,7 @@ func TestAccVPCSecurityGroup_tags_DefaultTags_nullNonOverlappingResourceTag(t *t func TestAccVPCSecurityGroup_tags_ComputedTag_OnCreate(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1810,7 +1810,7 @@ func TestAccVPCSecurityGroup_tags_ComputedTag_OnCreate(t *testing.T) { func TestAccVPCSecurityGroup_tags_ComputedTag_OnUpdate_Add(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -1910,7 +1910,7 @@ func TestAccVPCSecurityGroup_tags_ComputedTag_OnUpdate_Add(t *testing.T) { func TestAccVPCSecurityGroup_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -2000,7 +2000,7 @@ func TestAccVPCSecurityGroup_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { func TestAccVPCSecurityGroup_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) @@ -2162,7 +2162,7 @@ func TestAccVPCSecurityGroup_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { func TestAccVPCSecurityGroup_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.SecurityGroup + var v awstypes.SecurityGroup resourceName := "aws_security_group.test" rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) diff --git a/internal/service/ec2/vpc_security_groups_data_source.go b/internal/service/ec2/vpc_security_groups_data_source.go index 96186c844ed4..4e8e27cf4020 100644 --- a/internal/service/ec2/vpc_security_groups_data_source.go +++ b/internal/service/ec2/vpc_security_groups_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -52,8 +50,8 @@ func dataSourceSecurityGroups() *schema.Resource { func dataSourceSecurityGroupsRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeSecurityGroupsInput{} @@ -78,19 +76,13 @@ func dataSourceSecurityGroupsRead(ctx context.Context, d *schema.ResourceData, m var arns, securityGroupIDs, vpcIDs []string for _, v := range output { - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: aws.ToString(v.OwnerId), - Resource: fmt.Sprintf("security-group/%s", aws.ToString(v.GroupId)), - }.String() - arns = append(arns, arn) - securityGroupIDs = append(securityGroupIDs, aws.ToString(v.GroupId)) + ownerID, sgID := aws.ToString(v.OwnerId), aws.ToString(v.GroupId) + arns = append(arns, securityGroupARN(ctx, c, ownerID, sgID)) + securityGroupIDs = append(securityGroupIDs, sgID) vpcIDs = append(vpcIDs, aws.ToString(v.VpcId)) } - d.SetId(meta.(*conns.AWSClient).Region(ctx)) + d.SetId(c.Region(ctx)) d.Set(names.AttrARNs, arns) d.Set(names.AttrIDs, securityGroupIDs) d.Set("vpc_ids", vpcIDs) diff --git a/internal/service/ec2/vpc_subnet.go b/internal/service/ec2/vpc_subnet.go index 82c33b50df9b..f9158e365028 100644 --- a/internal/service/ec2/vpc_subnet.go +++ b/internal/service/ec2/vpc_subnet.go @@ -29,7 +29,7 @@ import ( // @SDKResource("aws_subnet", name="Subnet") // @Tags(identifierAttribute="id") -// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/ec2/types;types.Subnet") +// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/ec2/types;awstypes;awstypes.Subnet") // @Testing(generator=false) func resourceSubnet() *schema.Resource { //lintignore:R011 @@ -231,7 +231,7 @@ func resourceSubnetRead(ctx context.Context, d *schema.ResourceData, meta any) d var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + subnet, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.Subnet, error) { return findSubnetByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -245,8 +245,6 @@ func resourceSubnetRead(ctx context.Context, d *schema.ResourceData, meta any) d return sdkdiag.AppendErrorf(diags, "reading EC2 Subnet (%s): %s", d.Id(), err) } - subnet := outputRaw.(*awstypes.Subnet) - d.Set(names.AttrARN, subnet.SubnetArn) d.Set("assign_ipv6_address_on_creation", subnet.AssignIpv6AddressOnCreation) d.Set(names.AttrAvailabilityZone, subnet.AvailabilityZone) diff --git a/internal/service/ec2/vpc_subnet_tags_gen_test.go b/internal/service/ec2/vpc_subnet_tags_gen_test.go index b0522e6c3a20..3178bb9e0383 100644 --- a/internal/service/ec2/vpc_subnet_tags_gen_test.go +++ b/internal/service/ec2/vpc_subnet_tags_gen_test.go @@ -5,7 +5,7 @@ package ec2_test import ( "testing" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-testing/config" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" @@ -18,7 +18,7 @@ import ( func TestAccVPCSubnet_tags(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -191,7 +191,7 @@ func TestAccVPCSubnet_tags(t *testing.T) { func TestAccVPCSubnet_tags_null(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -254,7 +254,7 @@ func TestAccVPCSubnet_tags_null(t *testing.T) { func TestAccVPCSubnet_tags_EmptyMap(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -313,7 +313,7 @@ func TestAccVPCSubnet_tags_EmptyMap(t *testing.T) { func TestAccVPCSubnet_tags_AddOnUpdate(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -390,7 +390,7 @@ func TestAccVPCSubnet_tags_AddOnUpdate(t *testing.T) { func TestAccVPCSubnet_tags_EmptyTag_OnCreate(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -474,7 +474,7 @@ func TestAccVPCSubnet_tags_EmptyTag_OnCreate(t *testing.T) { func TestAccVPCSubnet_tags_EmptyTag_OnUpdate_Add(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -605,7 +605,7 @@ func TestAccVPCSubnet_tags_EmptyTag_OnUpdate_Add(t *testing.T) { func TestAccVPCSubnet_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -690,7 +690,7 @@ func TestAccVPCSubnet_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { func TestAccVPCSubnet_tags_DefaultTags_providerOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -862,7 +862,7 @@ func TestAccVPCSubnet_tags_DefaultTags_providerOnly(t *testing.T) { func TestAccVPCSubnet_tags_DefaultTags_nonOverlapping(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1015,7 +1015,7 @@ func TestAccVPCSubnet_tags_DefaultTags_nonOverlapping(t *testing.T) { func TestAccVPCSubnet_tags_DefaultTags_overlapping(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1184,7 +1184,7 @@ func TestAccVPCSubnet_tags_DefaultTags_overlapping(t *testing.T) { func TestAccVPCSubnet_tags_DefaultTags_updateToProviderOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1270,7 +1270,7 @@ func TestAccVPCSubnet_tags_DefaultTags_updateToProviderOnly(t *testing.T) { func TestAccVPCSubnet_tags_DefaultTags_updateToResourceOnly(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1355,7 +1355,7 @@ func TestAccVPCSubnet_tags_DefaultTags_updateToResourceOnly(t *testing.T) { func TestAccVPCSubnet_tags_DefaultTags_emptyResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1417,7 +1417,7 @@ func TestAccVPCSubnet_tags_DefaultTags_emptyResourceTag(t *testing.T) { func TestAccVPCSubnet_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1471,7 +1471,7 @@ func TestAccVPCSubnet_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { func TestAccVPCSubnet_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1530,7 +1530,7 @@ func TestAccVPCSubnet_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) func TestAccVPCSubnet_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1589,7 +1589,7 @@ func TestAccVPCSubnet_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing. func TestAccVPCSubnet_tags_ComputedTag_OnCreate(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1641,7 +1641,7 @@ func TestAccVPCSubnet_tags_ComputedTag_OnCreate(t *testing.T) { func TestAccVPCSubnet_tags_ComputedTag_OnUpdate_Add(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1734,7 +1734,7 @@ func TestAccVPCSubnet_tags_ComputedTag_OnUpdate_Add(t *testing.T) { func TestAccVPCSubnet_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1817,7 +1817,7 @@ func TestAccVPCSubnet_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { func TestAccVPCSubnet_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ @@ -1975,7 +1975,7 @@ func TestAccVPCSubnet_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { func TestAccVPCSubnet_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { ctx := acctest.Context(t) - var v types.Subnet + var v awstypes.Subnet resourceName := "aws_subnet.test" acctest.ParallelTest(ctx, t, resource.TestCase{ diff --git a/internal/service/ec2/vpc_traffic_mirror_filter.go b/internal/service/ec2/vpc_traffic_mirror_filter.go index c4a193677643..7f699c8337a8 100644 --- a/internal/service/ec2/vpc_traffic_mirror_filter.go +++ b/internal/service/ec2/vpc_traffic_mirror_filter.go @@ -8,7 +8,6 @@ import ( "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -105,7 +104,8 @@ func resourceTrafficMirrorFilterCreate(ctx context.Context, d *schema.ResourceDa func resourceTrafficMirrorFilterRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) trafficMirrorFilter, err := findTrafficMirrorFilterByID(ctx, conn, d.Id()) @@ -119,14 +119,7 @@ func resourceTrafficMirrorFilterRead(ctx context.Context, d *schema.ResourceData return sdkdiag.AppendErrorf(diags, "reading EC2 Traffic Mirror Filter (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: "ec2", - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: "traffic-mirror-filter/" + d.Id(), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, trafficMirrorFilterARN(ctx, c, d.Id())) d.Set(names.AttrDescription, trafficMirrorFilter.Description) d.Set("network_services", trafficMirrorFilter.NetworkServices) @@ -184,3 +177,7 @@ func resourceTrafficMirrorFilterDelete(ctx context.Context, d *schema.ResourceDa return diags } + +func trafficMirrorFilterARN(ctx context.Context, c *conns.AWSClient, trafficMirrorFilterID string) string { + return c.RegionalARN(ctx, names.EC2, "traffic-mirror-filter/"+trafficMirrorFilterID) +} diff --git a/internal/service/ec2/vpc_traffic_mirror_filter_rule.go b/internal/service/ec2/vpc_traffic_mirror_filter_rule.go index 5926fc0bcae9..f900dd2910fd 100644 --- a/internal/service/ec2/vpc_traffic_mirror_filter_rule.go +++ b/internal/service/ec2/vpc_traffic_mirror_filter_rule.go @@ -10,7 +10,6 @@ import ( "strings" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -165,7 +164,8 @@ func resourceTrafficMirrorFilterRuleCreate(ctx context.Context, d *schema.Resour func resourceTrafficMirrorFilterRuleRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) rule, err := findTrafficMirrorFilterRuleByTwoPartKey(ctx, conn, d.Get("traffic_mirror_filter_id").(string), d.Id()) @@ -179,14 +179,7 @@ func resourceTrafficMirrorFilterRuleRead(ctx context.Context, d *schema.Resource return sdkdiag.AppendErrorf(diags, "reading EC2 Traffic Mirror Filter Rule (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: "ec2", - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: "traffic-mirror-filter-rule/" + d.Id(), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, trafficMirrorFilterRuleARN(ctx, c, d.Id())) d.Set(names.AttrDescription, rule.Description) d.Set("destination_cidr_block", rule.DestinationCidrBlock) if rule.DestinationPortRange != nil { @@ -325,6 +318,10 @@ func resourceTrafficMirrorFilterRuleImport(ctx context.Context, d *schema.Resour return []*schema.ResourceData{d}, nil } +func trafficMirrorFilterRuleARN(ctx context.Context, c *conns.AWSClient, trafficMirrorFilterRuleID string) string { + return c.RegionalARN(ctx, names.EC2, "traffic-mirror-filter-rule/"+trafficMirrorFilterRuleID) +} + func expandTrafficMirrorPortRangeRequest(tfMap map[string]any) *awstypes.TrafficMirrorPortRangeRequest { if tfMap == nil { return nil diff --git a/internal/service/ec2/vpc_traffic_mirror_session.go b/internal/service/ec2/vpc_traffic_mirror_session.go index 2257e70a95cb..ed6f3baae7ae 100644 --- a/internal/service/ec2/vpc_traffic_mirror_session.go +++ b/internal/service/ec2/vpc_traffic_mirror_session.go @@ -8,7 +8,6 @@ import ( "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -126,7 +125,8 @@ func resourceTrafficMirrorSessionCreate(ctx context.Context, d *schema.ResourceD func resourceTrafficMirrorSessionRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) session, err := findTrafficMirrorSessionByID(ctx, conn, d.Id()) @@ -141,14 +141,7 @@ func resourceTrafficMirrorSessionRead(ctx context.Context, d *schema.ResourceDat } ownerID := aws.ToString(session.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: "ec2", - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: "traffic-mirror-session/" + d.Id(), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, trafficMirrorSessionARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrDescription, session.Description) d.Set(names.AttrNetworkInterfaceID, session.NetworkInterfaceId) d.Set(names.AttrOwnerID, ownerID) @@ -244,3 +237,7 @@ func resourceTrafficMirrorSessionDelete(ctx context.Context, d *schema.ResourceD return diags } + +func trafficMirrorSessionARN(ctx context.Context, c *conns.AWSClient, accountID, trafficMirrorSessionID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "traffic-mirror-session/"+trafficMirrorSessionID) +} diff --git a/internal/service/ec2/vpc_traffic_mirror_target.go b/internal/service/ec2/vpc_traffic_mirror_target.go index c39f34040db2..0373400d425a 100644 --- a/internal/service/ec2/vpc_traffic_mirror_target.go +++ b/internal/service/ec2/vpc_traffic_mirror_target.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -127,7 +125,8 @@ func resourceTrafficMirrorTargetCreate(ctx context.Context, d *schema.ResourceDa func resourceTrafficMirrorTargetRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) target, err := findTrafficMirrorTargetByID(ctx, conn, d.Id()) @@ -142,14 +141,7 @@ func resourceTrafficMirrorTargetRead(ctx context.Context, d *schema.ResourceData } ownerID := aws.ToString(target.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("traffic-mirror-target/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, trafficMirrorTargetARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrDescription, target.Description) d.Set("gateway_load_balancer_endpoint_id", target.GatewayLoadBalancerEndpointId) d.Set(names.AttrNetworkInterfaceID, target.NetworkInterfaceId) @@ -189,3 +181,7 @@ func resourceTrafficMirrorTargetDelete(ctx context.Context, d *schema.ResourceDa return diags } + +func trafficMirrorTargetARN(ctx context.Context, c *conns.AWSClient, accountID, trafficMirrorTargetID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "traffic-mirror-target/"+trafficMirrorTargetID) +} diff --git a/internal/service/ec2/vpnclient_endpoint.go b/internal/service/ec2/vpnclient_endpoint.go index 60d72ce25d3e..11ce355714ed 100644 --- a/internal/service/ec2/vpnclient_endpoint.go +++ b/internal/service/ec2/vpnclient_endpoint.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -324,7 +322,8 @@ func resourceClientVPNEndpointCreate(ctx context.Context, d *schema.ResourceData func resourceClientVPNEndpointRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) ep, err := findClientVPNEndpointByID(ctx, conn, d.Id()) @@ -338,14 +337,7 @@ func resourceClientVPNEndpointRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "reading EC2 Client VPN Endpoint (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("client-vpn-endpoint/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, clientVPNEndpointARN(ctx, c, d.Id())) if err := d.Set("authentication_options", flattenClientVPNAuthentications(ep.AuthenticationOptions)); err != nil { return sdkdiag.AppendErrorf(diags, "setting authentication_options: %s", err) } @@ -792,3 +784,7 @@ func flattenClientRouteEnforcementOptions(apiObject *awstypes.ClientRouteEnforce return tfMap } + +func clientVPNEndpointARN(ctx context.Context, c *conns.AWSClient, clientVPNEndpointID string) string { + return c.RegionalARN(ctx, names.EC2, "client-vpn-endpoint/"+clientVPNEndpointID) +} diff --git a/internal/service/ec2/vpnclient_endpoint_data_source.go b/internal/service/ec2/vpnclient_endpoint_data_source.go index be33b58f92a2..dd57af467bea 100644 --- a/internal/service/ec2/vpnclient_endpoint_data_source.go +++ b/internal/service/ec2/vpnclient_endpoint_data_source.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -196,7 +194,8 @@ func dataSourceClientVPNEndpoint() *schema.Resource { func dataSourceClientVPNEndpointRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := &ec2.DescribeClientVpnEndpointsInput{} @@ -223,14 +222,7 @@ func dataSourceClientVPNEndpointRead(ctx context.Context, d *schema.ResourceData } d.SetId(aws.ToString(ep.ClientVpnEndpointId)) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("client-vpn-endpoint/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, clientVPNEndpointARN(ctx, c, d.Id())) if err := d.Set("authentication_options", flattenClientVPNAuthentications(ep.AuthenticationOptions)); err != nil { return sdkdiag.AppendErrorf(diags, "setting authentication_options: %s", err) } diff --git a/internal/service/ec2/vpnsite_customer_gateway.go b/internal/service/ec2/vpnsite_customer_gateway.go index af9e9adfbcd5..259dbc334363 100644 --- a/internal/service/ec2/vpnsite_customer_gateway.go +++ b/internal/service/ec2/vpnsite_customer_gateway.go @@ -5,12 +5,10 @@ package ec2 import ( "context" - "fmt" "log" "strconv" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -147,7 +145,8 @@ func resourceCustomerGatewayCreate(ctx context.Context, d *schema.ResourceData, func resourceCustomerGatewayRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) customerGateway, err := findCustomerGatewayByID(ctx, conn, d.Id()) @@ -161,14 +160,7 @@ func resourceCustomerGatewayRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "reading EC2 Customer Gateway (%s): %s", d.Id(), err) } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("customer-gateway/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, customerGatewayARN(ctx, c, d.Id())) d.Set("bgp_asn", customerGateway.BgpAsn) d.Set("bgp_asn_extended", customerGateway.BgpAsnExtended) d.Set(names.AttrCertificateARN, customerGateway.CertificateArn) @@ -210,3 +202,7 @@ func resourceCustomerGatewayDelete(ctx context.Context, d *schema.ResourceData, return diags } + +func customerGatewayARN(ctx context.Context, c *conns.AWSClient, customerGatewayID string) string { + return c.RegionalARN(ctx, names.EC2, "customer-gateway/"+customerGatewayID) +} diff --git a/internal/service/ec2/vpnsite_customer_gateway_data_source.go b/internal/service/ec2/vpnsite_customer_gateway_data_source.go index 4c33af33c744..fd33a3f5eb12 100644 --- a/internal/service/ec2/vpnsite_customer_gateway_data_source.go +++ b/internal/service/ec2/vpnsite_customer_gateway_data_source.go @@ -5,12 +5,10 @@ package ec2 import ( "context" - "fmt" "strconv" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -74,7 +72,8 @@ func dataSourceCustomerGateway() *schema.Resource { func dataSourceCustomerGatewayRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := ec2.DescribeCustomerGatewaysInput{} @@ -93,15 +92,7 @@ func dataSourceCustomerGatewayRead(ctx context.Context, d *schema.ResourceData, } d.SetId(aws.ToString(cgw.CustomerGatewayId)) - - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("customer-gateway/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, customerGatewayARN(ctx, c, d.Id())) if v := aws.ToString(cgw.BgpAsn); v != "" { v, err := strconv.ParseInt(v, 0, 0) diff --git a/internal/service/ec2/vpnsite_gateway.go b/internal/service/ec2/vpnsite_gateway.go index 2cf9fbb3c73a..89f959af034c 100644 --- a/internal/service/ec2/vpnsite_gateway.go +++ b/internal/service/ec2/vpnsite_gateway.go @@ -10,7 +10,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -104,9 +103,10 @@ func resourceVPNGatewayCreate(ctx context.Context, d *schema.ResourceData, meta func resourceVPNGatewayRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (any, error) { + vpnGateway, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func(ctx context.Context) (*awstypes.VpnGateway, error) { return findVPNGatewayByID(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -120,17 +120,8 @@ func resourceVPNGatewayRead(ctx context.Context, d *schema.ResourceData, meta an return sdkdiag.AppendErrorf(diags, "reading EC2 VPN Gateway (%s): %s", d.Id(), err) } - vpnGateway := outputRaw.(*awstypes.VpnGateway) - d.Set("amazon_side_asn", flex.Int64ToStringValue(vpnGateway.AmazonSideAsn)) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("vpn-gateway/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, vpnGatewayARN(ctx, c, d.Id())) if aws.ToString(vpnGateway.AvailabilityZone) != "" { d.Set(names.AttrAvailabilityZone, vpnGateway.AvailabilityZone) } @@ -247,3 +238,7 @@ func detachVPNGatewayFromVPC(ctx context.Context, conn *ec2.Client, vpnGatewayID return nil } + +func vpnGatewayARN(ctx context.Context, c *conns.AWSClient, vpnGatewayID string) string { + return c.RegionalARN(ctx, names.EC2, "vpn-gateway/"+vpnGatewayID) +} diff --git a/internal/service/ec2/vpnsite_gateway_data_source.go b/internal/service/ec2/vpnsite_gateway_data_source.go index 54b8ec3bf892..27144a5da1f7 100644 --- a/internal/service/ec2/vpnsite_gateway_data_source.go +++ b/internal/service/ec2/vpnsite_gateway_data_source.go @@ -5,12 +5,10 @@ package ec2 import ( "context" - "fmt" "strconv" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -71,7 +69,8 @@ func dataSourceVPNGateway() *schema.Resource { func dataSourceVPNGatewayRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) input := ec2.DescribeVpnGatewaysInput{} @@ -118,16 +117,8 @@ func dataSourceVPNGatewayRead(ctx context.Context, d *schema.ResourceData, meta } d.SetId(aws.ToString(vgw.VpnGatewayId)) - d.Set("amazon_side_asn", strconv.FormatInt(aws.ToInt64(vgw.AmazonSideAsn), 10)) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: meta.(*conns.AWSClient).AccountID(ctx), - Resource: fmt.Sprintf("vpn-gateway/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, vpnGatewayARN(ctx, c, d.Id())) for _, attachment := range vgw.VpcAttachments { if attachment.State == awstypes.AttachmentStatusAttached { d.Set("attached_vpc_id", attachment.VpcId) diff --git a/internal/service/ec2/wavelength_carrier_gateway.go b/internal/service/ec2/wavelength_carrier_gateway.go index ea38c98eca3c..fe33a7897aa1 100644 --- a/internal/service/ec2/wavelength_carrier_gateway.go +++ b/internal/service/ec2/wavelength_carrier_gateway.go @@ -5,11 +5,9 @@ package ec2 import ( "context" - "fmt" "log" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/ec2" awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" @@ -84,7 +82,8 @@ func resourceCarrierGatewayCreate(ctx context.Context, d *schema.ResourceData, m func resourceCarrierGatewayRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Client(ctx) + c := meta.(*conns.AWSClient) + conn := c.EC2Client(ctx) carrierGateway, err := findCarrierGatewayByID(ctx, conn, d.Id()) @@ -99,14 +98,7 @@ func resourceCarrierGatewayRead(ctx context.Context, d *schema.ResourceData, met } ownerID := aws.ToString(carrierGateway.OwnerId) - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition(ctx), - Service: names.EC2, - Region: meta.(*conns.AWSClient).Region(ctx), - AccountID: ownerID, - Resource: fmt.Sprintf("carrier-gateway/%s", d.Id()), - }.String() - d.Set(names.AttrARN, arn) + d.Set(names.AttrARN, carrierGatewayARN(ctx, c, ownerID, d.Id())) d.Set(names.AttrOwnerID, ownerID) d.Set(names.AttrVPCID, carrierGateway.VpcId) @@ -147,3 +139,7 @@ func resourceCarrierGatewayDelete(ctx context.Context, d *schema.ResourceData, m return diags } + +func carrierGatewayARN(ctx context.Context, c *conns.AWSClient, accountID, carrierGatewayID string) string { + return c.RegionalARNWithAccount(ctx, names.EC2, accountID, "carrier-gateway/"+carrierGatewayID) +} diff --git a/internal/service/ecr/lifecycle_policy.go b/internal/service/ecr/lifecycle_policy.go index c2bf61f7fdfe..4e5bde6f5f77 100644 --- a/internal/service/ecr/lifecycle_policy.go +++ b/internal/service/ecr/lifecycle_policy.go @@ -94,7 +94,7 @@ func resourceLifecyclePolicyRead(ctx context.Context, d *schema.ResourceData, me var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ECRClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + output, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*ecr.GetLifecyclePolicyOutput, error) { return findLifecyclePolicyByRepositoryName(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -108,8 +108,6 @@ func resourceLifecyclePolicyRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "reading ECR Lifecycle Policy (%s): %s", d.Id(), err) } - output := outputRaw.(*ecr.GetLifecyclePolicyOutput) - if equivalent, err := equivalentLifecyclePolicyJSON(d.Get(names.AttrPolicy).(string), aws.ToString(output.LifecyclePolicyText)); err != nil { return sdkdiag.AppendFromErr(diags, err) } else if !equivalent { diff --git a/internal/service/ecr/repository.go b/internal/service/ecr/repository.go index f083bb5e360a..f48e064dbed4 100644 --- a/internal/service/ecr/repository.go +++ b/internal/service/ecr/repository.go @@ -167,7 +167,7 @@ func resourceRepositoryRead(ctx context.Context, d *schema.ResourceData, meta an var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ECRClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + repository, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*types.Repository, error) { return findRepositoryByName(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -181,8 +181,6 @@ func resourceRepositoryRead(ctx context.Context, d *schema.ResourceData, meta an return sdkdiag.AppendErrorf(diags, "reading ECR Repository (%s): %s", d.Id(), err) } - repository := outputRaw.(*types.Repository) - d.Set(names.AttrARN, repository.RepositoryArn) if err := d.Set(names.AttrEncryptionConfiguration, flattenRepositoryEncryptionConfiguration(repository.EncryptionConfiguration)); err != nil { return sdkdiag.AppendErrorf(diags, "setting encryption_configuration: %s", err) diff --git a/internal/service/ecr/repository_policy.go b/internal/service/ecr/repository_policy.go index fc7341a76420..43ff9fb17432 100644 --- a/internal/service/ecr/repository_policy.go +++ b/internal/service/ecr/repository_policy.go @@ -84,7 +84,7 @@ func resourceRepositoryPolicyRead(ctx context.Context, d *schema.ResourceData, m var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ECRClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + output, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*ecr.GetRepositoryPolicyOutput, error) { return findRepositoryPolicyByRepositoryName(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -98,8 +98,6 @@ func resourceRepositoryPolicyRead(ctx context.Context, d *schema.ResourceData, m return sdkdiag.AppendErrorf(diags, "reading ECR Repository Policy (%s): %s", d.Id(), err) } - output := outputRaw.(*ecr.GetRepositoryPolicyOutput) - policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get(names.AttrPolicy).(string), aws.ToString(output.PolicyText)) if err != nil { return sdkdiag.AppendFromErr(diags, err) diff --git a/internal/service/ecs/capacity_provider.go b/internal/service/ecs/capacity_provider.go index 4e31ea7b3836..dd7b0cce8635 100644 --- a/internal/service/ecs/capacity_provider.go +++ b/internal/service/ecs/capacity_provider.go @@ -386,7 +386,7 @@ func expandAutoScalingGroupProviderCreate(configured any) *awstypes.AutoScalingG return nil } - if configured.([]any) == nil || len(configured.([]any)) == 0 { + if len(configured.([]any)) == 0 { return nil } @@ -413,7 +413,7 @@ func expandAutoScalingGroupProviderUpdate(configured any) *awstypes.AutoScalingG return nil } - if configured.([]any) == nil || len(configured.([]any)) == 0 { + if len(configured.([]any)) == 0 { return nil } @@ -438,7 +438,7 @@ func expandManagedScaling(configured any) *awstypes.ManagedScaling { return nil } - if configured.([]any) == nil || len(configured.([]any)) == 0 { + if len(configured.([]any)) == 0 { return nil } diff --git a/internal/service/ecs/cluster.go b/internal/service/ecs/cluster.go index 7f3626e80a85..72078054aff2 100644 --- a/internal/service/ecs/cluster.go +++ b/internal/service/ecs/cluster.go @@ -230,7 +230,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta any) const ( timeout = 2 * time.Second ) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, timeout, func() (any, error) { + cluster, err := tfresource.RetryWhenNewResourceNotFound(ctx, timeout, func(ctx context.Context) (*awstypes.Cluster, error) { return findClusterByNameOrARN(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -244,7 +244,6 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta any) return sdkdiag.AppendErrorf(diags, "reading ECS Cluster (%s): %s", d.Id(), err) } - cluster := outputRaw.(*awstypes.Cluster) d.Set(names.AttrARN, cluster.ClusterArn) if cluster.Configuration != nil { if err := d.Set(names.AttrConfiguration, flattenClusterConfiguration(cluster.Configuration)); err != nil { diff --git a/internal/service/elbv2/const.go b/internal/service/elbv2/const.go index 6791aa1d04e2..56f7170035c5 100644 --- a/internal/service/elbv2/const.go +++ b/internal/service/elbv2/const.go @@ -201,7 +201,7 @@ const ( ) func healthCheckProtocolEnumValues() []string { - return enum.Slice[awstypes.ProtocolEnum]( + return enum.Slice( awstypes.ProtocolEnumHttp, awstypes.ProtocolEnumHttps, awstypes.ProtocolEnumTcp, diff --git a/internal/service/elbv2/listener_certificate.go b/internal/service/elbv2/listener_certificate.go index 1d7f019efe72..e93fb57c16cb 100644 --- a/internal/service/elbv2/listener_certificate.go +++ b/internal/service/elbv2/listener_certificate.go @@ -89,7 +89,7 @@ func resourceListenerCertificateRead(ctx context.Context, d *schema.ResourceData return sdkdiag.AppendFromErr(diags, err) } - _, err = tfresource.RetryWhenNewResourceNotFound(ctx, elbv2PropagationTimeout, func() (any, error) { + _, err = tfresource.RetryWhenNewResourceNotFound(ctx, elbv2PropagationTimeout, func(ctx context.Context) (any, error) { return findListenerCertificateByTwoPartKey(ctx, conn, listenerARN, certificateARN) }, d.IsNewResource()) diff --git a/internal/service/elbv2/listener_rule.go b/internal/service/elbv2/listener_rule.go index 1345348ba1ca..c5604c6c0079 100644 --- a/internal/service/elbv2/listener_rule.go +++ b/internal/service/elbv2/listener_rule.go @@ -544,7 +544,7 @@ func resourceListenerRuleRead(ctx context.Context, d *schema.ResourceData, meta var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBV2Client(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, elbv2PropagationTimeout, func() (any, error) { + rule, err := tfresource.RetryWhenNewResourceNotFound(ctx, elbv2PropagationTimeout, func(ctx context.Context) (*awstypes.Rule, error) { return findListenerRuleByARN(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -558,8 +558,6 @@ func resourceListenerRuleRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "reading ELBv2 Listener Rule (%s): %s", d.Id(), err) } - rule := outputRaw.(*awstypes.Rule) - d.Set(names.AttrARN, rule.RuleArn) // The listener arn isn't in the response but can be derived from the rule arn diff --git a/internal/service/iam/group_policy_attachment.go b/internal/service/iam/group_policy_attachment.go index 2f6df897192c..9a1b7f38ce6d 100644 --- a/internal/service/iam/group_policy_attachment.go +++ b/internal/service/iam/group_policy_attachment.go @@ -78,7 +78,7 @@ func resourceGroupPolicyAttachmentRead(ctx context.Context, d *schema.ResourceDa // Human friendly ID for error messages since d.Id() is non-descriptive. id := fmt.Sprintf("%s:%s", group, policyARN) - _, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + _, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (any, error) { return findAttachedGroupPolicyByTwoPartKey(ctx, conn, group, policyARN) }, d.IsNewResource()) diff --git a/internal/service/iam/policy.go b/internal/service/iam/policy.go index bf25102504fd..7843d5d6f43a 100644 --- a/internal/service/iam/policy.go +++ b/internal/service/iam/policy.go @@ -164,7 +164,7 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta any) d policy *awstypes.Policy policyVersion *awstypes.PolicyVersion } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + output, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*policyWithVersion, error) { iamPolicy := &policyWithVersion{} if v, err := findPolicyByARN(ctx, conn, d.Id()); err == nil { @@ -192,9 +192,7 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta any) d return sdkdiag.AppendErrorf(diags, "reading IAM Policy (%s): %s", d.Id(), err) } - output := outputRaw.(*policyWithVersion) policy := output.policy - d.Set(names.AttrARN, policy.Arn) d.Set("attachment_count", policy.AttachmentCount) d.Set(names.AttrDescription, policy.Description) diff --git a/internal/service/iam/role.go b/internal/service/iam/role.go index 8b78716f0ff2..32d2180b3af3 100644 --- a/internal/service/iam/role.go +++ b/internal/service/iam/role.go @@ -285,7 +285,7 @@ func resourceRoleRead(ctx context.Context, d *schema.ResourceData, meta any) dia var diags diag.Diagnostics conn := meta.(*conns.AWSClient).IAMClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + role, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.Role, error) { return findRoleByName(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -299,8 +299,6 @@ func resourceRoleRead(ctx context.Context, d *schema.ResourceData, meta any) dia return sdkdiag.AppendErrorf(diags, "reading IAM Role (%s): %s", d.Id(), err) } - role := outputRaw.(*awstypes.Role) - // occasionally, immediately after a role is created, AWS will give an ARN like AROAQ7SSZBKHREXAMPLE (unique ID) if role, err = waitRoleARNIsNotUniqueID(ctx, conn, d.Id(), role); err != nil { return sdkdiag.AppendErrorf(diags, "reading IAM Role (%s): waiting for valid ARN: %s", d.Id(), err) diff --git a/internal/service/iam/role_policy_attachment.go b/internal/service/iam/role_policy_attachment.go index aff7eaa109c4..4b946f5620da 100644 --- a/internal/service/iam/role_policy_attachment.go +++ b/internal/service/iam/role_policy_attachment.go @@ -76,7 +76,7 @@ func resourceRolePolicyAttachmentRead(ctx context.Context, d *schema.ResourceDat // Human friendly ID for error messages since d.Id() is non-descriptive. id := fmt.Sprintf("%s:%s", role, policyARN) - _, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + _, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (any, error) { return findAttachedRolePolicyByTwoPartKey(ctx, conn, role, policyARN) }, d.IsNewResource()) diff --git a/internal/service/iam/service_linked_role.go b/internal/service/iam/service_linked_role.go index dfb97a925cf4..162732845e7b 100644 --- a/internal/service/iam/service_linked_role.go +++ b/internal/service/iam/service_linked_role.go @@ -149,7 +149,7 @@ func resourceServiceLinkedRoleRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendFromErr(diags, err) } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + role, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.Role, error) { return findRoleByName(ctx, conn, roleName) }, d.IsNewResource()) @@ -163,8 +163,6 @@ func resourceServiceLinkedRoleRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "reading IAM Service Linked Role (%s): %s", d.Id(), err) } - role := outputRaw.(*awstypes.Role) - d.Set(names.AttrARN, role.Arn) d.Set("aws_service_name", serviceName) d.Set("create_date", aws.ToTime(role.CreateDate).Format(time.RFC3339)) diff --git a/internal/service/iam/service_specific_credential.go b/internal/service/iam/service_specific_credential.go index f80e3e43987b..18af7ca3832b 100644 --- a/internal/service/iam/service_specific_credential.go +++ b/internal/service/iam/service_specific_credential.go @@ -113,7 +113,7 @@ func resourceServiceSpecificCredentialRead(ctx context.Context, d *schema.Resour return sdkdiag.AppendErrorf(diags, "reading IAM Service Specific Credential (%s): %s", d.Id(), err) } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + cred, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.ServiceSpecificCredentialMetadata, error) { return FindServiceSpecificCredential(ctx, conn, serviceName, userName, credID) }, d.IsNewResource()) @@ -127,8 +127,6 @@ func resourceServiceSpecificCredentialRead(ctx context.Context, d *schema.Resour return sdkdiag.AppendErrorf(diags, "reading IAM Service Specific Credential (%s): %s", d.Id(), err) } - cred := outputRaw.(*awstypes.ServiceSpecificCredentialMetadata) - d.Set("service_specific_credential_id", cred.ServiceSpecificCredentialId) d.Set("service_user_name", cred.ServiceUserName) d.Set(names.AttrServiceName, cred.ServiceName) diff --git a/internal/service/iam/signing_certificate.go b/internal/service/iam/signing_certificate.go index 137b4e6f656f..afb6ad2eff60 100644 --- a/internal/service/iam/signing_certificate.go +++ b/internal/service/iam/signing_certificate.go @@ -103,7 +103,7 @@ func resourceSigningCertificateRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "reading IAM Signing Certificate (%s): %s", d.Id(), err) } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + output, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.SigningCertificate, error) { return FindSigningCertificate(ctx, conn, userName, certId) }, d.IsNewResource()) @@ -117,12 +117,10 @@ func resourceSigningCertificateRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "reading IAM Signing Certificate (%s): %s", d.Id(), err) } - resp := outputRaw.(*awstypes.SigningCertificate) - - d.Set("certificate_body", resp.CertificateBody) - d.Set("certificate_id", resp.CertificateId) - d.Set(names.AttrUserName, resp.UserName) - d.Set(names.AttrStatus, resp.Status) + d.Set("certificate_body", output.CertificateBody) + d.Set("certificate_id", output.CertificateId) + d.Set(names.AttrUserName, output.UserName) + d.Set(names.AttrStatus, output.Status) return diags } diff --git a/internal/service/iam/user.go b/internal/service/iam/user.go index 80cd07adc647..5347db8c3119 100644 --- a/internal/service/iam/user.go +++ b/internal/service/iam/user.go @@ -140,7 +140,7 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta any) dia var diags diag.Diagnostics conn := meta.(*conns.AWSClient).IAMClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + user, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.User, error) { return findUserByName(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -154,8 +154,6 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta any) dia return sdkdiag.AppendErrorf(diags, "reading IAM User (%s): %s", d.Id(), err) } - user := outputRaw.(*awstypes.User) - d.Set(names.AttrARN, user.Arn) d.Set(names.AttrName, user.UserName) d.Set(names.AttrPath, user.Path) diff --git a/internal/service/iam/user_policy_attachment.go b/internal/service/iam/user_policy_attachment.go index 864436cd00b3..cbd3d02e3e8f 100644 --- a/internal/service/iam/user_policy_attachment.go +++ b/internal/service/iam/user_policy_attachment.go @@ -77,7 +77,7 @@ func resourceUserPolicyAttachmentRead(ctx context.Context, d *schema.ResourceDat // Human friendly ID for error messages since d.Id() is non-descriptive. id := fmt.Sprintf("%s:%s", user, policyARN) - _, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + _, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (any, error) { return findAttachedUserPolicyByTwoPartKey(ctx, conn, user, policyARN) }, d.IsNewResource()) diff --git a/internal/service/iam/user_test.go b/internal/service/iam/user_test.go index 7321194164c5..ff3b106c8062 100644 --- a/internal/service/iam/user_test.go +++ b/internal/service/iam/user_test.go @@ -757,7 +757,7 @@ func testAccCheckUserAttachPolicy(ctx context.Context, user *awstypes.User) reso return fmt.Errorf("externally creating IAM Policy (%s): %s", aws.ToString(user.UserName), err) } - _, err = tfresource.RetryWhenNewResourceNotFound(ctx, 2*time.Minute, func() (any, error) { + _, err = tfresource.RetryWhenNewResourceNotFound(ctx, 2*time.Minute, func(ctx context.Context) (any, error) { return tfiam.FindPolicyByARN(ctx, conn, aws.ToString(output.Policy.Arn)) }, true) if err != nil { diff --git a/internal/service/kms/alias.go b/internal/service/kms/alias.go index 8893f2e35ca3..84f9e6ada5ed 100644 --- a/internal/service/kms/alias.go +++ b/internal/service/kms/alias.go @@ -98,7 +98,7 @@ func resourceAliasRead(ctx context.Context, d *schema.ResourceData, meta any) di var diags diag.Diagnostics conn := meta.(*conns.AWSClient).KMSClient(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + alias, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*awstypes.AliasListEntry, error) { return findAliasByName(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -112,7 +112,6 @@ func resourceAliasRead(ctx context.Context, d *schema.ResourceData, meta any) di return sdkdiag.AppendErrorf(diags, "reading KMS Alias (%s): %s", d.Id(), err) } - alias := outputRaw.(*awstypes.AliasListEntry) aliasARN := aws.ToString(alias.AliasArn) targetKeyID := aws.ToString(alias.TargetKeyId) targetKeyARN, err := aliasARNToKeyARN(aliasARN, targetKeyID) diff --git a/internal/service/kms/key.go b/internal/service/kms/key.go index 68359263db3c..d1dc6f071e3d 100644 --- a/internal/service/kms/key.go +++ b/internal/service/kms/key.go @@ -350,7 +350,7 @@ type kmsKeyInfo struct { func findKeyInfo(ctx context.Context, conn *kms.Client, keyID string, isNewResource bool) (*kmsKeyInfo, error) { // Wait for propagation since KMS is eventually consistent. - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (any, error) { + return tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func(ctx context.Context) (*kmsKeyInfo, error) { var err error var key kmsKeyInfo @@ -394,12 +394,6 @@ func findKeyInfo(ctx context.Context, conn *kms.Client, keyID string, isNewResou return &key, nil }, isNewResource) - - if err != nil { - return nil, err - } - - return outputRaw.(*kmsKeyInfo), nil } func findKeyByID(ctx context.Context, conn *kms.Client, keyID string, optFns ...func(*kms.Options)) (*awstypes.KeyMetadata, error) { diff --git a/internal/service/lambda/exports_test.go b/internal/service/lambda/exports_test.go index 032ffff61fca..4b6488686d57 100644 --- a/internal/service/lambda/exports_test.go +++ b/internal/service/lambda/exports_test.go @@ -42,3 +42,8 @@ var ( ValidQualifier = validQualifier ValidPolicyStatementID = validPolicyStatementID ) + +type ( + Policy = policy + PolicyStatement = policyStatement +) diff --git a/internal/service/lambda/permission.go b/internal/service/lambda/permission.go index 670800df497a..59aa52c3c7eb 100644 --- a/internal/service/lambda/permission.go +++ b/internal/service/lambda/permission.go @@ -177,7 +177,7 @@ func resourcePermissionRead(ctx context.Context, d *schema.ResourceData, meta an conn := meta.(*conns.AWSClient).LambdaClient(ctx) functionName := d.Get("function_name").(string) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, lambdaPropagationTimeout, func() (any, error) { + statement, err := tfresource.RetryWhenNewResourceNotFound(ctx, lambdaPropagationTimeout, func(ctx context.Context) (*policyStatement, error) { return findPolicyStatementByTwoPartKey(ctx, conn, functionName, d.Id(), d.Get("qualifier").(string)) }, d.IsNewResource()) @@ -191,9 +191,7 @@ func resourcePermissionRead(ctx context.Context, d *schema.ResourceData, meta an return sdkdiag.AppendErrorf(diags, "reading Lambda Permission (%s/%s): %s", functionName, d.Id(), err) } - statement := outputRaw.(*PolicyStatement) qualifier, _ := getQualifierFromAliasOrVersionARN(statement.Resource) - d.Set("qualifier", qualifier) // Save Lambda function name in the same format @@ -339,7 +337,7 @@ func findPolicy(ctx context.Context, conn *lambda.Client, input *lambda.GetPolic return output, nil } -func findPolicyStatementByTwoPartKey(ctx context.Context, conn *lambda.Client, functionName, statementID, qualifier string) (*PolicyStatement, error) { +func findPolicyStatementByTwoPartKey(ctx context.Context, conn *lambda.Client, functionName, statementID, qualifier string) (*policyStatement, error) { input := &lambda.GetPolicyInput{ FunctionName: aws.String(functionName), } @@ -353,7 +351,7 @@ func findPolicyStatementByTwoPartKey(ctx context.Context, conn *lambda.Client, f return nil, err } - policy := &Policy{} + policy := &policy{} err = json.Unmarshal([]byte(aws.ToString(output.Policy)), policy) if err != nil { @@ -390,13 +388,13 @@ func getFunctionNameFromARN(arn string) (string, error) { return matches[5], nil } -type Policy struct { +type policy struct { Version string - Statement []PolicyStatement + Statement []policyStatement Id string } -type PolicyStatement struct { +type policyStatement struct { Condition map[string]map[string]string Action string Resource string diff --git a/internal/service/sns/topic_subscription.go b/internal/service/sns/topic_subscription.go index d0fcaa812120..6734506c5a0c 100644 --- a/internal/service/sns/topic_subscription.go +++ b/internal/service/sns/topic_subscription.go @@ -252,7 +252,7 @@ func resourceTopicSubscriptionRead(ctx context.Context, d *schema.ResourceData, } } - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, subscriptionCreateTimeout, func() (any, error) { + attributes, err := tfresource.RetryWhenNewResourceNotFound(ctx, subscriptionCreateTimeout, func(ctx context.Context) (map[string]string, error) { return findSubscriptionAttributesByARN(ctx, conn, d.Id()) }, d.IsNewResource()) @@ -266,8 +266,6 @@ func resourceTopicSubscriptionRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "reading SNS Topic Subscription (%s): %s", d.Id(), err) } - attributes := outputRaw.(map[string]string) - return sdkdiag.AppendFromErr(diags, subscriptionAttributeMap.APIAttributesToResourceData(attributes, d)) } diff --git a/internal/tfresource/retry.go b/internal/tfresource/retry.go index 759dd47fa098..60b876e9fbb8 100644 --- a/internal/tfresource/retry.go +++ b/internal/tfresource/retry.go @@ -226,14 +226,14 @@ func RetryWhenNotFound[T any](ctx context.Context, timeout time.Duration, f func } // RetryWhenNewResourceNotFound retries the specified function when it returns a retry.NotFoundError and `isNewResource` is true. -func RetryWhenNewResourceNotFound(ctx context.Context, timeout time.Duration, f func() (any, error), isNewResource bool) (any, error) { - return RetryWhen(ctx, timeout, f, func(err error) (bool, error) { +func RetryWhenNewResourceNotFound[T any](ctx context.Context, timeout time.Duration, f func(context.Context) (T, error), isNewResource bool) (T, error) { + return retry.Op(f).If(func(_ T, err error) (bool, error) { if isNewResource && NotFound(err) { return true, err } return false, err - }) + })(ctx, timeout) } type Options struct { diff --git a/internal/tfresource/retry_test.go b/internal/tfresource/retry_test.go index 6a9196c5a746..4c0dcbfc3714 100644 --- a/internal/tfresource/retry_test.go +++ b/internal/tfresource/retry_test.go @@ -99,33 +99,33 @@ func TestRetryWhenNewResourceNotFound(t *testing.T) { var retryCount int32 testCases := []struct { Name string - F func() (any, error) + F func(context.Context) (any, error) NewResource bool ExpectError bool }{ { Name: "no error", - F: func() (any, error) { + F: func(context.Context) (any, error) { return nil, nil }, }, { Name: "no error new resource", - F: func() (any, error) { + F: func(context.Context) (any, error) { return nil, nil }, NewResource: true, }, { Name: "non-retryable other error", - F: func() (any, error) { + F: func(context.Context) (any, error) { return nil, errors.New("TestCode") }, ExpectError: true, }, { Name: "non-retryable other error new resource", - F: func() (any, error) { + F: func(context.Context) (any, error) { return nil, errors.New("TestCode") }, NewResource: true, @@ -133,14 +133,14 @@ func TestRetryWhenNewResourceNotFound(t *testing.T) { }, { Name: "retryable NotFoundError not new resource", - F: func() (any, error) { + F: func(context.Context) (any, error) { return nil, &retry.NotFoundError{} }, ExpectError: true, }, { Name: "retryable NotFoundError new resource timeout", - F: func() (any, error) { + F: func(context.Context) (any, error) { return nil, &retry.NotFoundError{} }, NewResource: true, @@ -148,7 +148,7 @@ func TestRetryWhenNewResourceNotFound(t *testing.T) { }, { Name: "retryable NotFoundError success new resource", - F: func() (any, error) { + F: func(context.Context) (any, error) { if atomic.CompareAndSwapInt32(&retryCount, 0, 1) { return nil, &retry.NotFoundError{} }