From f76d564c8673a2b69687aa51249161acd9fdb181 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Wed, 26 Jun 2024 19:12:51 +0100 Subject: [PATCH 01/37] elb: Migrate to AWS SDK v2 --- go.mod | 1 + go.sum | 2 ++ internal/conns/awsclient_gen.go | 6 +++--- names/data/names_data.hcl | 2 +- names/names.go | 1 + 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index d4eb12968a1..cf3d79d1b98 100644 --- a/go.mod +++ b/go.mod @@ -93,6 +93,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/eks v1.45.1 github.com/aws/aws-sdk-go-v2/service/elasticache v1.40.1 github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.25.1 + github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.1 github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.1 github.com/aws/aws-sdk-go-v2/service/emr v1.42.0 github.com/aws/aws-sdk-go-v2/service/emrserverless v1.23.1 diff --git a/go.sum b/go.sum index 2090b454c23..b1c72f24c66 100644 --- a/go.sum +++ b/go.sum @@ -206,6 +206,8 @@ github.com/aws/aws-sdk-go-v2/service/elasticache v1.40.1 h1:yJMmaQ3jTpCrsXl0lxQU github.com/aws/aws-sdk-go-v2/service/elasticache v1.40.1/go.mod h1:HfavnpYheVa3TXRxHNZYIM/BMI8hmSbtiSbYxqdri/4= github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.25.1 h1:T1lEDcxMSuHOIeY6CrmTCpRa1lOy9GMi03OZCa9H31g= github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.25.1/go.mod h1:H8YbT18eu4O03RiBqdDderRdpnHe2Pv439zdO5mmbfU= +github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.1 h1:/x4d5NeeoKJAhyZ5zHnBOaxOSotobVb9mXeprdl363I= +github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.1/go.mod h1:Dm9KFhagyV3Ecne6tpYIXWh51N/Q288vpm+0u3P/gbo= github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.1 h1:XuwjSEGfLxo6UJtpJVy/E80GpE1gNclDBv5k1nTQcCs= github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.1/go.mod h1:74D8OQ00uEvvpuG5e4VX+/2v3MC2pltRtzNyXJnEjrI= github.com/aws/aws-sdk-go-v2/service/emr v1.42.0 h1:n3e3/X7ixZrQja0ot3l6M19nw8EarUo1yR0rH4e8aec= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 5daf03f5003..c9dee9c5961 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -85,6 +85,7 @@ import ( eks_sdkv2 "github.com/aws/aws-sdk-go-v2/service/eks" elasticache_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticache" elasticbeanstalk_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk" + elasticloadbalancing_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" elasticloadbalancingv2_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" emr_sdkv2 "github.com/aws/aws-sdk-go-v2/service/emr" emrserverless_sdkv2 "github.com/aws/aws-sdk-go-v2/service/emrserverless" @@ -207,7 +208,6 @@ import ( elasticache_sdkv1 "github.com/aws/aws-sdk-go/service/elasticache" elasticsearchservice_sdkv1 "github.com/aws/aws-sdk-go/service/elasticsearchservice" elastictranscoder_sdkv1 "github.com/aws/aws-sdk-go/service/elastictranscoder" - elb_sdkv1 "github.com/aws/aws-sdk-go/service/elb" elbv2_sdkv1 "github.com/aws/aws-sdk-go/service/elbv2" emr_sdkv1 "github.com/aws/aws-sdk-go/service/emr" emrcontainers_sdkv1 "github.com/aws/aws-sdk-go/service/emrcontainers" @@ -621,8 +621,8 @@ func (c *AWSClient) EKSClient(ctx context.Context) *eks_sdkv2.Client { return errs.Must(client[*eks_sdkv2.Client](ctx, c, names.EKS, make(map[string]any))) } -func (c *AWSClient) ELBConn(ctx context.Context) *elb_sdkv1.ELB { - return errs.Must(conn[*elb_sdkv1.ELB](ctx, c, names.ELB, make(map[string]any))) +func (c *AWSClient) ELBClient(ctx context.Context) *elasticloadbalancing_sdkv2.Client { + return errs.Must(client[*elasticloadbalancing_sdkv2.Client](ctx, c, names.ELB, make(map[string]any))) } func (c *AWSClient) ELBV2Conn(ctx context.Context) *elbv2_sdkv1.ELBV2 { diff --git a/names/data/names_data.hcl b/names/data/names_data.hcl index 190618005d9..a20216d5eaa 100644 --- a/names/data/names_data.hcl +++ b/names/data/names_data.hcl @@ -3535,7 +3535,7 @@ service "elb" { sdk { id = "Elastic Load Balancing" - client_version = [1] + client_version = [2] } names { diff --git a/names/names.go b/names/names.go index c89fe9aa207..3ba89daffb7 100644 --- a/names/names.go +++ b/names/names.go @@ -66,6 +66,7 @@ const ( DeviceFarmEndpointID = "devicefarm" ECREndpointID = "api.ecr" EKSEndpointID = "eks" + ELBEndpointID = "elasticloadbalancing" EMREndpointID = "elasticmapreduce" EventsEndpointID = "events" EvidentlyEndpointID = "evidently" From 50d9574d0cb310dfbb928c1ae05c374247fbaef3 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:16:26 +0100 Subject: [PATCH 02/37] make gen --- internal/service/elb/generate.go | 2 +- .../elb/service_endpoint_resolver_gen.go | 66 ++++++++++--------- .../service/elb/service_endpoints_gen_test.go | 4 +- internal/service/elb/service_package_gen.go | 28 +++----- internal/service/elb/tags_gen.go | 54 +++++++-------- 5 files changed, 75 insertions(+), 79 deletions(-) diff --git a/internal/service/elb/generate.go b/internal/service/elb/generate.go index 00321adf62d..6cc54c3c562 100644 --- a/internal/service/elb/generate.go +++ b/internal/service/elb/generate.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=DescribeTags -ListTagsInIDElem=LoadBalancerNames -ListTagsInIDNeedSlice=yes -ListTagsOutTagsElem=TagDescriptions[0].Tags -ServiceTagsSlice -TagOp=AddTags -TagInIDElem=LoadBalancerNames -TagInIDNeedSlice=yes -TagKeyType=TagKeyOnly -UntagOp=RemoveTags -UntagInNeedTagKeyType=yes -UntagInTagsElem=Tags -UpdateTags +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsOp=DescribeTags -ListTagsInIDElem=LoadBalancerNames -ListTagsInIDNeedValueSlice=yes -ListTagsOutTagsElem=TagDescriptions[0].Tags -ServiceTagsSlice -TagOp=AddTags -TagInIDElem=LoadBalancerNames -TagInIDNeedValueSlice=yes -TagKeyType=TagKeyOnly -UntagOp=RemoveTags -UntagInNeedTagKeyType=yes -UntagInTagsElem=Tags -UpdateTags //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/elb/service_endpoint_resolver_gen.go b/internal/service/elb/service_endpoint_resolver_gen.go index 43ac900d381..941c5efd895 100644 --- a/internal/service/elb/service_endpoint_resolver_gen.go +++ b/internal/service/elb/service_endpoint_resolver_gen.go @@ -6,65 +6,63 @@ import ( "context" "fmt" "net" - "net/url" - endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + elasticloadbalancing_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/errs" ) -var _ endpoints_sdkv1.Resolver = resolverSDKv1{} +var _ elasticloadbalancing_sdkv2.EndpointResolverV2 = resolverSDKv2{} -type resolverSDKv1 struct { - ctx context.Context +type resolverSDKv2 struct { + defaultResolver elasticloadbalancing_sdkv2.EndpointResolverV2 } -func newEndpointResolverSDKv1(ctx context.Context) resolverSDKv1 { - return resolverSDKv1{ - ctx: ctx, +func newEndpointResolverSDKv2() resolverSDKv2 { + return resolverSDKv2{ + defaultResolver: elasticloadbalancing_sdkv2.NewDefaultEndpointResolverV2(), } } -func (r resolverSDKv1) EndpointFor(service, region string, opts ...func(*endpoints_sdkv1.Options)) (endpoint endpoints_sdkv1.ResolvedEndpoint, err error) { - ctx := r.ctx +func (r resolverSDKv2) ResolveEndpoint(ctx context.Context, params elasticloadbalancing_sdkv2.EndpointParameters) (endpoint smithyendpoints.Endpoint, err error) { + params = params.WithDefaults() + useFIPS := aws_sdkv2.ToBool(params.UseFIPS) - var opt endpoints_sdkv1.Options - opt.Set(opts...) - - useFIPS := opt.UseFIPSEndpoint == endpoints_sdkv1.FIPSEndpointStateEnabled + if eps := params.Endpoint; aws_sdkv2.ToString(eps) != "" { + tflog.Debug(ctx, "setting endpoint", map[string]any{ + "tf_aws.endpoint": endpoint, + }) - defaultResolver := endpoints_sdkv1.DefaultResolver() + if useFIPS { + tflog.Debug(ctx, "endpoint set, ignoring UseFIPSEndpoint setting") + params.UseFIPS = aws_sdkv2.Bool(false) + } - if useFIPS { + return r.defaultResolver.ResolveEndpoint(ctx, params) + } else if useFIPS { ctx = tflog.SetField(ctx, "tf_aws.use_fips", useFIPS) - endpoint, err = defaultResolver.EndpointFor(service, region, opts...) + endpoint, err = r.defaultResolver.ResolveEndpoint(ctx, params) if err != nil { return endpoint, err } tflog.Debug(ctx, "endpoint resolved", map[string]any{ - "tf_aws.endpoint": endpoint.URL, + "tf_aws.endpoint": endpoint.URI.String(), }) - var endpointURL *url.URL - endpointURL, err = url.Parse(endpoint.URL) - if err != nil { - return endpoint, err - } - - hostname := endpointURL.Hostname() + hostname := endpoint.URI.Hostname() _, err = net.LookupHost(hostname) if err != nil { if dnsErr, ok := errs.As[*net.DNSError](err); ok && dnsErr.IsNotFound { tflog.Debug(ctx, "default endpoint host not found, disabling FIPS", map[string]any{ "tf_aws.hostname": hostname, }) - opts = append(opts, func(o *endpoints_sdkv1.Options) { - o.UseFIPSEndpoint = endpoints_sdkv1.FIPSEndpointStateDisabled - }) + params.UseFIPS = aws_sdkv2.Bool(false) } else { - err = fmt.Errorf("looking up accessanalyzer endpoint %q: %s", hostname, err) + err = fmt.Errorf("looking up elasticloadbalancing endpoint %q: %s", hostname, err) return } } else { @@ -72,5 +70,13 @@ func (r resolverSDKv1) EndpointFor(service, region string, opts ...func(*endpoin } } - return defaultResolver.EndpointFor(service, region, opts...) + return r.defaultResolver.ResolveEndpoint(ctx, params) +} + +func withBaseEndpoint(endpoint string) func(*elasticloadbalancing_sdkv2.Options) { + return func(o *elasticloadbalancing_sdkv2.Options) { + if endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + } } diff --git a/internal/service/elb/service_endpoints_gen_test.go b/internal/service/elb/service_endpoints_gen_test.go index 20485ecf20a..fc56c8107a0 100644 --- a/internal/service/elb/service_endpoints_gen_test.go +++ b/internal/service/elb/service_endpoints_gen_test.go @@ -13,9 +13,9 @@ import ( "strings" "testing" + elb_sdkv1 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" aws_sdkv1 "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/endpoints" - elb_sdkv1 "github.com/aws/aws-sdk-go/service/elb" "github.com/google/go-cmp/cmp" "github.com/hashicorp/aws-sdk-go-base/v2/servicemocks" "github.com/hashicorp/go-cty/cty" @@ -332,7 +332,7 @@ func defaultFIPSEndpoint(region string) (url.URL, error) { func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) apiCallParams { t.Helper() - client := meta.ELBConn(ctx) + client := meta.ELBClient(ctx) req, _ := client.DescribeLoadBalancersRequest(&elb_sdkv1.DescribeLoadBalancersInput{}) diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index 0979859a4db..edc828068cc 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -5,10 +5,8 @@ package elb import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - elb_sdkv1 "github.com/aws/aws-sdk-go/service/elb" - "github.com/hashicorp/terraform-plugin-log/tflog" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + elasticloadbalancing_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -90,22 +88,14 @@ func (p *servicePackage) ServicePackageName() string { return names.ELB } -// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*elb_sdkv1.ELB, error) { - sess := config[names.AttrSession].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*elasticloadbalancing_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - cfg := aws_sdkv1.Config{} - - if endpoint := config[names.AttrEndpoint].(string); endpoint != "" { - tflog.Debug(ctx, "setting endpoint", map[string]any{ - "tf_aws.endpoint": endpoint, - }) - cfg.Endpoint = aws_sdkv1.String(endpoint) - } else { - cfg.EndpointResolver = newEndpointResolverSDKv1(ctx) - } - - return elb_sdkv1.New(sess.Copy(&cfg)), nil + return elasticloadbalancing_sdkv2.NewFromConfig(cfg, + elasticloadbalancing_sdkv2.WithEndpointResolverV2(newEndpointResolverSDKv2()), + withBaseEndpoint(config[names.AttrEndpoint].(string)), + ), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/elb/tags_gen.go b/internal/service/elb/tags_gen.go index 57d0b4e9a54..260377d5d90 100644 --- a/internal/service/elb/tags_gen.go +++ b/internal/service/elb/tags_gen.go @@ -5,9 +5,9 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" - "github.com/aws/aws-sdk-go/service/elb/elbiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" @@ -19,12 +19,12 @@ import ( // listTags lists elb service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func listTags(ctx context.Context, conn elbiface.ELBAPI, identifier string) (tftags.KeyValueTags, error) { - input := &elb.DescribeTagsInput{ - LoadBalancerNames: aws.StringSlice([]string{identifier}), +func listTags(ctx context.Context, conn *elasticloadbalancing.Client, identifier string, optFns ...func(*elasticloadbalancing.Options)) (tftags.KeyValueTags, error) { + input := &elasticloadbalancing.DescribeTagsInput{ + LoadBalancerNames: []string{identifier}, } - output, err := conn.DescribeTagsWithContext(ctx, input) + output, err := conn.DescribeTags(ctx, input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -36,7 +36,7 @@ func listTags(ctx context.Context, conn elbiface.ELBAPI, identifier string) (tft // ListTags lists elb service tags and set them in Context. // It is called from outside this package. func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier string) error { - tags, err := listTags(ctx, meta.(*conns.AWSClient).ELBConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).ELBClient(ctx), identifier) if err != nil { return err @@ -52,11 +52,11 @@ func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier stri // []*SERVICE.Tag handling // TagKeys returns elb service tag keys. -func TagKeys(tags tftags.KeyValueTags) []*elb.TagKeyOnly { - result := make([]*elb.TagKeyOnly, 0, len(tags)) +func TagKeys(tags tftags.KeyValueTags) []*elasticloadbalancing.TagKeyOnly { + result := make([]*elasticloadbalancing.TagKeyOnly, 0, len(tags)) for k := range tags.Map() { - tagKey := &elb.TagKeyOnly{ + tagKey := &elasticloadbalancing.TagKeyOnly{ Key: aws.String(k), } @@ -67,11 +67,11 @@ func TagKeys(tags tftags.KeyValueTags) []*elb.TagKeyOnly { } // Tags returns elb service tags. -func Tags(tags tftags.KeyValueTags) []*elb.Tag { - result := make([]*elb.Tag, 0, len(tags)) +func Tags(tags tftags.KeyValueTags) []awstypes.Tag { + result := make([]awstypes.Tag, 0, len(tags)) for k, v := range tags.Map() { - tag := &elb.Tag{ + tag := awstypes.Tag{ Key: aws.String(k), Value: aws.String(v), } @@ -82,12 +82,12 @@ func Tags(tags tftags.KeyValueTags) []*elb.Tag { return result } -// KeyValueTags creates tftags.KeyValueTags from elb service tags. -func KeyValueTags(ctx context.Context, tags []*elb.Tag) tftags.KeyValueTags { +// KeyValueTags creates tftags.KeyValueTags from elasticloadbalancing service tags. +func KeyValueTags(ctx context.Context, tags []awstypes.Tag) tftags.KeyValueTags { m := make(map[string]*string, len(tags)) for _, tag := range tags { - m[aws.StringValue(tag.Key)] = tag.Value + m[aws.ToString(tag.Key)] = tag.Value } return tftags.New(ctx, m) @@ -95,7 +95,7 @@ func KeyValueTags(ctx context.Context, tags []*elb.Tag) tftags.KeyValueTags { // getTagsIn returns elb service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) []*elb.Tag { +func getTagsIn(ctx context.Context) []awstypes.Tag { if inContext, ok := tftags.FromContext(ctx); ok { if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { return tags @@ -106,7 +106,7 @@ func getTagsIn(ctx context.Context) []*elb.Tag { } // setTagsOut sets elb service tags in Context. -func setTagsOut(ctx context.Context, tags []*elb.Tag) { +func setTagsOut(ctx context.Context, tags []awstypes.Tag) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } @@ -115,7 +115,7 @@ func setTagsOut(ctx context.Context, tags []*elb.Tag) { // updateTags updates elb service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func updateTags(ctx context.Context, conn elbiface.ELBAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *elasticloadbalancing.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*elasticloadbalancing.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -124,12 +124,12 @@ func updateTags(ctx context.Context, conn elbiface.ELBAPI, identifier string, ol removedTags := oldTags.Removed(newTags) removedTags = removedTags.IgnoreSystem(names.ELB) if len(removedTags) > 0 { - input := &elb.RemoveTagsInput{ - LoadBalancerNames: aws.StringSlice([]string{identifier}), + input := &elasticloadbalancing.RemoveTagsInput{ + LoadBalancerNames: []string{identifier}, Tags: TagKeys(removedTags), } - _, err := conn.RemoveTagsWithContext(ctx, input) + _, err := conn.RemoveTags(ctx, input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -139,12 +139,12 @@ func updateTags(ctx context.Context, conn elbiface.ELBAPI, identifier string, ol updatedTags := oldTags.Updated(newTags) updatedTags = updatedTags.IgnoreSystem(names.ELB) if len(updatedTags) > 0 { - input := &elb.AddTagsInput{ - LoadBalancerNames: aws.StringSlice([]string{identifier}), + input := &elasticloadbalancing.AddTagsInput{ + LoadBalancerNames: []string{identifier}, Tags: Tags(updatedTags), } - _, err := conn.AddTagsWithContext(ctx, input) + _, err := conn.AddTags(ctx, input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -157,5 +157,5 @@ func updateTags(ctx context.Context, conn elbiface.ELBAPI, identifier string, ol // UpdateTags updates elb service tags. // It is called from outside this package. func (p *servicePackage) UpdateTags(ctx context.Context, meta any, identifier string, oldTags, newTags any) error { - return updateTags(ctx, meta.(*conns.AWSClient).ELBConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).ELBClient(ctx), identifier, oldTags, newTags) } From eade42aa37d45a9a8297600349b19e36f40f09a9 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:18:46 +0100 Subject: [PATCH 03/37] r/app_cookie_stickiness_policy: Migrate to AWS SDK v2 --- .../elb/app_cookie_stickiness_policy.go | 65 +++++++++---------- .../elb/app_cookie_stickiness_policy_test.go | 4 +- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/internal/service/elb/app_cookie_stickiness_policy.go b/internal/service/elb/app_cookie_stickiness_policy.go index 774a0b21566..e13cc3e55f0 100644 --- a/internal/service/elb/app_cookie_stickiness_policy.go +++ b/internal/service/elb/app_cookie_stickiness_policy.go @@ -11,13 +11,14 @@ import ( "strings" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -69,32 +70,32 @@ func ResourceAppCookieStickinessPolicy() *schema.Resource { func resourceAppCookieStickinessPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName := d.Get("load_balancer").(string) lbPort := d.Get("lb_port").(int) policyName := d.Get(names.AttrName).(string) id := AppCookieStickinessPolicyCreateResourceID(lbName, lbPort, policyName) { - input := &elb.CreateAppCookieStickinessPolicyInput{ + input := &elasticloadbalancing.CreateAppCookieStickinessPolicyInput{ CookieName: aws.String(d.Get("cookie_name").(string)), LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), } - if _, err := conn.CreateAppCookieStickinessPolicyWithContext(ctx, input); err != nil { + if _, err := conn.CreateAppCookieStickinessPolicy(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "creating ELB Classic App Cookie Stickiness Policy (%s): %s", id, err) } } { - input := &elb.SetLoadBalancerPoliciesOfListenerInput{ + input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), - LoadBalancerPort: aws.Int64(int64(lbPort)), - PolicyNames: aws.StringSlice([]string{policyName}), + LoadBalancerPort: int32(lbPort), + PolicyNames: []string{policyName}, } - if _, err := conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, input); err != nil { + if _, err := conn.SetLoadBalancerPoliciesOfListener(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic App Cookie Stickiness Policy (%s): %s", id, err) } } @@ -106,7 +107,7 @@ func resourceAppCookieStickinessPolicyCreate(ctx context.Context, d *schema.Reso func resourceAppCookieStickinessPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, lbPort, policyName, err := AppCookieStickinessPolicyParseResourceID(d.Id()) @@ -126,7 +127,7 @@ func resourceAppCookieStickinessPolicyRead(ctx context.Context, d *schema.Resour return sdkdiag.AppendErrorf(diags, "reading ELB Classic App Cookie Stickiness Policy (%s): %s", d.Id(), err) } - if len(policy.PolicyAttributeDescriptions) != 1 || aws.StringValue(policy.PolicyAttributeDescriptions[0].AttributeName) != "CookieName" { + if len(policy.PolicyAttributeDescriptions) != 1 || aws.ToString(policy.PolicyAttributeDescriptions[0].AttributeName) != "CookieName" { return sdkdiag.AppendErrorf(diags, "cookie not found") } cookieAttr := policy.PolicyAttributeDescriptions[0] @@ -140,7 +141,7 @@ func resourceAppCookieStickinessPolicyRead(ctx context.Context, d *schema.Resour func resourceAppCookieStickinessPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, lbPort, policyName, err := AppCookieStickinessPolicyParseResourceID(d.Id()) @@ -151,20 +152,20 @@ func resourceAppCookieStickinessPolicyDelete(ctx context.Context, d *schema.Reso // Perversely, if we Set an empty list of PolicyNames, we detach the // policies attached to a listener, which is required to delete the // policy itself. - input := &elb.SetLoadBalancerPoliciesOfListenerInput{ + input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), - LoadBalancerPort: aws.Int64(int64(lbPort)), - PolicyNames: aws.StringSlice([]string{}), + LoadBalancerPort: int32(lbPort), + PolicyNames: []string{}, } - _, err = conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, input) + _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic App Cookie Stickiness Policy (%s): %s", d.Id(), err) } log.Printf("[DEBUG] Deleting ELB Classic App Cookie Stickiness Policy: %s", d.Id()) - _, err = conn.DeleteLoadBalancerPolicyWithContext(ctx, &elb.DeleteLoadBalancerPolicyInput{ + _, err = conn.DeleteLoadBalancerPolicy(ctx, &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), }) @@ -176,15 +177,15 @@ func resourceAppCookieStickinessPolicyDelete(ctx context.Context, d *schema.Reso return diags } -func FindLoadBalancerPolicyByTwoPartKey(ctx context.Context, conn *elb.ELB, lbName, policyName string) (*elb.PolicyDescription, error) { - input := &elb.DescribeLoadBalancerPoliciesInput{ +func FindLoadBalancerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName, policyName string) (*awstypes.PolicyDescription, error) { + input := &elasticloadbalancing.DescribeLoadBalancerPoliciesInput{ LoadBalancerName: aws.String(lbName), - PolicyNames: aws.StringSlice([]string{policyName}), + PolicyNames: []string{policyName}, } - output, err := conn.DescribeLoadBalancerPoliciesWithContext(ctx, input) + output, err := conn.DescribeLoadBalancerPolicies(ctx, input) - if tfawserr.ErrCodeEquals(err, elb.ErrCodePolicyNotFoundException, elb.ErrCodeAccessPointNotFoundException) { + if errs.IsA[*awstypes.PolicyNotFoundException](err) || errs.IsA[*awstypes.AccessPointNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -195,18 +196,10 @@ func FindLoadBalancerPolicyByTwoPartKey(ctx context.Context, conn *elb.ELB, lbNa return nil, err } - if output == nil || len(output.PolicyDescriptions) == 0 || output.PolicyDescriptions[0] == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - if count := len(output.PolicyDescriptions); count > 1 { - return nil, tfresource.NewTooManyResultsError(count, input) - } - - return output.PolicyDescriptions[0], nil + return tfresource.AssertSingleValueResult(output.PolicyDescriptions) } -func FindLoadBalancerListenerPolicyByThreePartKey(ctx context.Context, conn *elb.ELB, lbName string, lbPort int, policyName string) (*elb.PolicyDescription, error) { +func FindLoadBalancerListenerPolicyByThreePartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, lbPort int, policyName string) (*awstypes.PolicyDescription, error) { policy, err := FindLoadBalancerPolicyByTwoPartKey(ctx, conn, lbName, policyName) if err != nil { @@ -220,16 +213,16 @@ func FindLoadBalancerListenerPolicyByThreePartKey(ctx context.Context, conn *elb } for _, v := range lb.ListenerDescriptions { - if v == nil || v.Listener == nil { + if v.Listener == nil { continue } - if aws.Int64Value(v.Listener.LoadBalancerPort) != int64(lbPort) { + if v.Listener.LoadBalancerPort != int32(lbPort) { continue } for _, v := range v.PolicyNames { - if aws.StringValue(v) == policyName { + if v == policyName { return policy, nil } } diff --git a/internal/service/elb/app_cookie_stickiness_policy_test.go b/internal/service/elb/app_cookie_stickiness_policy_test.go index d6e3d604ca8..96ad7d34988 100644 --- a/internal/service/elb/app_cookie_stickiness_policy_test.go +++ b/internal/service/elb/app_cookie_stickiness_policy_test.go @@ -103,7 +103,7 @@ func TestAccELBAppCookieStickinessPolicy_Disappears_elb(t *testing.T) { func testAccCheckAppCookieStickinessPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_app_cookie_stickiness_policy" { @@ -150,7 +150,7 @@ func testAccCheckAppCookieStickinessPolicyExists(ctx context.Context, n string) return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) _, err = tfelb.FindLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) From 30cb9731e9f347da0e76b81faaa410e1db42bd8c Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:19:22 +0100 Subject: [PATCH 04/37] r/elb_attachment: Migrate to AWS SDK v2 --- internal/service/elb/attachment.go | 38 +++++++++++++------------ internal/service/elb/attachment_test.go | 29 ++++++++++--------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/internal/service/elb/attachment.go b/internal/service/elb/attachment.go index 4dad85856f7..56b62d97964 100644 --- a/internal/service/elb/attachment.go +++ b/internal/service/elb/attachment.go @@ -9,14 +9,16 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) @@ -46,20 +48,20 @@ func ResourceAttachment() *schema.Resource { func resourceAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) elbName := d.Get("elb").(string) instance := d.Get("instance").(string) - registerInstancesOpts := elb.RegisterInstancesWithLoadBalancerInput{ + registerInstancesOpts := elasticloadbalancing.RegisterInstancesWithLoadBalancerInput{ LoadBalancerName: aws.String(elbName), - Instances: []*elb.Instance{{InstanceId: aws.String(instance)}}, + Instances: []awstypes.Instance{{InstanceId: aws.String(instance)}}, } log.Printf("[INFO] registering instance %s with ELB %s", instance, elbName) err := retry.RetryContext(ctx, 10*time.Minute, func() *retry.RetryError { - _, err := conn.RegisterInstancesWithLoadBalancerWithContext(ctx, ®isterInstancesOpts) + _, err := conn.RegisterInstancesWithLoadBalancer(ctx, ®isterInstancesOpts) if tfawserr.ErrCodeEquals(err, "InvalidTarget") { return retry.RetryableError(fmt.Errorf("attaching instance to ELB, retrying: %s", err)) @@ -72,7 +74,7 @@ func resourceAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta return nil }) if tfresource.TimedOut(err) { - _, err = conn.RegisterInstancesWithLoadBalancerWithContext(ctx, ®isterInstancesOpts) + _, err = conn.RegisterInstancesWithLoadBalancer(ctx, ®isterInstancesOpts) } if err != nil { return sdkdiag.AppendErrorf(diags, "Failure registering instances with ELB: %s", err) @@ -86,20 +88,20 @@ func resourceAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta func resourceAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) elbName := d.Get("elb").(string) // only add the instance that was previously defined for this resource expected := d.Get("instance").(string) // Retrieve the ELB properties to get a list of attachments - describeElbOpts := &elb.DescribeLoadBalancersInput{ - LoadBalancerNames: []*string{aws.String(elbName)}, + describeElbOpts := &elasticloadbalancing.DescribeLoadBalancersInput{ + LoadBalancerNames: []string{elbName}, } - resp, err := conn.DescribeLoadBalancersWithContext(ctx, describeElbOpts) + resp, err := conn.DescribeLoadBalancers(ctx, describeElbOpts) if err != nil { - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, elb.ErrCodeAccessPointNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.AccessPointNotFoundException](err) { log.Printf("[WARN] ELB Classic LB (%s) not found, removing from state", elbName) d.SetId("") return diags @@ -115,7 +117,7 @@ func resourceAttachmentRead(ctx context.Context, d *schema.ResourceData, meta in // only set the instance Id that this resource manages found := false for _, i := range resp.LoadBalancerDescriptions[0].Instances { - if expected == aws.StringValue(i.InstanceId) { + if expected == aws.ToString(i.InstanceId) { d.Set("instance", expected) found = true } @@ -131,19 +133,19 @@ func resourceAttachmentRead(ctx context.Context, d *schema.ResourceData, meta in func resourceAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) elbName := d.Get("elb").(string) instance := d.Get("instance").(string) log.Printf("[INFO] Deleting Attachment %s from: %s", instance, elbName) - deRegisterInstancesOpts := elb.DeregisterInstancesFromLoadBalancerInput{ + deRegisterInstancesOpts := elasticloadbalancing.DeregisterInstancesFromLoadBalancerInput{ LoadBalancerName: aws.String(elbName), - Instances: []*elb.Instance{{InstanceId: aws.String(instance)}}, + Instances: []awstypes.Instance{{InstanceId: aws.String(instance)}}, } - _, err := conn.DeregisterInstancesFromLoadBalancerWithContext(ctx, &deRegisterInstancesOpts) + _, err := conn.DeregisterInstancesFromLoadBalancer(ctx, &deRegisterInstancesOpts) if err != nil { return sdkdiag.AppendErrorf(diags, "Failure deregistering instances from ELB: %s", err) } diff --git a/internal/service/elb/attachment_test.go b/internal/service/elb/attachment_test.go index 41ab621f891..a6e18f2c289 100644 --- a/internal/service/elb/attachment_test.go +++ b/internal/service/elb/attachment_test.go @@ -8,7 +8,8 @@ import ( "log" "testing" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -18,8 +19,8 @@ import ( func TestAccELBAttachment_basic(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription - resourceName := "aws_elb.test" + var conf awstypes.LoadBalancerDescription + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -62,20 +63,20 @@ func TestAccELBAttachment_basic(t *testing.T) { // remove and instance and check that it's correctly re-attached. func TestAccELBAttachment_drift(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription - resourceName := "aws_elb.test" + var conf awstypes.LoadBalancerDescription + resourceName := "aws_elasticloadbalancing.test" testAccAttachmentConfig_deregInstance := func() { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) - deRegisterInstancesOpts := elb.DeregisterInstancesFromLoadBalancerInput{ + deRegisterInstancesOpts := elasticloadbalancing.DeregisterInstancesFromLoadBalancerInput{ LoadBalancerName: conf.LoadBalancerName, Instances: conf.Instances, } log.Printf("[DEBUG] deregistering instance %v from ELB", *conf.Instances[0].InstanceId) - _, err := conn.DeregisterInstancesFromLoadBalancerWithContext(ctx, &deRegisterInstancesOpts) + _, err := conn.DeregisterInstancesFromLoadBalancer(ctx, &deRegisterInstancesOpts) if err != nil { t.Fatalf("Failure deregistering instances from ELB: %s", err) } @@ -107,7 +108,7 @@ func TestAccELBAttachment_drift(t *testing.T) { }) } -func testAccAttachmentCheckInstanceCount(conf *elb.LoadBalancerDescription, expected int) resource.TestCheckFunc { +func testAccAttachmentCheckInstanceCount(conf *awstypes.LoadBalancerDescription, expected int) resource.TestCheckFunc { return func(*terraform.State) error { if actual := len(conf.Instances); actual != expected { return fmt.Errorf("instance count does not match: expected %d, got %d", expected, actual) @@ -145,7 +146,7 @@ resource "aws_instance" "foo1" { } resource "aws_elb_attachment" "foo1" { - elb = aws_elb.test.id + elb = aws_elasticloadbalancing.test.id instance = aws_instance.foo1.id } `) @@ -185,12 +186,12 @@ resource "aws_instance" "foo2" { } resource "aws_elb_attachment" "foo1" { - elb = aws_elb.test.id + elb = aws_elasticloadbalancing.test.id instance = aws_instance.foo1.id } resource "aws_elb_attachment" "foo2" { - elb = aws_elb.test.id + elb = aws_elasticloadbalancing.test.id instance = aws_instance.foo2.id } `) @@ -230,12 +231,12 @@ resource "aws_instance" "foo2" { } resource "aws_elb_attachment" "foo1" { - elb = aws_elb.test.id + elb = aws_elasticloadbalancing.test.id instance = aws_instance.foo2.id } resource "aws_elb_attachment" "foo2" { - elb = aws_elb.test.id + elb = aws_elasticloadbalancing.test.id instance = aws_instance.foo1.id } `) From 6607aff9f98a903882e64103c0742d1a5e16266f Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:20:08 +0100 Subject: [PATCH 05/37] r/load_balancer_backend_server_policy: Migrate to AWS SDK v2 --- internal/service/elb/backend_server_policy.go | 36 +++++++++---------- .../service/elb/backend_server_policy_test.go | 4 +-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/internal/service/elb/backend_server_policy.go b/internal/service/elb/backend_server_policy.go index 7f84b5e6a18..04bce7b9dc6 100644 --- a/internal/service/elb/backend_server_policy.go +++ b/internal/service/elb/backend_server_policy.go @@ -10,8 +10,8 @@ import ( "strconv" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" "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" @@ -48,21 +48,21 @@ func ResourceBackendServerPolicy() *schema.Resource { func resourceBackendServerPolicySet(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) instancePort := d.Get("instance_port").(int) lbName := d.Get("load_balancer_name").(string) id := BackendServerPolicyCreateResourceID(lbName, instancePort) - input := &elb.SetLoadBalancerPoliciesForBackendServerInput{ - InstancePort: aws.Int64(int64(instancePort)), + input := &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ + InstancePort: aws.Int32(int32(instancePort)), LoadBalancerName: aws.String(lbName), } if v, ok := d.GetOk("policy_names"); ok && v.(*schema.Set).Len() > 0 { - input.PolicyNames = flex.ExpandStringSet(v.(*schema.Set)) + input.PolicyNames = flex.ExpandStringValueSet(v.(*schema.Set)) } - _, err := conn.SetLoadBalancerPoliciesForBackendServerWithContext(ctx, input) + _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic Backend Server Policy (%s): %s", id, err) @@ -75,7 +75,7 @@ func resourceBackendServerPolicySet(ctx context.Context, d *schema.ResourceData, func resourceBackendServerPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, instancePort, err := BackendServerPolicyParseResourceID(d.Id()) @@ -104,7 +104,7 @@ func resourceBackendServerPolicyRead(ctx context.Context, d *schema.ResourceData func resourceBackendServerPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, instancePort, err := BackendServerPolicyParseResourceID(d.Id()) @@ -112,14 +112,14 @@ func resourceBackendServerPolicyDelete(ctx context.Context, d *schema.ResourceDa return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) } - input := &elb.SetLoadBalancerPoliciesForBackendServerInput{ - InstancePort: aws.Int64(int64(instancePort)), + input := &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ + InstancePort: aws.Int32(int32(instancePort)), LoadBalancerName: aws.String(lbName), - PolicyNames: aws.StringSlice([]string{}), + PolicyNames: []string{}, } log.Printf("[DEBUG] Deleting ELB Classic Backend Server Policy: %s", d.Id()) - _, err = conn.SetLoadBalancerPoliciesForBackendServerWithContext(ctx, input) + _, err = conn.SetLoadBalancerPoliciesForBackendServer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic Backend Server Policy (%s): %s", d.Id(), err) @@ -128,7 +128,7 @@ func resourceBackendServerPolicyDelete(ctx context.Context, d *schema.ResourceDa return diags } -func FindLoadBalancerBackendServerPolicyByTwoPartKey(ctx context.Context, conn *elb.ELB, lbName string, instancePort int) ([]string, error) { +func FindLoadBalancerBackendServerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, instancePort int) ([]string, error) { lb, err := FindLoadBalancerByName(ctx, conn, lbName) if err != nil { @@ -138,15 +138,11 @@ func FindLoadBalancerBackendServerPolicyByTwoPartKey(ctx context.Context, conn * var policyNames []string for _, v := range lb.BackendServerDescriptions { - if v == nil { + if aws.ToInt32(v.InstancePort) != int32(instancePort) { continue } - if aws.Int64Value(v.InstancePort) != int64(instancePort) { - continue - } - - policyNames = append(policyNames, aws.StringValueSlice(v.PolicyNames)...) + policyNames = append(policyNames, v.PolicyNames...) } return policyNames, nil diff --git a/internal/service/elb/backend_server_policy_test.go b/internal/service/elb/backend_server_policy_test.go index f149dda94ae..7baa0a7f533 100644 --- a/internal/service/elb/backend_server_policy_test.go +++ b/internal/service/elb/backend_server_policy_test.go @@ -115,7 +115,7 @@ func TestAccELBBackendServerPolicy_update(t *testing.T) { func testAccCheckBackendServerPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_load_balancer_backend_policy" { @@ -162,7 +162,7 @@ func testAccCheckBackendServerPolicyExists(ctx context.Context, n string) resour return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) _, err = tfelb.FindLoadBalancerBackendServerPolicyByTwoPartKey(ctx, conn, lbName, instancePort) From f599819dc530edc494179f8a76d5d5aa7ddd2153 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:21:05 +0100 Subject: [PATCH 06/37] r/lb_cookie_stickiness_policy: Migrate to AWS SDK v2 --- .../elb/lb_cookie_stickiness_policy.go | 36 +++++++++---------- .../elb/lb_cookie_stickiness_policy_test.go | 4 +-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/internal/service/elb/lb_cookie_stickiness_policy.go b/internal/service/elb/lb_cookie_stickiness_policy.go index 105fce4de73..4399d76ab85 100644 --- a/internal/service/elb/lb_cookie_stickiness_policy.go +++ b/internal/service/elb/lb_cookie_stickiness_policy.go @@ -10,8 +10,8 @@ import ( "strconv" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" "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" @@ -56,14 +56,14 @@ func ResourceCookieStickinessPolicy() *schema.Resource { func resourceCookieStickinessPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName := d.Get("load_balancer").(string) lbPort := d.Get("lb_port").(int) policyName := d.Get(names.AttrName).(string) id := LBCookieStickinessPolicyCreateResourceID(lbName, lbPort, policyName) { - input := &elb.CreateLBCookieStickinessPolicyInput{ + input := &elasticloadbalancing.CreateLBCookieStickinessPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), } @@ -72,7 +72,7 @@ func resourceCookieStickinessPolicyCreate(ctx context.Context, d *schema.Resourc input.CookieExpirationPeriod = aws.Int64(int64(v.(int))) } - _, err := conn.CreateLBCookieStickinessPolicyWithContext(ctx, input) + _, err := conn.CreateLBCookieStickinessPolicy(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ELB Classic LB Cookie Stickiness Policy (%s): %s", id, err) @@ -80,13 +80,13 @@ func resourceCookieStickinessPolicyCreate(ctx context.Context, d *schema.Resourc } { - input := &elb.SetLoadBalancerPoliciesOfListenerInput{ + input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), - LoadBalancerPort: aws.Int64(int64(lbPort)), - PolicyNames: aws.StringSlice([]string{policyName}), + LoadBalancerPort: int32(lbPort), + PolicyNames: []string{policyName}, } - _, err := conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, input) + _, err := conn.SetLoadBalancerPoliciesOfListener(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic LB Cookie Stickiness Policy (%s): %s", id, err) @@ -100,7 +100,7 @@ func resourceCookieStickinessPolicyCreate(ctx context.Context, d *schema.Resourc func resourceCookieStickinessPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, lbPort, policyName, err := LBCookieStickinessPolicyParseResourceID(d.Id()) @@ -120,10 +120,10 @@ func resourceCookieStickinessPolicyRead(ctx context.Context, d *schema.ResourceD return sdkdiag.AppendErrorf(diags, "reading ELB Classic LB Cookie Stickiness Policy (%s): %s", d.Id(), err) } - if len(policy.PolicyAttributeDescriptions) != 1 || aws.StringValue(policy.PolicyAttributeDescriptions[0].AttributeName) != "CookieExpirationPeriod" { + if len(policy.PolicyAttributeDescriptions) != 1 || aws.ToString(policy.PolicyAttributeDescriptions[0].AttributeName) != "CookieExpirationPeriod" { return sdkdiag.AppendErrorf(diags, "cookie expiration period not found") } - if v, err := strconv.Atoi(aws.StringValue(policy.PolicyAttributeDescriptions[0].AttributeValue)); err != nil { + if v, err := strconv.Atoi(aws.ToString(policy.PolicyAttributeDescriptions[0].AttributeValue)); err != nil { return sdkdiag.AppendErrorf(diags, "parsing cookie expiration period: %s", err) } else { d.Set("cookie_expiration_period", v) @@ -137,7 +137,7 @@ func resourceCookieStickinessPolicyRead(ctx context.Context, d *schema.ResourceD func resourceCookieStickinessPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, lbPort, policyName, err := LBCookieStickinessPolicyParseResourceID(d.Id()) @@ -148,20 +148,20 @@ func resourceCookieStickinessPolicyDelete(ctx context.Context, d *schema.Resourc // Perversely, if we Set an empty list of PolicyNames, we detach the // policies attached to a listener, which is required to delete the // policy itself. - input := &elb.SetLoadBalancerPoliciesOfListenerInput{ + input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), - LoadBalancerPort: aws.Int64(int64(lbPort)), - PolicyNames: aws.StringSlice([]string{}), + LoadBalancerPort: int32(lbPort), + PolicyNames: []string{}, } - _, err = conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, input) + _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic LB Cookie Stickiness Policy (%s): %s", d.Id(), err) } log.Printf("[DEBUG] Deleting ELB Classic LB Cookie Stickiness Policy: %s", d.Id()) - _, err = conn.DeleteLoadBalancerPolicyWithContext(ctx, &elb.DeleteLoadBalancerPolicyInput{ + _, err = conn.DeleteLoadBalancerPolicy(ctx, &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), }) diff --git a/internal/service/elb/lb_cookie_stickiness_policy_test.go b/internal/service/elb/lb_cookie_stickiness_policy_test.go index abcca5c86e4..1598edf4a09 100644 --- a/internal/service/elb/lb_cookie_stickiness_policy_test.go +++ b/internal/service/elb/lb_cookie_stickiness_policy_test.go @@ -98,7 +98,7 @@ func TestAccELBCookieStickinessPolicy_Disappears_elb(t *testing.T) { func testAccCheckLBCookieStickinessPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_lb_cookie_stickiness_policy" { @@ -145,7 +145,7 @@ func testAccCheckLBCookieStickinessPolicyExists(ctx context.Context, n string) r return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) _, err = tfelb.FindLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) From 3996f19bcdf914be38b9ee4ec9cda61a0768dede Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:21:44 +0100 Subject: [PATCH 07/37] r/lb_ssl_negotiation_policy: Migrate to AWS SDK v2 --- .../service/elb/lb_ssl_negotiation_policy.go | 32 +++++++++---------- .../elb/lb_ssl_negotiation_policy_test.go | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/service/elb/lb_ssl_negotiation_policy.go b/internal/service/elb/lb_ssl_negotiation_policy.go index cd03716c743..49f48e5caf9 100644 --- a/internal/service/elb/lb_ssl_negotiation_policy.go +++ b/internal/service/elb/lb_ssl_negotiation_policy.go @@ -10,8 +10,8 @@ import ( "strconv" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" "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" @@ -72,7 +72,7 @@ func ResourceSSLNegotiationPolicy() *schema.Resource { func resourceSSLNegotiationPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName := d.Get("load_balancer").(string) lbPort := d.Get("lb_port").(int) @@ -80,7 +80,7 @@ func resourceSSLNegotiationPolicyCreate(ctx context.Context, d *schema.ResourceD id := SSLNegotiationPolicyCreateResourceID(lbName, lbPort, policyName) { - input := &elb.CreateLoadBalancerPolicyInput{ + input := &elasticloadbalancing.CreateLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), PolicyTypeName: aws.String("SSLNegotiationPolicyType"), @@ -90,7 +90,7 @@ func resourceSSLNegotiationPolicyCreate(ctx context.Context, d *schema.ResourceD input.PolicyAttributes = ExpandPolicyAttributes(v.(*schema.Set).List()) } - _, err := conn.CreateLoadBalancerPolicyWithContext(ctx, input) + _, err := conn.CreateLoadBalancerPolicy(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ELB Classic SSL Negotiation Policy (%s): %s", id, err) @@ -98,13 +98,13 @@ func resourceSSLNegotiationPolicyCreate(ctx context.Context, d *schema.ResourceD } { - input := &elb.SetLoadBalancerPoliciesOfListenerInput{ + input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), - LoadBalancerPort: aws.Int64(int64(lbPort)), - PolicyNames: aws.StringSlice([]string{policyName}), + LoadBalancerPort: int32(lbPort), + PolicyNames: []string{policyName}, } - _, err := conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, input) + _, err := conn.SetLoadBalancerPoliciesOfListener(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic SSL Negotiation Policy (%s): %s", id, err) @@ -118,7 +118,7 @@ func resourceSSLNegotiationPolicyCreate(ctx context.Context, d *schema.ResourceD func resourceSSLNegotiationPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, lbPort, policyName, err := SSLNegotiationPolicyParseResourceID(d.Id()) @@ -162,7 +162,7 @@ func resourceSSLNegotiationPolicyRead(ctx context.Context, d *schema.ResourceDat func resourceSSLNegotiationPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, lbPort, policyName, err := SSLNegotiationPolicyParseResourceID(d.Id()) @@ -173,19 +173,19 @@ func resourceSSLNegotiationPolicyDelete(ctx context.Context, d *schema.ResourceD // Perversely, if we Set an empty list of PolicyNames, we detach the // policies attached to a listener, which is required to delete the // policy itself. - input := &elb.SetLoadBalancerPoliciesOfListenerInput{ + input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), - LoadBalancerPort: aws.Int64(int64(lbPort)), - PolicyNames: aws.StringSlice([]string{}), + LoadBalancerPort: int32(lbPort), + PolicyNames: []string{}, } - _, err = conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, input) + _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic SSL Negotiation Policy (%s): %s", d.Id(), err) } - _, err = conn.DeleteLoadBalancerPolicyWithContext(ctx, &elb.DeleteLoadBalancerPolicyInput{ + _, err = conn.DeleteLoadBalancerPolicy(ctx, &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), }) diff --git a/internal/service/elb/lb_ssl_negotiation_policy_test.go b/internal/service/elb/lb_ssl_negotiation_policy_test.go index 449cfdbc2b6..781aff155fc 100644 --- a/internal/service/elb/lb_ssl_negotiation_policy_test.go +++ b/internal/service/elb/lb_ssl_negotiation_policy_test.go @@ -104,7 +104,7 @@ func TestAccELBSSLNegotiationPolicy_disappears(t *testing.T) { func testAccCheckLBSSLNegotiationPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_lb_ssl_negotiation_policy" { @@ -151,7 +151,7 @@ func testAccCheckLBSSLNegotiationPolicy(ctx context.Context, n string) resource. return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) _, err = tfelb.FindLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) From ed3ea693f83d56e5f111250b7d89f76a57170bdc Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:22:26 +0100 Subject: [PATCH 08/37] r/load_balancer_listener_policy: Migrate to AWS SDK v2 --- internal/service/elb/listener_policy.go | 36 +++++++++----------- internal/service/elb/listener_policy_test.go | 4 +-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/internal/service/elb/listener_policy.go b/internal/service/elb/listener_policy.go index 8ff47c4f2dc..2462a8b0fdb 100644 --- a/internal/service/elb/listener_policy.go +++ b/internal/service/elb/listener_policy.go @@ -10,8 +10,8 @@ import ( "strconv" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" "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" @@ -54,21 +54,21 @@ func ResourceListenerPolicy() *schema.Resource { func resourceListenerPolicySet(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName := d.Get("load_balancer_name").(string) lbPort := d.Get("load_balancer_port").(int) id := ListenerPolicyCreateResourceID(lbName, lbPort) - input := &elb.SetLoadBalancerPoliciesOfListenerInput{ + input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), - LoadBalancerPort: aws.Int64(int64(lbPort)), + LoadBalancerPort: int32(lbPort), } if v, ok := d.GetOk("policy_names"); ok && v.(*schema.Set).Len() > 0 { - input.PolicyNames = flex.ExpandStringSet(v.(*schema.Set)) + input.PolicyNames = flex.ExpandStringValueSet(v.(*schema.Set)) } - _, err := conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, input) + _, err := conn.SetLoadBalancerPoliciesOfListener(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic Listener Policy (%s): %s", id, err) @@ -81,7 +81,7 @@ func resourceListenerPolicySet(ctx context.Context, d *schema.ResourceData, meta func resourceListenerPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, lbPort, err := ListenerPolicyParseResourceID(d.Id()) @@ -110,7 +110,7 @@ func resourceListenerPolicyRead(ctx context.Context, d *schema.ResourceData, met func resourceListenerPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, lbPort, err := ListenerPolicyParseResourceID(d.Id()) @@ -118,14 +118,14 @@ func resourceListenerPolicyDelete(ctx context.Context, d *schema.ResourceData, m return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) } - input := &elb.SetLoadBalancerPoliciesOfListenerInput{ + input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), - LoadBalancerPort: aws.Int64(int64(lbPort)), - PolicyNames: aws.StringSlice([]string{}), + LoadBalancerPort: int32(lbPort), + PolicyNames: []string{}, } log.Printf("[DEBUG] Deleting ELB Classic Listener Policy: %s", d.Id()) - _, err = conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, input) + _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic Listener Policy (%s): %s", d.Id(), err) @@ -134,7 +134,7 @@ func resourceListenerPolicyDelete(ctx context.Context, d *schema.ResourceData, m return diags } -func FindLoadBalancerListenerPolicyByTwoPartKey(ctx context.Context, conn *elb.ELB, lbName string, lbPort int) ([]string, error) { +func FindLoadBalancerListenerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, lbPort int) ([]string, error) { lb, err := FindLoadBalancerByName(ctx, conn, lbName) if err != nil { @@ -144,15 +144,11 @@ func FindLoadBalancerListenerPolicyByTwoPartKey(ctx context.Context, conn *elb.E var policyNames []string for _, v := range lb.ListenerDescriptions { - if v == nil { + if v.Listener.LoadBalancerPort != int32(lbPort) { continue } - if aws.Int64Value(v.Listener.LoadBalancerPort) != int64(lbPort) { - continue - } - - policyNames = append(policyNames, aws.StringValueSlice(v.PolicyNames)...) + policyNames = append(policyNames, v.PolicyNames...) } return policyNames, nil diff --git a/internal/service/elb/listener_policy_test.go b/internal/service/elb/listener_policy_test.go index 1e6da4456d0..28c5fa54a27 100644 --- a/internal/service/elb/listener_policy_test.go +++ b/internal/service/elb/listener_policy_test.go @@ -106,7 +106,7 @@ func TestAccELBListenerPolicy_disappears(t *testing.T) { func testAccCheckListenerPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_load_balancer_listener_policy" { @@ -153,7 +153,7 @@ func testAccCheckListenerPolicyExists(ctx context.Context, n string) resource.Te return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) _, err = tfelb.FindLoadBalancerListenerPolicyByTwoPartKey(ctx, conn, lbName, lbPort) From def43f966b1b5c420592ab00286537c1dd8e2d80 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:23:04 +0100 Subject: [PATCH 09/37] d/elb, r/elb: Migrate to AWS SDK v2 --- internal/service/elb/load_balancer.go | 205 +++++++++--------- .../service/elb/load_balancer_data_source.go | 38 ++-- internal/service/elb/load_balancer_test.go | 119 +++++----- 3 files changed, 182 insertions(+), 180 deletions(-) diff --git a/internal/service/elb/load_balancer.go b/internal/service/elb/load_balancer.go index 5fef81e88b4..9baa893527d 100644 --- a/internal/service/elb/load_balancer.go +++ b/internal/service/elb/load_balancer.go @@ -14,11 +14,11 @@ import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports "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" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/elb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -26,6 +26,7 @@ import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tfec2 "github.com/hashicorp/terraform-provider-aws/internal/service/ec2" @@ -270,7 +271,7 @@ func ResourceLoadBalancer() *schema.Resource { func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) listeners, err := ExpandListeners(d.Get("listener").(*schema.Set).List()) if err != nil { @@ -282,14 +283,14 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, met create.WithConfiguredPrefix(d.Get(names.AttrNamePrefix).(string)), create.WithDefaultPrefix("tf-lb-"), ).Generate() - input := &elb.CreateLoadBalancerInput{ + input := &elasticloadbalancing.CreateLoadBalancerInput{ Listeners: listeners, LoadBalancerName: aws.String(elbName), Tags: getTagsIn(ctx), } if v, ok := d.GetOk(names.AttrAvailabilityZones); ok && v.(*schema.Set).Len() > 0 { - input.AvailabilityZones = flex.ExpandStringSet(v.(*schema.Set)) + input.AvailabilityZones = flex.ExpandStringValueSet(v.(*schema.Set)) } if _, ok := d.GetOk("internal"); ok { @@ -297,16 +298,16 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, met } if v, ok := d.GetOk(names.AttrSecurityGroups); ok && v.(*schema.Set).Len() > 0 { - input.SecurityGroups = flex.ExpandStringSet(v.(*schema.Set)) + input.SecurityGroups = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk(names.AttrSubnets); ok && v.(*schema.Set).Len() > 0 { - input.Subnets = flex.ExpandStringSet(v.(*schema.Set)) + input.Subnets = flex.ExpandStringValueSet(v.(*schema.Set)) } - _, err = tfresource.RetryWhenAWSErrCodeEquals(ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { - return conn.CreateLoadBalancerWithContext(ctx, input) - }, elb.ErrCodeCertificateNotFoundException) + _, err = tfresource.RetryWhenIsA[*awstypes.CertificateNotFoundException](ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { + return conn.CreateLoadBalancer(ctx, input) + }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ELB Classic Load Balancer (%s): %s", elbName, err) @@ -319,7 +320,7 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, met func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lb, err := FindLoadBalancerByName(ctx, conn, d.Id()) @@ -347,7 +348,7 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta Resource: fmt.Sprintf("loadbalancer/%s", d.Id()), } d.Set(names.AttrARN, arn.String()) - d.Set(names.AttrAvailabilityZones, flex.FlattenStringList(lb.AvailabilityZones)) + d.Set(names.AttrAvailabilityZones, flex.FlattenStringValueList(lb.AvailabilityZones)) d.Set("connection_draining", lbAttrs.ConnectionDraining.Enabled) d.Set("connection_draining_timeout", lbAttrs.ConnectionDraining.Timeout) d.Set("cross_zone_load_balancing", lbAttrs.CrossZoneLoadBalancing.Enabled) @@ -358,26 +359,26 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta d.Set("instances", flattenInstances(lb.Instances)) var scheme bool if lb.Scheme != nil { - scheme = aws.StringValue(lb.Scheme) == "internal" + scheme = aws.ToString(lb.Scheme) == "internal" } d.Set("internal", scheme) d.Set("listener", flattenListeners(lb.ListenerDescriptions)) d.Set(names.AttrName, lb.LoadBalancerName) - d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.StringValue(lb.LoadBalancerName))) - d.Set(names.AttrSecurityGroups, flex.FlattenStringList(lb.SecurityGroups)) - d.Set(names.AttrSubnets, flex.FlattenStringList(lb.Subnets)) + d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(lb.LoadBalancerName))) + d.Set(names.AttrSecurityGroups, flex.FlattenStringValueList(lb.SecurityGroups)) + d.Set(names.AttrSubnets, flex.FlattenStringValueList(lb.Subnets)) d.Set("zone_id", lb.CanonicalHostedZoneNameID) if lb.SourceSecurityGroup != nil { group := lb.SourceSecurityGroup.GroupName - if v := aws.StringValue(lb.SourceSecurityGroup.OwnerAlias); v != "" { - group = aws.String(v + "/" + aws.StringValue(lb.SourceSecurityGroup.GroupName)) + if v := aws.ToString(lb.SourceSecurityGroup.OwnerAlias); v != "" { + group = aws.String(v + "/" + aws.ToString(lb.SourceSecurityGroup.GroupName)) } d.Set("source_security_group", group) // Manually look up the ELB Security Group ID, since it's not provided if lb.VPCId != nil { - sg, err := tfec2.FindSecurityGroupByNameAndVPCIDAndOwnerID(ctx, meta.(*conns.AWSClient).EC2Conn(ctx), aws.StringValue(lb.SourceSecurityGroup.GroupName), aws.StringValue(lb.VPCId), aws.StringValue(lb.SourceSecurityGroup.OwnerAlias)) + sg, err := tfec2.FindSecurityGroupByNameAndVPCIDAndOwnerID(ctx, meta.(*conns.AWSClient).EC2Conn(ctx), aws.ToString(lb.SourceSecurityGroup.GroupName), aws.ToString(lb.VPCId), aws.ToString(lb.SourceSecurityGroup.OwnerAlias)) if err != nil { return sdkdiag.AppendErrorf(diags, "reading ELB Classic Load Balancer (%s) security group: %s", d.Id(), err) } else { @@ -403,7 +404,7 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta _, n := d.GetChange("access_logs") elbal := lbAttrs.AccessLog nl := n.([]interface{}) - if len(nl) == 0 && !aws.BoolValue(elbal.Enabled) { + if len(nl) == 0 && !elbal.Enabled { elbal = nil } if err := d.Set("access_logs", flattenAccessLog(elbal)); err != nil { @@ -412,15 +413,15 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta } for _, attr := range lbAttrs.AdditionalAttributes { - switch aws.StringValue(attr.Key) { - case "elb.http.desyncmitigationmode": + switch aws.ToString(attr.Key) { + case "elasticloadbalancing.http.desyncmitigationmode": d.Set("desync_mitigation_mode", attr.Value) } } // There's only one health check, so save that to state as we // currently can - if aws.StringValue(lb.HealthCheck.Target) != "" { + if aws.ToString(lb.HealthCheck.Target) != "" { if err := d.Set(names.AttrHealthCheck, FlattenHealthCheck(lb.HealthCheck)); err != nil { return sdkdiag.AppendErrorf(diags, "setting health_check: %s", err) } @@ -431,7 +432,7 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) if d.HasChange("listener") { o, n := d.GetChange("listener") @@ -446,17 +447,17 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } if len(remove) > 0 { - ports := make([]*int64, 0, len(remove)) + ports := make([]int32, 0, len(remove)) for _, listener := range remove { ports = append(ports, listener.LoadBalancerPort) } - input := &elb.DeleteLoadBalancerListenersInput{ + input := &elasticloadbalancing.DeleteLoadBalancerListenersInput{ LoadBalancerName: aws.String(d.Id()), LoadBalancerPorts: ports, } - _, err := conn.DeleteLoadBalancerListenersWithContext(ctx, input) + _, err := conn.DeleteLoadBalancerListeners(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "deleting ELB Classic Load Balancer (%s) listeners: %s", d.Id(), err) @@ -464,7 +465,7 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } if len(add) > 0 { - input := &elb.CreateLoadBalancerListenersInput{ + input := &elasticloadbalancing.CreateLoadBalancerListenersInput{ Listeners: add, LoadBalancerName: aws.String(d.Id()), } @@ -473,13 +474,13 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met // other listeners on the ELB. Retry here to eliminate that. _, err := tfresource.RetryWhen(ctx, d.Timeout(schema.TimeoutUpdate), func() (interface{}, error) { - return conn.CreateLoadBalancerListenersWithContext(ctx, input) + return conn.CreateLoadBalancerListeners(ctx, input) }, func(err error) (bool, error) { - if tfawserr.ErrCodeEquals(err, elb.ErrCodeDuplicateListenerException) { + if errs.IsA[*awstypes.DuplicateListenerException](err) { return true, err } - if tfawserr.ErrMessageContains(err, elb.ErrCodeCertificateNotFoundException, "Server Certificate not found for the key: arn") { + if errs.IsAErrorMessageContains[*awstypes.CertificateNotFoundException](err, "Server Certificate not found for the key: arn") { return true, err } @@ -503,12 +504,12 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met add := ExpandInstanceString(ns.Difference(os).List()) if len(add) > 0 { - input := &elb.RegisterInstancesWithLoadBalancerInput{ + input := &elasticloadbalancing.RegisterInstancesWithLoadBalancerInput{ Instances: add, LoadBalancerName: aws.String(d.Id()), } - _, err := conn.RegisterInstancesWithLoadBalancerWithContext(ctx, input) + _, err := conn.RegisterInstancesWithLoadBalancer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "registering ELB Classic Load Balancer (%s) instances: %s", d.Id(), err) @@ -516,12 +517,12 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } if len(remove) > 0 { - input := &elb.DeregisterInstancesFromLoadBalancerInput{ + input := &elasticloadbalancing.DeregisterInstancesFromLoadBalancerInput{ Instances: remove, LoadBalancerName: aws.String(d.Id()), } - _, err := conn.DeregisterInstancesFromLoadBalancerWithContext(ctx, input) + _, err := conn.DeregisterInstancesFromLoadBalancer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "deregistering ELB Classic Load Balancer (%s) instances: %s", d.Id(), err) @@ -530,19 +531,19 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } if d.HasChanges("cross_zone_load_balancing", "idle_timeout", "access_logs", "desync_mitigation_mode") { - input := &elb.ModifyLoadBalancerAttributesInput{ - LoadBalancerAttributes: &elb.LoadBalancerAttributes{ - AdditionalAttributes: []*elb.AdditionalAttribute{ + input := &elasticloadbalancing.ModifyLoadBalancerAttributesInput{ + LoadBalancerAttributes: &awstypes.LoadBalancerAttributes{ + AdditionalAttributes: []awstypes.AdditionalAttribute{ { - Key: aws.String("elb.http.desyncmitigationmode"), + Key: aws.String("elasticloadbalancing.http.desyncmitigationmode"), Value: aws.String(d.Get("desync_mitigation_mode").(string)), }, }, - CrossZoneLoadBalancing: &elb.CrossZoneLoadBalancing{ - Enabled: aws.Bool(d.Get("cross_zone_load_balancing").(bool)), + CrossZoneLoadBalancing: &awstypes.CrossZoneLoadBalancing{ + Enabled: d.Get("cross_zone_load_balancing").(bool), }, - ConnectionSettings: &elb.ConnectionSettings{ - IdleTimeout: aws.Int64(int64(d.Get("idle_timeout").(int))), + ConnectionSettings: &awstypes.ConnectionSettings{ + IdleTimeout: aws.Int32(int32(d.Get("idle_timeout").(int))), }, }, LoadBalancerName: aws.String(d.Id()), @@ -550,20 +551,20 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met if logs := d.Get("access_logs").([]interface{}); len(logs) == 1 { l := logs[0].(map[string]interface{}) - input.LoadBalancerAttributes.AccessLog = &elb.AccessLog{ - Enabled: aws.Bool(l[names.AttrEnabled].(bool)), - EmitInterval: aws.Int64(int64(l[names.AttrInterval].(int))), + input.LoadBalancerAttributes.AccessLog = &awstypes.AccessLog{ + Enabled: l[names.AttrEnabled].(bool), + EmitInterval: aws.Int32(int32(l[names.AttrInterval].(int))), S3BucketName: aws.String(l[names.AttrBucket].(string)), S3BucketPrefix: aws.String(l[names.AttrBucketPrefix].(string)), } } else if len(logs) == 0 { // disable access logs - input.LoadBalancerAttributes.AccessLog = &elb.AccessLog{ - Enabled: aws.Bool(false), + input.LoadBalancerAttributes.AccessLog = &awstypes.AccessLog{ + Enabled: false, } } - _, err := conn.ModifyLoadBalancerAttributesWithContext(ctx, input) + _, err := conn.ModifyLoadBalancerAttributes(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "modifying ELB Classic Load Balancer (%s) attributes: %s", d.Id(), err) @@ -578,17 +579,17 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met // We do timeout changes first since they require us to set draining // to true for a hot second. if d.HasChange("connection_draining_timeout") { - input := &elb.ModifyLoadBalancerAttributesInput{ - LoadBalancerAttributes: &elb.LoadBalancerAttributes{ - ConnectionDraining: &elb.ConnectionDraining{ - Enabled: aws.Bool(true), - Timeout: aws.Int64(int64(d.Get("connection_draining_timeout").(int))), + input := &elasticloadbalancing.ModifyLoadBalancerAttributesInput{ + LoadBalancerAttributes: &awstypes.LoadBalancerAttributes{ + ConnectionDraining: &awstypes.ConnectionDraining{ + Enabled: true, + Timeout: aws.Int32(int32(d.Get("connection_draining_timeout").(int))), }, }, LoadBalancerName: aws.String(d.Id()), } - _, err := conn.ModifyLoadBalancerAttributesWithContext(ctx, input) + _, err := conn.ModifyLoadBalancerAttributes(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "modifying ELB Classic Load Balancer (%s) attributes: %s", d.Id(), err) @@ -598,16 +599,16 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met // Then we always set connection draining even if there is no change. // This lets us reset to "false" if requested even with a timeout // change. - input := &elb.ModifyLoadBalancerAttributesInput{ - LoadBalancerAttributes: &elb.LoadBalancerAttributes{ - ConnectionDraining: &elb.ConnectionDraining{ - Enabled: aws.Bool(d.Get("connection_draining").(bool)), + input := &elasticloadbalancing.ModifyLoadBalancerAttributesInput{ + LoadBalancerAttributes: &awstypes.LoadBalancerAttributes{ + ConnectionDraining: &awstypes.ConnectionDraining{ + Enabled: d.Get("connection_draining").(bool), }, }, LoadBalancerName: aws.String(d.Id()), } - _, err := conn.ModifyLoadBalancerAttributesWithContext(ctx, input) + _, err := conn.ModifyLoadBalancerAttributes(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "modifying ELB Classic Load Balancer (%s) attributes: %s", d.Id(), err) @@ -617,17 +618,17 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met if d.HasChange(names.AttrHealthCheck) { if hc := d.Get(names.AttrHealthCheck).([]interface{}); len(hc) > 0 { check := hc[0].(map[string]interface{}) - input := &elb.ConfigureHealthCheckInput{ - HealthCheck: &elb.HealthCheck{ - HealthyThreshold: aws.Int64(int64(check["healthy_threshold"].(int))), - Interval: aws.Int64(int64(check[names.AttrInterval].(int))), + input := &elasticloadbalancing.ConfigureHealthCheckInput{ + HealthCheck: &awstypes.HealthCheck{ + HealthyThreshold: aws.Int32(int32(check["healthy_threshold"].(int))), + Interval: aws.Int32(int32(check[names.AttrInterval].(int))), Target: aws.String(check[names.AttrTarget].(string)), - Timeout: aws.Int64(int64(check[names.AttrTimeout].(int))), - UnhealthyThreshold: aws.Int64(int64(check["unhealthy_threshold"].(int))), + Timeout: aws.Int32(int32(check[names.AttrTimeout].(int))), + UnhealthyThreshold: aws.Int32(int32(check["unhealthy_threshold"].(int))), }, LoadBalancerName: aws.String(d.Id()), } - _, err := conn.ConfigureHealthCheckWithContext(ctx, input) + _, err := conn.ConfigureHealthCheck(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "configuring ELB Classic Load Balancer (%s) health check: %s", d.Id(), err) @@ -636,12 +637,12 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } if d.HasChange(names.AttrSecurityGroups) { - input := &elb.ApplySecurityGroupsToLoadBalancerInput{ + input := &elasticloadbalancing.ApplySecurityGroupsToLoadBalancerInput{ LoadBalancerName: aws.String(d.Id()), - SecurityGroups: flex.ExpandStringSet(d.Get(names.AttrSecurityGroups).(*schema.Set)), + SecurityGroups: flex.ExpandStringValueSet(d.Get(names.AttrSecurityGroups).(*schema.Set)), } - _, err := conn.ApplySecurityGroupsToLoadBalancerWithContext(ctx, input) + _, err := conn.ApplySecurityGroupsToLoadBalancer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "applying ELB Classic Load Balancer (%s) security groups: %s", d.Id(), err) @@ -653,16 +654,16 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met os := o.(*schema.Set) ns := n.(*schema.Set) - removed := flex.ExpandStringSet(os.Difference(ns)) - added := flex.ExpandStringSet(ns.Difference(os)) + removed := flex.ExpandStringValueSet(os.Difference(ns)) + added := flex.ExpandStringValueSet(ns.Difference(os)) if len(added) > 0 { - input := &elb.EnableAvailabilityZonesForLoadBalancerInput{ + input := &elasticloadbalancing.EnableAvailabilityZonesForLoadBalancerInput{ AvailabilityZones: added, LoadBalancerName: aws.String(d.Id()), } - _, err := conn.EnableAvailabilityZonesForLoadBalancerWithContext(ctx, input) + _, err := conn.EnableAvailabilityZonesForLoadBalancer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "enabling ELB Classic Load Balancer (%s) Availability Zones: %s", d.Id(), err) @@ -670,12 +671,12 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } if len(removed) > 0 { - input := &elb.DisableAvailabilityZonesForLoadBalancerInput{ + input := &elasticloadbalancing.DisableAvailabilityZonesForLoadBalancerInput{ AvailabilityZones: removed, LoadBalancerName: aws.String(d.Id()), } - _, err := conn.DisableAvailabilityZonesForLoadBalancerWithContext(ctx, input) + _, err := conn.DisableAvailabilityZonesForLoadBalancer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "enabling ELB Classic Load Balancer (%s) Availability Zones: %s", d.Id(), err) @@ -688,16 +689,16 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met os := o.(*schema.Set) ns := n.(*schema.Set) - removed := flex.ExpandStringSet(os.Difference(ns)) - added := flex.ExpandStringSet(ns.Difference(os)) + removed := flex.ExpandStringValueSet(os.Difference(ns)) + added := flex.ExpandStringValueSet(ns.Difference(os)) if len(removed) > 0 { - input := &elb.DetachLoadBalancerFromSubnetsInput{ + input := &elasticloadbalancing.DetachLoadBalancerFromSubnetsInput{ LoadBalancerName: aws.String(d.Id()), Subnets: removed, } - _, err := conn.DetachLoadBalancerFromSubnetsWithContext(ctx, input) + _, err := conn.DetachLoadBalancerFromSubnets(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "detaching ELB Classic Load Balancer (%s) from subnets: %s", d.Id(), err) @@ -705,14 +706,14 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } if len(added) > 0 { - input := &elb.AttachLoadBalancerToSubnetsInput{ + input := &elasticloadbalancing.AttachLoadBalancerToSubnetsInput{ LoadBalancerName: aws.String(d.Id()), Subnets: added, } - _, err := tfresource.RetryWhenAWSErrMessageContains(ctx, d.Timeout(schema.TimeoutUpdate), func() (interface{}, error) { - return conn.AttachLoadBalancerToSubnetsWithContext(ctx, input) - }, elb.ErrCodeInvalidConfigurationRequestException, "cannot be attached to multiple subnets in the same AZ") + _, err := tfresource.RetryWhenIsAErrorMessageContains[*awstypes.InvalidConfigurationRequestException](ctx, d.Timeout(schema.TimeoutUpdate), func() (interface{}, error) { + return conn.AttachLoadBalancerToSubnets(ctx, input) + }, "cannot be attached to multiple subnets in the same AZ") if err != nil { return sdkdiag.AppendErrorf(diags, "attaching ELB Classic Load Balancer (%s) to subnets: %s", d.Id(), err) @@ -725,10 +726,10 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met func resourceLoadBalancerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) log.Printf("[INFO] Deleting ELB Classic Load Balancer: %s", d.Id()) - _, err := conn.DeleteLoadBalancerWithContext(ctx, &elb.DeleteLoadBalancerInput{ + _, err := conn.DeleteLoadBalancer(ctx, &elasticloadbalancing.DeleteLoadBalancerInput{ LoadBalancerName: aws.String(d.Id()), }) @@ -745,14 +746,14 @@ func resourceLoadBalancerDelete(ctx context.Context, d *schema.ResourceData, met return diags } -func FindLoadBalancerByName(ctx context.Context, conn *elb.ELB, name string) (*elb.LoadBalancerDescription, error) { - input := &elb.DescribeLoadBalancersInput{ - LoadBalancerNames: aws.StringSlice([]string{name}), +func FindLoadBalancerByName(ctx context.Context, conn *elasticloadbalancing.Client, name string) (*awstypes.LoadBalancerDescription, error) { + input := &elasticloadbalancing.DescribeLoadBalancersInput{ + LoadBalancerNames: []string{name}, } - output, err := conn.DescribeLoadBalancersWithContext(ctx, input) + output, err := conn.DescribeLoadBalancers(ctx, input) - if tfawserr.ErrCodeEquals(err, elb.ErrCodeAccessPointNotFoundException) { + if errs.IsA[*awstypes.AccessPointNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -763,7 +764,7 @@ func FindLoadBalancerByName(ctx context.Context, conn *elb.ELB, name string) (*e return nil, err } - if output == nil || len(output.LoadBalancerDescriptions) == 0 || output.LoadBalancerDescriptions[0] == nil { + if output == nil || len(output.LoadBalancerDescriptions) == 0 { return nil, tfresource.NewEmptyResultError(input) } @@ -772,23 +773,23 @@ func FindLoadBalancerByName(ctx context.Context, conn *elb.ELB, name string) (*e } // Eventual consistency check. - if aws.StringValue(output.LoadBalancerDescriptions[0].LoadBalancerName) != name { + if aws.ToString(output.LoadBalancerDescriptions[0].LoadBalancerName) != name { return nil, &retry.NotFoundError{ LastRequest: input, } } - return output.LoadBalancerDescriptions[0], nil + return tfresource.AssertSingleValueResult(output.LoadBalancerDescriptions) } -func findLoadBalancerAttributesByName(ctx context.Context, conn *elb.ELB, name string) (*elb.LoadBalancerAttributes, error) { - input := &elb.DescribeLoadBalancerAttributesInput{ +func findLoadBalancerAttributesByName(ctx context.Context, conn *elasticloadbalancing.Client, name string) (*awstypes.LoadBalancerAttributes, error) { + input := &elasticloadbalancing.DescribeLoadBalancerAttributesInput{ LoadBalancerName: aws.String(name), } - output, err := conn.DescribeLoadBalancerAttributesWithContext(ctx, input) + output, err := conn.DescribeLoadBalancerAttributes(ctx, input) - if tfawserr.ErrCodeEquals(err, elb.ErrCodeAccessPointNotFoundException) { + if errs.IsA[*awstypes.AccessPointNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -945,8 +946,8 @@ func deleteNetworkInterfaces(ctx context.Context, conn *ec2.Client, name string) continue } - attachmentID := aws.StringValue(networkInterface.Attachment.AttachmentId) - networkInterfaceID := aws.StringValue(networkInterface.NetworkInterfaceId) + attachmentID := aws.ToString(networkInterface.Attachment.AttachmentId) + networkInterfaceID := aws.ToString(networkInterface.NetworkInterfaceId) if err := tfec2.DetachNetworkInterface(ctx, conn, networkInterfaceID, attachmentID, tfec2.NetworkInterfaceDetachedTimeout); err != nil { errs = append(errs, err) diff --git a/internal/service/elb/load_balancer_data_source.go b/internal/service/elb/load_balancer_data_source.go index 398cdce4cda..9dd4f63ea26 100644 --- a/internal/service/elb/load_balancer_data_source.go +++ b/internal/service/elb/load_balancer_data_source.go @@ -7,9 +7,9 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/elb" + "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/elasticloadbalancing" "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" @@ -208,7 +208,7 @@ func DataSourceLoadBalancer() *schema.Resource { func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) ec2conn := meta.(*conns.AWSClient).EC2Conn(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -219,13 +219,13 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading ELB Classic Load Balancer (%s): %s", lbName, err) } - d.SetId(aws.StringValue(lb.LoadBalancerName)) + d.SetId(aws.ToString(lb.LoadBalancerName)) - input := &elb.DescribeLoadBalancerAttributesInput{ + input := &elasticloadbalancing.DescribeLoadBalancerAttributesInput{ LoadBalancerName: aws.String(d.Id()), } - output, err := conn.DescribeLoadBalancerAttributesWithContext(ctx, input) + output, err := conn.DescribeLoadBalancerAttributes(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "reading ELB Classic Load Balancer (%s) attributes: %s", d.Id(), err) @@ -247,25 +247,25 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met var scheme bool if lb.Scheme != nil { - scheme = aws.StringValue(lb.Scheme) == "internal" + scheme = aws.ToString(lb.Scheme) == "internal" } d.Set("internal", scheme) - d.Set(names.AttrAvailabilityZones, flex.FlattenStringList(lb.AvailabilityZones)) + d.Set(names.AttrAvailabilityZones, flex.FlattenStringValueList(lb.AvailabilityZones)) d.Set("instances", flattenInstances(lb.Instances)) d.Set("listener", flattenListeners(lb.ListenerDescriptions)) - d.Set(names.AttrSecurityGroups, flex.FlattenStringList(lb.SecurityGroups)) + d.Set(names.AttrSecurityGroups, flex.FlattenStringValueList(lb.SecurityGroups)) if lb.SourceSecurityGroup != nil { group := lb.SourceSecurityGroup.GroupName - if lb.SourceSecurityGroup.OwnerAlias != nil && aws.StringValue(lb.SourceSecurityGroup.OwnerAlias) != "" { - group = aws.String(aws.StringValue(lb.SourceSecurityGroup.OwnerAlias) + "/" + aws.StringValue(lb.SourceSecurityGroup.GroupName)) + if lb.SourceSecurityGroup.OwnerAlias != nil && aws.ToString(lb.SourceSecurityGroup.OwnerAlias) != "" { + group = aws.String(aws.ToString(lb.SourceSecurityGroup.OwnerAlias) + "/" + aws.ToString(lb.SourceSecurityGroup.GroupName)) } d.Set("source_security_group", group) // Manually look up the ELB Security Group ID, since it's not provided var elbVpc string if lb.VPCId != nil { - elbVpc = aws.StringValue(lb.VPCId) - sg, err := tfec2.FindSecurityGroupByNameAndVPCIDAndOwnerID(ctx, ec2conn, aws.StringValue(lb.SourceSecurityGroup.GroupName), elbVpc, aws.StringValue(lb.SourceSecurityGroup.OwnerAlias)) + elbVpc = aws.ToString(lb.VPCId) + sg, err := tfec2.FindSecurityGroupByNameAndVPCIDAndOwnerID(ctx, ec2conn, aws.ToString(lb.SourceSecurityGroup.GroupName), elbVpc, aws.ToString(lb.SourceSecurityGroup.OwnerAlias)) if err != nil { return sdkdiag.AppendErrorf(diags, "looking up ELB Security Group ID: %s", err) } else { @@ -273,7 +273,7 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met } } } - d.Set(names.AttrSubnets, flex.FlattenStringList(lb.Subnets)) + d.Set(names.AttrSubnets, flex.FlattenStringValueList(lb.Subnets)) if lbAttrs.ConnectionSettings != nil { d.Set("idle_timeout", lbAttrs.ConnectionSettings.IdleTimeout) } @@ -297,7 +297,7 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met _, n := d.GetChange("access_logs") elbal := lbAttrs.AccessLog nl := n.([]interface{}) - if len(nl) == 0 && !aws.BoolValue(elbal.Enabled) { + if len(nl) == 0 && !elbal.Enabled { elbal = nil } if err := d.Set("access_logs", flattenAccessLog(elbal)); err != nil { @@ -306,8 +306,8 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met } for _, attr := range lbAttrs.AdditionalAttributes { - switch aws.StringValue(attr.Key) { - case "elb.http.desyncmitigationmode": + switch aws.ToString(attr.Key) { + case "elasticloadbalancing.http.desyncmitigationmode": d.Set("desync_mitigation_mode", attr.Value) } } @@ -324,7 +324,7 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met // There's only one health check, so save that to state as we // currently can - if aws.StringValue(lb.HealthCheck.Target) != "" { + if aws.ToString(lb.HealthCheck.Target) != "" { d.Set(names.AttrHealthCheck, FlattenHealthCheck(lb.HealthCheck)) } diff --git a/internal/service/elb/load_balancer_test.go b/internal/service/elb/load_balancer_test.go index 6ccd0303d07..fceb7f22253 100644 --- a/internal/service/elb/load_balancer_test.go +++ b/internal/service/elb/load_balancer_test.go @@ -11,8 +11,9 @@ import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" @@ -242,9 +243,9 @@ func TestValidLoadBalancerHealthCheckTarget(t *testing.T) { func TestAccELBLoadBalancer_basic(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription + var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -296,9 +297,9 @@ func TestAccELBLoadBalancer_basic(t *testing.T) { func TestAccELBLoadBalancer_disappears(t *testing.T) { ctx := acctest.Context(t) - var loadBalancer elb.LoadBalancerDescription + var loadBalancer awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -320,8 +321,8 @@ func TestAccELBLoadBalancer_disappears(t *testing.T) { func TestAccELBLoadBalancer_nameGenerated(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription - resourceName := "aws_elb.test" + var conf awstypes.LoadBalancerDescription + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -348,8 +349,8 @@ func TestAccELBLoadBalancer_nameGenerated(t *testing.T) { func TestAccELBLoadBalancer_namePrefix(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription - resourceName := "aws_elb.test" + var conf awstypes.LoadBalancerDescription + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -376,9 +377,9 @@ func TestAccELBLoadBalancer_namePrefix(t *testing.T) { func TestAccELBLoadBalancer_tags(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription + var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -425,8 +426,8 @@ func TestAccELBLoadBalancer_tags(t *testing.T) { func TestAccELBLoadBalancer_fullCharacterRange(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription - resourceName := "aws_elb.test" + var conf awstypes.LoadBalancerDescription + resourceName := "aws_elasticloadbalancing.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -448,8 +449,8 @@ func TestAccELBLoadBalancer_fullCharacterRange(t *testing.T) { func TestAccELBLoadBalancer_AccessLogs_enabled(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription - resourceName := "aws_elb.test" + var conf awstypes.LoadBalancerDescription + resourceName := "aws_elasticloadbalancing.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -489,8 +490,8 @@ func TestAccELBLoadBalancer_AccessLogs_enabled(t *testing.T) { func TestAccELBLoadBalancer_AccessLogs_disabled(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription - resourceName := "aws_elb.test" + var conf awstypes.LoadBalancerDescription + resourceName := "aws_elasticloadbalancing.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -528,9 +529,9 @@ func TestAccELBLoadBalancer_AccessLogs_disabled(t *testing.T) { func TestAccELBLoadBalancer_generatesNameForZeroValue(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription + var conf awstypes.LoadBalancerDescription generatedNameRegexp := regexache.MustCompile("^tf-lb-") - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -551,9 +552,9 @@ func TestAccELBLoadBalancer_generatesNameForZeroValue(t *testing.T) { func TestAccELBLoadBalancer_availabilityZones(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription + var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -582,11 +583,11 @@ func TestAccELBLoadBalancer_availabilityZones(t *testing.T) { func TestAccELBLoadBalancer_ListenerSSLCertificateID_iamServerCertificate(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription + var conf awstypes.LoadBalancerDescription key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" testCheck := func(*terraform.State) error { if len(conf.ListenerDescriptions) != 1 { @@ -624,9 +625,9 @@ func TestAccELBLoadBalancer_ListenerSSLCertificateID_iamServerCertificate(t *tes func TestAccELBLoadBalancer_Swap_subnets(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription + var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -644,15 +645,15 @@ func TestAccELBLoadBalancer_Swap_subnets(t *testing.T) { { Config: testAccLoadBalancerConfig_subnetSwap(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, "aws_elb.test", &conf), - resource.TestCheckResourceAttr("aws_elb.test", "subnets.#", acctest.Ct2), + testAccCheckLoadBalancerExists(ctx, "aws_elasticloadbalancing.test", &conf), + resource.TestCheckResourceAttr("aws_elasticloadbalancing.test", "subnets.#", acctest.Ct2), ), }, { Config: testAccLoadBalancerConfig_subnetCompleteSwap(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, "aws_elb.test", &conf), - resource.TestCheckResourceAttr("aws_elb.test", "subnets.#", acctest.Ct2), + testAccCheckLoadBalancerExists(ctx, "aws_elasticloadbalancing.test", &conf), + resource.TestCheckResourceAttr("aws_elasticloadbalancing.test", "subnets.#", acctest.Ct2), ), }, }, @@ -661,9 +662,9 @@ func TestAccELBLoadBalancer_Swap_subnets(t *testing.T) { func TestAccELBLoadBalancer_instanceAttaching(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription + var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" testCheckInstanceAttached := func(count int) resource.TestCheckFunc { return func(*terraform.State) error { @@ -701,9 +702,9 @@ func TestAccELBLoadBalancer_instanceAttaching(t *testing.T) { func TestAccELBLoadBalancer_listener(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription + var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -772,12 +773,12 @@ func TestAccELBLoadBalancer_listener(t *testing.T) { { PreConfig: func() { // Simulate out of band listener removal - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) - input := &elb.DeleteLoadBalancerListenersInput{ + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) + input := &elasticloadbalancing.DeleteLoadBalancerListenersInput{ LoadBalancerName: conf.LoadBalancerName, - LoadBalancerPorts: []*int64{aws.Int64(80)}, + LoadBalancerPorts: []int32{80}, } - if _, err := conn.DeleteLoadBalancerListenersWithContext(ctx, input); err != nil { + if _, err := conn.DeleteLoadBalancerListeners(ctx, input); err != nil { t.Fatalf("Error deleting listener: %s", err) } }, @@ -796,19 +797,19 @@ func TestAccELBLoadBalancer_listener(t *testing.T) { { PreConfig: func() { // Simulate out of band listener addition - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) - input := &elb.CreateLoadBalancerListenersInput{ + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) + input := &elasticloadbalancing.CreateLoadBalancerListenersInput{ LoadBalancerName: conf.LoadBalancerName, - Listeners: []*elb.Listener{ + Listeners: []awstypes.Listener{ { - InstancePort: aws.Int64(22), + InstancePort: aws.Int32(22), InstanceProtocol: aws.String("tcp"), - LoadBalancerPort: aws.Int64(22), + LoadBalancerPort: int32(22), Protocol: aws.String("tcp"), }, }, } - if _, err := conn.CreateLoadBalancerListenersWithContext(ctx, input); err != nil { + if _, err := conn.CreateLoadBalancerListeners(ctx, input); err != nil { t.Fatalf("Error creating listener: %s", err) } }, @@ -830,9 +831,9 @@ func TestAccELBLoadBalancer_listener(t *testing.T) { func TestAccELBLoadBalancer_healthCheck(t *testing.T) { ctx := acctest.Context(t) - var conf elb.LoadBalancerDescription + var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -861,7 +862,7 @@ func TestAccELBLoadBalancer_healthCheck(t *testing.T) { func TestAccELBLoadBalancer_timeout(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -888,7 +889,7 @@ func TestAccELBLoadBalancer_timeout(t *testing.T) { func TestAccELBLoadBalancer_connectionDraining(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -923,7 +924,7 @@ func TestAccELBLoadBalancer_connectionDraining(t *testing.T) { func TestAccELBLoadBalancer_securityGroups(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -952,7 +953,7 @@ func TestAccELBLoadBalancer_securityGroups(t *testing.T) { func TestAccELBLoadBalancer_desyncMitigationMode(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -978,7 +979,7 @@ func TestAccELBLoadBalancer_desyncMitigationMode(t *testing.T) { func TestAccELBLoadBalancer_desyncMitigationMode_update(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elb.test" + resourceName := "aws_elasticloadbalancing.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -1020,7 +1021,7 @@ func TestAccELBLoadBalancer_desyncMitigationMode_update(t *testing.T) { func testAccCheckLoadBalancerDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_elb" { @@ -1044,7 +1045,7 @@ func testAccCheckLoadBalancerDestroy(ctx context.Context) resource.TestCheckFunc } } -func testAccCheckLoadBalancerExists(ctx context.Context, n string, v *elb.LoadBalancerDescription) resource.TestCheckFunc { +func testAccCheckLoadBalancerExists(ctx context.Context, n string, v *awstypes.LoadBalancerDescription) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -1055,7 +1056,7 @@ func testAccCheckLoadBalancerExists(ctx context.Context, n string, v *elb.LoadBa return fmt.Errorf("No ELB Classic Load Balancer ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) output, err := tfelb.FindLoadBalancerByName(ctx, conn, rs.Primary.ID) @@ -1069,12 +1070,12 @@ func testAccCheckLoadBalancerExists(ctx context.Context, n string, v *elb.LoadBa } } -func testAccCheckLoadBalancerAttributes(conf *elb.LoadBalancerDescription) resource.TestCheckFunc { +func testAccCheckLoadBalancerAttributes(conf *awstypes.LoadBalancerDescription) resource.TestCheckFunc { return func(s *terraform.State) error { - l := elb.Listener{ - InstancePort: aws.Int64(8000), + l := awstypes.Listener{ + InstancePort: aws.Int32(8000), InstanceProtocol: aws.String("HTTP"), - LoadBalancerPort: aws.Int64(80), + LoadBalancerPort: int32(80), Protocol: aws.String("HTTP"), } @@ -1306,7 +1307,7 @@ resource "aws_elb" "test" { # See https://github.com/hashicorp/terraform-provider-aws/issues/2498 output "lb_name" { - value = aws_elb.test.name + value = aws_elasticloadbalancing.test.name } `) From 36c241d60a36eb8ab03e32e59b8f5d36839b66f1 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:23:31 +0100 Subject: [PATCH 10/37] r/load_balancer_policy: Migrate to AWS SDK v2 --- internal/service/elb/policy.go | 87 +++++++++++++++-------------- internal/service/elb/policy_test.go | 38 ++++++------- 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/internal/service/elb/policy.go b/internal/service/elb/policy.go index c7266714b6e..7908f09235d 100644 --- a/internal/service/elb/policy.go +++ b/internal/service/elb/policy.go @@ -9,12 +9,13 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -74,12 +75,12 @@ func ResourcePolicy() *schema.Resource { func resourcePolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName := d.Get("load_balancer_name").(string) policyName := d.Get("policy_name").(string) id := PolicyCreateResourceID(lbName, policyName) - input := &elb.CreateLoadBalancerPolicyInput{ + input := &elasticloadbalancing.CreateLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), PolicyTypeName: aws.String(d.Get("policy_type_name").(string)), @@ -89,7 +90,7 @@ func resourcePolicyCreate(ctx context.Context, d *schema.ResourceData, meta inte input.PolicyAttributes = ExpandPolicyAttributes(v.(*schema.Set).List()) } - _, err := conn.CreateLoadBalancerPolicyWithContext(ctx, input) + _, err := conn.CreateLoadBalancerPolicy(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ELB Classic Load Balancer Policy (%s): %s", id, err) @@ -102,7 +103,7 @@ func resourcePolicyCreate(ctx context.Context, d *schema.ResourceData, meta inte func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, policyName, err := PolicyParseResourceID(d.Id()) @@ -134,7 +135,7 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) reassignments := Reassignment{} lbName, policyName, err := PolicyParseResourceID(d.Id()) @@ -155,12 +156,12 @@ func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta inte } } - request := &elb.DeleteLoadBalancerPolicyInput{ + request := &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), } - if _, err := conn.DeleteLoadBalancerPolicyWithContext(ctx, request); err != nil { + if _, err := conn.DeleteLoadBalancerPolicy(ctx, request); err != nil { return sdkdiag.AppendErrorf(diags, "deleting Load Balancer Policy %s: %s", d.Id(), err) } @@ -170,13 +171,13 @@ func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta inte } for _, listenerAssignment := range reassignments.listenerPolicies { - if _, err := conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, listenerAssignment); err != nil { + if _, err := conn.SetLoadBalancerPoliciesOfListener(ctx, listenerAssignment); err != nil { return sdkdiag.AppendErrorf(diags, "setting LoadBalancerPoliciesOfListener: %s", err) } } for _, backendServerAssignment := range reassignments.backendServerPolicies { - if _, err := conn.SetLoadBalancerPoliciesForBackendServerWithContext(ctx, backendServerAssignment); err != nil { + if _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, backendServerAssignment); err != nil { return sdkdiag.AppendErrorf(diags, "setting LoadBalancerPoliciesForBackendServer: %s", err) } } @@ -186,7 +187,7 @@ func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta inte func resourcePolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) lbName, policyName, err := PolicyParseResourceID(d.Id()) @@ -206,26 +207,26 @@ func resourcePolicyDelete(ctx context.Context, d *schema.ResourceData, meta inte } } - request := &elb.DeleteLoadBalancerPolicyInput{ + request := &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), } - if _, err := conn.DeleteLoadBalancerPolicyWithContext(ctx, request); err != nil { + if _, err := conn.DeleteLoadBalancerPolicy(ctx, request); err != nil { return sdkdiag.AppendErrorf(diags, "deleting ELB Classic Load Balancer Policy (%s): %s", d.Id(), err) } return diags } -func resourcePolicyAssigned(ctx context.Context, policyName, loadBalancerName string, conn *elb.ELB) (bool, error) { - describeElbOpts := &elb.DescribeLoadBalancersInput{ - LoadBalancerNames: []*string{aws.String(loadBalancerName)}, +func resourcePolicyAssigned(ctx context.Context, policyName, loadBalancerName string, conn *elasticloadbalancing.Client) (bool, error) { + describeElbOpts := &elasticloadbalancing.DescribeLoadBalancersInput{ + LoadBalancerNames: []string{loadBalancerName}, } - describeResp, err := conn.DescribeLoadBalancersWithContext(ctx, describeElbOpts) + describeResp, err := conn.DescribeLoadBalancers(ctx, describeElbOpts) - if tfawserr.ErrCodeEquals(err, elb.ErrCodeAccessPointNotFoundException) { + if errs.IsA[*awstypes.AccessPointNotFoundException](err) { return false, nil } @@ -241,7 +242,7 @@ func resourcePolicyAssigned(ctx context.Context, policyName, loadBalancerName st assigned := false for _, backendServer := range lb.BackendServerDescriptions { for _, name := range backendServer.PolicyNames { - if policyName == aws.StringValue(name) { + if policyName == name { assigned = true break } @@ -250,7 +251,7 @@ func resourcePolicyAssigned(ctx context.Context, policyName, loadBalancerName st for _, listener := range lb.ListenerDescriptions { for _, name := range listener.PolicyNames { - if policyName == aws.StringValue(name) { + if policyName == name { assigned = true break } @@ -261,20 +262,20 @@ func resourcePolicyAssigned(ctx context.Context, policyName, loadBalancerName st } type Reassignment struct { - backendServerPolicies []*elb.SetLoadBalancerPoliciesForBackendServerInput - listenerPolicies []*elb.SetLoadBalancerPoliciesOfListenerInput + backendServerPolicies []*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput + listenerPolicies []*elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput } -func resourcePolicyUnassign(ctx context.Context, policyName, loadBalancerName string, conn *elb.ELB) (Reassignment, error) { +func resourcePolicyUnassign(ctx context.Context, policyName, loadBalancerName string, conn *elasticloadbalancing.Client) (Reassignment, error) { reassignments := Reassignment{} - describeElbOpts := &elb.DescribeLoadBalancersInput{ - LoadBalancerNames: []*string{aws.String(loadBalancerName)}, + describeElbOpts := &elasticloadbalancing.DescribeLoadBalancersInput{ + LoadBalancerNames: []string{loadBalancerName}, } - describeResp, err := conn.DescribeLoadBalancersWithContext(ctx, describeElbOpts) + describeResp, err := conn.DescribeLoadBalancers(ctx, describeElbOpts) - if tfawserr.ErrCodeEquals(err, elb.ErrCodeAccessPointNotFoundException) { + if errs.IsA[*awstypes.AccessPointNotFoundException](err) { return reassignments, nil } @@ -289,30 +290,30 @@ func resourcePolicyUnassign(ctx context.Context, policyName, loadBalancerName st lb := describeResp.LoadBalancerDescriptions[0] for _, backendServer := range lb.BackendServerDescriptions { - policies := []*string{} + policies := []string{} for _, name := range backendServer.PolicyNames { - if policyName != aws.StringValue(name) { + if policyName != name { policies = append(policies, name) } } if len(backendServer.PolicyNames) != len(policies) { - setOpts := &elb.SetLoadBalancerPoliciesForBackendServerInput{ + setOpts := &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ LoadBalancerName: aws.String(loadBalancerName), - InstancePort: aws.Int64(*backendServer.InstancePort), + InstancePort: backendServer.InstancePort, PolicyNames: policies, } - reassignOpts := &elb.SetLoadBalancerPoliciesForBackendServerInput{ + reassignOpts := &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ LoadBalancerName: aws.String(loadBalancerName), - InstancePort: aws.Int64(*backendServer.InstancePort), + InstancePort: backendServer.InstancePort, PolicyNames: backendServer.PolicyNames, } reassignments.backendServerPolicies = append(reassignments.backendServerPolicies, reassignOpts) - _, err = conn.SetLoadBalancerPoliciesForBackendServerWithContext(ctx, setOpts) + _, err = conn.SetLoadBalancerPoliciesForBackendServer(ctx, setOpts) if err != nil { return reassignments, fmt.Errorf("Setting Load Balancer Policies for Backend Server: %s", err) } @@ -320,30 +321,30 @@ func resourcePolicyUnassign(ctx context.Context, policyName, loadBalancerName st } for _, listener := range lb.ListenerDescriptions { - policies := []*string{} + policies := []string{} for _, name := range listener.PolicyNames { - if policyName != aws.StringValue(name) { + if policyName != name { policies = append(policies, name) } } if len(listener.PolicyNames) != len(policies) { - setOpts := &elb.SetLoadBalancerPoliciesOfListenerInput{ + setOpts := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(loadBalancerName), - LoadBalancerPort: aws.Int64(*listener.Listener.LoadBalancerPort), + LoadBalancerPort: listener.Listener.LoadBalancerPort, PolicyNames: policies, } - reassignOpts := &elb.SetLoadBalancerPoliciesOfListenerInput{ + reassignOpts := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(loadBalancerName), - LoadBalancerPort: aws.Int64(*listener.Listener.LoadBalancerPort), + LoadBalancerPort: listener.Listener.LoadBalancerPort, PolicyNames: listener.PolicyNames, } reassignments.listenerPolicies = append(reassignments.listenerPolicies, reassignOpts) - _, err = conn.SetLoadBalancerPoliciesOfListenerWithContext(ctx, setOpts) + _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, setOpts) if err != nil { return reassignments, fmt.Errorf("Setting Load Balancer Policies of Listener: %s", err) } diff --git a/internal/service/elb/policy_test.go b/internal/service/elb/policy_test.go index 0e8d3e6eacb..897e84b9a37 100644 --- a/internal/service/elb/policy_test.go +++ b/internal/service/elb/policy_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/elb" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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 TestAccELBPolicy_basic(t *testing.T) { ctx := acctest.Context(t) - var policy elb.PolicyDescription + var policy awstypes.PolicyDescription resourceName := "aws_load_balancer_policy.test-policy" rInt := sdkacctest.RandInt() @@ -44,7 +44,7 @@ func TestAccELBPolicy_basic(t *testing.T) { func TestAccELBPolicy_disappears(t *testing.T) { ctx := acctest.Context(t) - var policy elb.PolicyDescription + var policy awstypes.PolicyDescription resourceName := "aws_load_balancer_policy.test-policy" rInt := sdkacctest.RandInt() @@ -68,7 +68,7 @@ func TestAccELBPolicy_disappears(t *testing.T) { func TestAccELBPolicy_LBCookieStickinessPolicyType_computedAttributesOnly(t *testing.T) { ctx := acctest.Context(t) - var policy elb.PolicyDescription + var policy awstypes.PolicyDescription resourceName := "aws_load_balancer_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) policyTypeName := "LBCookieStickinessPolicyType" @@ -93,7 +93,7 @@ func TestAccELBPolicy_LBCookieStickinessPolicyType_computedAttributesOnly(t *tes func TestAccELBPolicy_SSLNegotiationPolicyType_computedAttributesOnly(t *testing.T) { ctx := acctest.Context(t) - var policy elb.PolicyDescription + var policy awstypes.PolicyDescription resourceName := "aws_load_balancer_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -117,7 +117,7 @@ func TestAccELBPolicy_SSLNegotiationPolicyType_computedAttributesOnly(t *testing func TestAccELBPolicy_SSLNegotiationPolicyType_customPolicy(t *testing.T) { ctx := acctest.Context(t) - var policy elb.PolicyDescription + var policy awstypes.PolicyDescription resourceName := "aws_load_balancer_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -167,7 +167,7 @@ func TestAccELBPolicy_SSLNegotiationPolicyType_customPolicy(t *testing.T) { func TestAccELBPolicy_SSLSecurityPolicy_predefined(t *testing.T) { ctx := acctest.Context(t) - var policy elb.PolicyDescription + var policy awstypes.PolicyDescription resourceName := "aws_load_balancer_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) predefinedSecurityPolicy := "ELBSecurityPolicy-TLS-1-2-2017-01" @@ -209,7 +209,7 @@ func TestAccELBPolicy_SSLSecurityPolicy_predefined(t *testing.T) { func TestAccELBPolicy_updateWhileAssigned(t *testing.T) { ctx := acctest.Context(t) - var policy elb.PolicyDescription + var policy awstypes.PolicyDescription resourceName := "aws_load_balancer_policy.test-policy" rInt := sdkacctest.RandInt() @@ -235,7 +235,7 @@ func TestAccELBPolicy_updateWhileAssigned(t *testing.T) { }) } -func testAccCheckPolicyExists(ctx context.Context, n string, v *elb.PolicyDescription) resource.TestCheckFunc { +func testAccCheckPolicyExists(ctx context.Context, n string, v *awstypes.PolicyDescription) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -252,7 +252,7 @@ func testAccCheckPolicyExists(ctx context.Context, n string, v *elb.PolicyDescri return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) output, err := tfelb.FindLoadBalancerPolicyByTwoPartKey(ctx, conn, lbName, policyName) @@ -268,7 +268,7 @@ func testAccCheckPolicyExists(ctx context.Context, n string, v *elb.PolicyDescri func testAccCheckPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_load_balancer_policy" { @@ -317,7 +317,7 @@ resource "aws_elb" "test-lb" { } resource "aws_load_balancer_policy" "test-policy" { - load_balancer_name = aws_elb.test-lb.name + load_balancer_name = aws_awstypes.test-lb.name policy_name = "test-policy-%[1]d" policy_type_name = "AppCookieStickinessPolicyType" @@ -350,7 +350,7 @@ resource "aws_elb" "test" { } resource "aws_load_balancer_policy" "test" { - load_balancer_name = aws_elb.test.name + load_balancer_name = aws_awstypes.test.name policy_name = %[1]q policy_type_name = %[2]q } @@ -376,7 +376,7 @@ resource "aws_elb" "test" { } resource "aws_load_balancer_policy" "test" { - load_balancer_name = aws_elb.test.name + load_balancer_name = aws_awstypes.test.name policy_name = %[1]q policy_type_name = "SSLNegotiationPolicyType" @@ -412,7 +412,7 @@ resource "aws_elb" "test" { } resource "aws_load_balancer_policy" "test" { - load_balancer_name = aws_elb.test.name + load_balancer_name = aws_awstypes.test.name policy_name = %[1]q policy_type_name = "SSLNegotiationPolicyType" @@ -443,7 +443,7 @@ resource "aws_elb" "test-lb" { } resource "aws_load_balancer_policy" "test-policy" { - load_balancer_name = aws_elb.test-lb.name + load_balancer_name = aws_awstypes.test-lb.name policy_name = "test-policy-%[1]d" policy_type_name = "AppCookieStickinessPolicyType" @@ -454,7 +454,7 @@ resource "aws_load_balancer_policy" "test-policy" { } resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" { - load_balancer_name = aws_elb.test-lb.name + load_balancer_name = aws_awstypes.test-lb.name load_balancer_port = 80 policy_names = [ @@ -483,7 +483,7 @@ resource "aws_elb" "test-lb" { } resource "aws_load_balancer_policy" "test-policy" { - load_balancer_name = aws_elb.test-lb.name + load_balancer_name = aws_awstypes.test-lb.name policy_name = "test-policy-%[1]d" policy_type_name = "AppCookieStickinessPolicyType" @@ -494,7 +494,7 @@ resource "aws_load_balancer_policy" "test-policy" { } resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" { - load_balancer_name = aws_elb.test-lb.name + load_balancer_name = aws_awstypes.test-lb.name load_balancer_port = 80 policy_names = [ From 1aba7d785c8427add5b24024b23d2b7d07a3c76a Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:24:18 +0100 Subject: [PATCH 11/37] r/proxy_protocol_policy: Migrate to AWS SDK v2 --- internal/service/elb/proxy_protocol_policy.go | 90 ++++++++++--------- .../service/elb/proxy_protocol_policy_test.go | 18 ++-- 2 files changed, 56 insertions(+), 52 deletions(-) diff --git a/internal/service/elb/proxy_protocol_policy.go b/internal/service/elb/proxy_protocol_policy.go index 91aab9a4223..84b07e6d236 100644 --- a/internal/service/elb/proxy_protocol_policy.go +++ b/internal/service/elb/proxy_protocol_policy.go @@ -10,12 +10,13 @@ import ( "strconv" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" ) @@ -45,12 +46,12 @@ func ResourceProxyProtocolPolicy() *schema.Resource { func resourceProxyProtocolPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) elbname := aws.String(d.Get("load_balancer").(string)) - input := &elb.CreateLoadBalancerPolicyInput{ + input := &elasticloadbalancing.CreateLoadBalancerPolicyInput{ LoadBalancerName: elbname, - PolicyAttributes: []*elb.PolicyAttribute{ + PolicyAttributes: []awstypes.PolicyAttribute{ { AttributeName: aws.String("ProxyProtocol"), AttributeValue: aws.String("True"), @@ -64,8 +65,8 @@ func resourceProxyProtocolPolicyCreate(ctx context.Context, d *schema.ResourceDa log.Printf("[DEBUG] ELB create a policy %s from policy type %s", *input.PolicyName, *input.PolicyTypeName) - if _, err := conn.CreateLoadBalancerPolicyWithContext(ctx, input); err != nil { - return sdkdiag.AppendErrorf(diags, "creating a policy %s: %s", aws.StringValue(input.PolicyName), err) + if _, err := conn.CreateLoadBalancerPolicy(ctx, input); err != nil { + return sdkdiag.AppendErrorf(diags, "creating a policy %s: %s", aws.ToString(input.PolicyName), err) } d.SetId(fmt.Sprintf("%s:%s", *elbname, *input.PolicyName)) @@ -75,16 +76,16 @@ func resourceProxyProtocolPolicyCreate(ctx context.Context, d *schema.ResourceDa func resourceProxyProtocolPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) elbname := d.Get("load_balancer").(string) // Retrieve the current ELB policies for updating the state - req := &elb.DescribeLoadBalancersInput{ - LoadBalancerNames: []*string{aws.String(elbname)}, + req := &elasticloadbalancing.DescribeLoadBalancersInput{ + LoadBalancerNames: []string{elbname}, } - resp, err := conn.DescribeLoadBalancersWithContext(ctx, req) + resp, err := conn.DescribeLoadBalancers(ctx, req) if err != nil { - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, elb.ErrCodeAccessPointNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.AccessPointNotFoundException](err) { log.Printf("[WARN] ELB Classic Proxy Protocol Policy (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -106,14 +107,14 @@ func resourceProxyProtocolPolicyRead(ctx context.Context, d *schema.ResourceData func resourceProxyProtocolPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) elbname := aws.String(d.Get("load_balancer").(string)) // Retrieve the current ELB policies for updating the state - req := &elb.DescribeLoadBalancersInput{ - LoadBalancerNames: []*string{elbname}, + req := &elasticloadbalancing.DescribeLoadBalancersInput{ + LoadBalancerNames: []string{*elbname}, } - resp, err := conn.DescribeLoadBalancersWithContext(ctx, req) + resp, err := conn.DescribeLoadBalancers(ctx, req) if err != nil { return sdkdiag.AppendErrorf(diags, "retrieving ELB attributes: %s", err) } @@ -128,7 +129,7 @@ func resourceProxyProtocolPolicyUpdate(ctx context.Context, d *schema.ResourceDa remove := os.Difference(ns).List() add := ns.Difference(os).List() - inputs := []*elb.SetLoadBalancerPoliciesForBackendServerInput{} + inputs := []*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{} i, err := resourceProxyProtocolPolicyRemove(policyName, remove, backends) if err != nil { @@ -144,7 +145,7 @@ func resourceProxyProtocolPolicyUpdate(ctx context.Context, d *schema.ResourceDa for _, input := range inputs { input.LoadBalancerName = elbname - if _, err := conn.SetLoadBalancerPoliciesForBackendServerWithContext(ctx, input); err != nil { + if _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "setting policy for backend: %s", err) } } @@ -155,16 +156,16 @@ func resourceProxyProtocolPolicyUpdate(ctx context.Context, d *schema.ResourceDa func resourceProxyProtocolPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ELBConn(ctx) + conn := meta.(*conns.AWSClient).ELBClient(ctx) elbname := aws.String(d.Get("load_balancer").(string)) // Retrieve the current ELB policies for updating the state - req := &elb.DescribeLoadBalancersInput{ - LoadBalancerNames: []*string{elbname}, + req := &elasticloadbalancing.DescribeLoadBalancersInput{ + LoadBalancerNames: []string{*elbname}, } - resp, err := conn.DescribeLoadBalancersWithContext(ctx, req) + resp, err := conn.DescribeLoadBalancers(ctx, req) if err != nil { - if tfawserr.ErrCodeEquals(err, elb.ErrCodeAccessPointNotFoundException) { + if errs.IsA[*awstypes.AccessPointNotFoundException](err) { return diags } return sdkdiag.AppendErrorf(diags, "retrieving ELB attributes: %s", err) @@ -180,32 +181,33 @@ func resourceProxyProtocolPolicyDelete(ctx context.Context, d *schema.ResourceDa } for _, input := range inputs { input.LoadBalancerName = elbname - if _, err := conn.SetLoadBalancerPoliciesForBackendServerWithContext(ctx, input); err != nil { + if _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "setting policy for backend: %s", err) } } - pOpt := &elb.DeleteLoadBalancerPolicyInput{ + pOpt := &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ LoadBalancerName: elbname, PolicyName: aws.String(policyName), } - if _, err := conn.DeleteLoadBalancerPolicyWithContext(ctx, pOpt); err != nil { + if _, err := conn.DeleteLoadBalancerPolicy(ctx, pOpt); err != nil { return sdkdiag.AppendErrorf(diags, "removing a policy from load balancer: %s", err) } return diags } -func resourceProxyProtocolPolicyRemove(policyName string, ports []interface{}, backends map[int64][]string) ([]*elb.SetLoadBalancerPoliciesForBackendServerInput, error) { - inputs := make([]*elb.SetLoadBalancerPoliciesForBackendServerInput, 0, len(ports)) +func resourceProxyProtocolPolicyRemove(policyName string, ports []interface{}, backends map[int32][]string) ([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, error) { + inputs := make([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, 0, len(ports)) for _, p := range ports { - ip, err := strconv.ParseInt(p.(string), 10, 64) + ip, err := strconv.ParseInt(p.(string), 10, 32) + ip32 := int32(ip) if err != nil { return nil, fmt.Errorf("detaching the policy: %s", err) } - newPolicies := []*string{} - curPolicies, found := backends[ip] + newPolicies := []string{} + curPolicies, found := backends[ip32] if !found { // No policy for this instance port found, just skip it. continue @@ -216,38 +218,40 @@ func resourceProxyProtocolPolicyRemove(policyName string, ports []interface{}, b // remove the policy continue } - newPolicies = append(newPolicies, aws.String(p)) + newPolicies = append(newPolicies, p) } - inputs = append(inputs, &elb.SetLoadBalancerPoliciesForBackendServerInput{ - InstancePort: &ip, + inputs = append(inputs, &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ + InstancePort: &ip32, PolicyNames: newPolicies, }) } return inputs, nil } -func resourceProxyProtocolPolicyAdd(policyName string, ports []interface{}, backends map[int64][]string) ([]*elb.SetLoadBalancerPoliciesForBackendServerInput, error) { - inputs := make([]*elb.SetLoadBalancerPoliciesForBackendServerInput, 0, len(ports)) +func resourceProxyProtocolPolicyAdd(policyName string, ports []interface{}, backends map[int32][]string) ([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, error) { + inputs := make([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, 0, len(ports)) for _, p := range ports { ip, err := strconv.ParseInt(p.(string), 10, 64) + ip32 := int32(ip) + if err != nil { return nil, fmt.Errorf("attaching the policy: %s", err) } - newPolicies := []*string{} - curPolicies := backends[ip] + newPolicies := []string{} + curPolicies := backends[ip32] for _, p := range curPolicies { if p == policyName { // Just remove it for now. It will be back later. continue } - newPolicies = append(newPolicies, aws.String(p)) + newPolicies = append(newPolicies, p) } - newPolicies = append(newPolicies, aws.String(policyName)) + newPolicies = append(newPolicies, policyName) - inputs = append(inputs, &elb.SetLoadBalancerPoliciesForBackendServerInput{ - InstancePort: &ip, + inputs = append(inputs, &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ + InstancePort: &ip32, PolicyNames: newPolicies, }) } diff --git a/internal/service/elb/proxy_protocol_policy_test.go b/internal/service/elb/proxy_protocol_policy_test.go index f996a058df4..74af1f33d41 100644 --- a/internal/service/elb/proxy_protocol_policy_test.go +++ b/internal/service/elb/proxy_protocol_policy_test.go @@ -8,14 +8,14 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -53,21 +53,21 @@ func TestAccELBProxyProtocolPolicy_basic(t *testing.T) { func testAccCheckProxyProtocolPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_placement_group" { continue } - req := &elb.DescribeLoadBalancersInput{ - LoadBalancerNames: []*string{ - aws.String(rs.Primary.Attributes["load_balancer"])}, + req := &elasticloadbalancing.DescribeLoadBalancersInput{ + LoadBalancerNames: []string{ + rs.Primary.Attributes["load_balancer"]}, } - _, err := conn.DescribeLoadBalancersWithContext(ctx, req) + _, err := conn.DescribeLoadBalancers(ctx, req) if err != nil { // Verify the error is what we want - if tfawserr.ErrCodeEquals(err, elb.ErrCodeAccessPointNotFoundException) { + if errs.IsA[*awstypes.AccessPointNotFoundException](err) { continue } return err From 2821d860967da068fc48606e97fbdb41e270311c Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:24:45 +0100 Subject: [PATCH 12/37] d/elb_service_account: Migrate to AWS SDK v2 --- internal/service/elb/service_account_data_source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/elb/service_account_data_source.go b/internal/service/elb/service_account_data_source.go index 2fcbe067740..85af1838277 100644 --- a/internal/service/elb/service_account_data_source.go +++ b/internal/service/elb/service_account_data_source.go @@ -6,7 +6,7 @@ package elb import ( "context" - "github.com/aws/aws-sdk-go/aws/arn" + "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" From dc55eb30cf83c425dc992adf4337e05844127da5 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:25:08 +0100 Subject: [PATCH 13/37] elb: Last AWS SDK v2 migration bits --- internal/service/elb/flex.go | 78 ++++++++++++++----------------- internal/service/elb/flex_test.go | 32 ++++++------- internal/service/elb/sweep.go | 38 +++++++-------- 3 files changed, 70 insertions(+), 78 deletions(-) diff --git a/internal/service/elb/flex.go b/internal/service/elb/flex.go index c5ebad226ff..2454b10548d 100644 --- a/internal/service/elb/flex.go +++ b/internal/service/elb/flex.go @@ -8,13 +8,13 @@ import ( "sort" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types" "github.com/hashicorp/terraform-provider-aws/names" ) // Flattens an access log into something that flatmap.Flatten() can handle -func flattenAccessLog(l *elb.AccessLog) []map[string]interface{} { +func flattenAccessLog(l *awstypes.AccessLog) []map[string]interface{} { result := make([]map[string]interface{}, 0, 1) if l == nil { @@ -23,20 +23,18 @@ func flattenAccessLog(l *elb.AccessLog) []map[string]interface{} { r := make(map[string]interface{}) if l.S3BucketName != nil { - r[names.AttrBucket] = aws.StringValue(l.S3BucketName) + r[names.AttrBucket] = aws.ToString(l.S3BucketName) } if l.S3BucketPrefix != nil { - r[names.AttrBucketPrefix] = aws.StringValue(l.S3BucketPrefix) + r[names.AttrBucketPrefix] = aws.ToString(l.S3BucketPrefix) } if l.EmitInterval != nil { - r[names.AttrInterval] = aws.Int64Value(l.EmitInterval) + r[names.AttrInterval] = aws.ToInt32(l.EmitInterval) } - if l.Enabled != nil { - r[names.AttrEnabled] = aws.BoolValue(l.Enabled) - } + r[names.AttrEnabled] = l.Enabled result = append(result, r) @@ -44,11 +42,11 @@ func flattenAccessLog(l *elb.AccessLog) []map[string]interface{} { } // Flattens an array of Backend Descriptions into a a map of instance_port to policy names. -func flattenBackendPolicies(backends []*elb.BackendServerDescription) map[int64][]string { - policies := make(map[int64][]string) +func flattenBackendPolicies(backends []awstypes.BackendServerDescription) map[int32][]string { + policies := make(map[int32][]string) for _, i := range backends { for _, p := range i.PolicyNames { - policies[*i.InstancePort] = append(policies[*i.InstancePort], *p) + policies[*i.InstancePort] = append(policies[*i.InstancePort], p) } sort.Strings(policies[*i.InstancePort]) } @@ -57,15 +55,15 @@ func flattenBackendPolicies(backends []*elb.BackendServerDescription) map[int64] // Flattens a health check into something that flatmap.Flatten() // can handle -func FlattenHealthCheck(check *elb.HealthCheck) []map[string]interface{} { +func FlattenHealthCheck(check *awstypes.HealthCheck) []map[string]interface{} { result := make([]map[string]interface{}, 0, 1) chk := make(map[string]interface{}) - chk["unhealthy_threshold"] = aws.Int64Value(check.UnhealthyThreshold) - chk["healthy_threshold"] = aws.Int64Value(check.HealthyThreshold) - chk[names.AttrTarget] = aws.StringValue(check.Target) - chk[names.AttrTimeout] = aws.Int64Value(check.Timeout) - chk[names.AttrInterval] = aws.Int64Value(check.Interval) + chk["unhealthy_threshold"] = aws.ToInt32(check.UnhealthyThreshold) + chk["healthy_threshold"] = aws.ToInt32(check.HealthyThreshold) + chk[names.AttrTarget] = aws.ToString(check.Target) + chk[names.AttrTimeout] = aws.ToInt32(check.Timeout) + chk[names.AttrInterval] = aws.ToInt32(check.Interval) result = append(result, chk) @@ -73,7 +71,7 @@ func FlattenHealthCheck(check *elb.HealthCheck) []map[string]interface{} { } // Flattens an array of Instances into a []string -func flattenInstances(list []*elb.Instance) []string { +func flattenInstances(list []awstypes.Instance) []string { result := make([]string, 0, len(list)) for _, i := range list { result = append(result, *i.InstanceId) @@ -82,30 +80,30 @@ func flattenInstances(list []*elb.Instance) []string { } // Expands an array of String Instance IDs into a []Instances -func ExpandInstanceString(list []interface{}) []*elb.Instance { - result := make([]*elb.Instance, 0, len(list)) +func ExpandInstanceString(list []interface{}) []awstypes.Instance { + result := make([]awstypes.Instance, 0, len(list)) for _, i := range list { - result = append(result, &elb.Instance{InstanceId: aws.String(i.(string))}) + result = append(result, awstypes.Instance{InstanceId: aws.String(i.(string))}) } return result } // Takes the result of flatmap.Expand for an array of listeners and // returns ELB API compatible objects -func ExpandListeners(configured []interface{}) ([]*elb.Listener, error) { - listeners := make([]*elb.Listener, 0, len(configured)) +func ExpandListeners(configured []interface{}) ([]awstypes.Listener, error) { + listeners := make([]awstypes.Listener, 0, len(configured)) // Loop over our configured listeners and create // an array of aws-sdk-go compatible objects for _, lRaw := range configured { data := lRaw.(map[string]interface{}) - ip := int64(data["instance_port"].(int)) - lp := int64(data["lb_port"].(int)) - l := &elb.Listener{ + ip := int32(data["instance_port"].(int)) + lp := int32(data["lb_port"].(int)) + l := awstypes.Listener{ InstancePort: &ip, InstanceProtocol: aws.String(data["instance_protocol"].(string)), - LoadBalancerPort: &lp, + LoadBalancerPort: lp, Protocol: aws.String(data["lb_protocol"].(string)), } @@ -114,7 +112,7 @@ func ExpandListeners(configured []interface{}) ([]*elb.Listener, error) { } var valid bool - if aws.StringValue(l.SSLCertificateId) != "" { + if aws.ToString(l.SSLCertificateId) != "" { // validate the protocol is correct for _, p := range []string{"https", "ssl"} { if (strings.ToLower(*l.InstanceProtocol) == p) || (strings.ToLower(*l.Protocol) == p) { @@ -136,18 +134,18 @@ func ExpandListeners(configured []interface{}) ([]*elb.Listener, error) { } // Flattens an array of Listeners into a []map[string]interface{} -func flattenListeners(list []*elb.ListenerDescription) []map[string]interface{} { +func flattenListeners(list []awstypes.ListenerDescription) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { l := map[string]interface{}{ "instance_port": *i.Listener.InstancePort, "instance_protocol": strings.ToLower(*i.Listener.InstanceProtocol), - "lb_port": *i.Listener.LoadBalancerPort, + "lb_port": i.Listener.LoadBalancerPort, "lb_protocol": strings.ToLower(*i.Listener.Protocol), } // SSLCertificateID is optional, and may be nil if i.Listener.SSLCertificateId != nil { - l["ssl_certificate_id"] = aws.StringValue(i.Listener.SSLCertificateId) + l["ssl_certificate_id"] = aws.ToString(i.Listener.SSLCertificateId) } result = append(result, l) } @@ -156,15 +154,15 @@ func flattenListeners(list []*elb.ListenerDescription) []map[string]interface{} // Takes the result of flatmap.Expand for an array of policy attributes and // returns ELB API compatible objects -func ExpandPolicyAttributes(configured []interface{}) []*elb.PolicyAttribute { - attributes := make([]*elb.PolicyAttribute, 0, len(configured)) +func ExpandPolicyAttributes(configured []interface{}) []awstypes.PolicyAttribute { + attributes := make([]awstypes.PolicyAttribute, 0, len(configured)) // Loop over our configured attributes and create // an array of aws-sdk-go compatible objects for _, lRaw := range configured { data := lRaw.(map[string]interface{}) - a := &elb.PolicyAttribute{ + a := awstypes.PolicyAttribute{ AttributeName: aws.String(data[names.AttrName].(string)), AttributeValue: aws.String(data[names.AttrValue].(string)), } @@ -176,17 +174,13 @@ func ExpandPolicyAttributes(configured []interface{}) []*elb.PolicyAttribute { } // Flattens an array of PolicyAttributes into a []interface{} -func FlattenPolicyAttributes(list []*elb.PolicyAttributeDescription) []interface{} { +func FlattenPolicyAttributes(list []awstypes.PolicyAttributeDescription) []interface{} { var attributes []interface{} for _, attrdef := range list { - if attrdef == nil { - continue - } - attribute := map[string]string{ - names.AttrName: aws.StringValue(attrdef.AttributeName), - names.AttrValue: aws.StringValue(attrdef.AttributeValue), + names.AttrName: aws.ToString(attrdef.AttributeName), + names.AttrValue: aws.ToString(attrdef.AttributeValue), } attributes = append(attributes, attribute) diff --git a/internal/service/elb/flex_test.go b/internal/service/elb/flex_test.go index 192ffbb9649..42c015eafef 100644 --- a/internal/service/elb/flex_test.go +++ b/internal/service/elb/flex_test.go @@ -8,8 +8,8 @@ import ( "strings" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types" "github.com/hashicorp/terraform-provider-aws/internal/acctest" tfelb "github.com/hashicorp/terraform-provider-aws/internal/service/elb" "github.com/hashicorp/terraform-provider-aws/names" @@ -38,9 +38,9 @@ func TestExpandListeners(t *testing.T) { t.Fatalf("bad: %#v", err) } - expected := &elb.Listener{ - InstancePort: aws.Int64(8000), - LoadBalancerPort: aws.Int64(80), + expected := &awstypes.Listener{ + InstancePort: aws.Int32(8000), + LoadBalancerPort: int32(80), InstanceProtocol: aws.String("http"), Protocol: aws.String("http"), } @@ -84,16 +84,16 @@ func TestFlattenHealthCheck(t *testing.T) { t.Parallel() cases := []struct { - Input *elb.HealthCheck + Input *awstypes.HealthCheck Output []map[string]interface{} }{ { - Input: &elb.HealthCheck{ - UnhealthyThreshold: aws.Int64(10), - HealthyThreshold: aws.Int64(10), + Input: &awstypes.HealthCheck{ + UnhealthyThreshold: aws.Int32(10), + HealthyThreshold: aws.Int32(10), Target: aws.String("HTTP:80/"), - Timeout: aws.Int64(30), - Interval: aws.Int64(30), + Timeout: aws.Int32(30), + Interval: aws.Int32(30), }, Output: []map[string]interface{}{ { @@ -118,7 +118,7 @@ func TestFlattenHealthCheck(t *testing.T) { func TestExpandInstanceString(t *testing.T) { t.Parallel() - expected := []*elb.Instance{ + expected := []*awstypes.Instance{ {InstanceId: aws.String("test-one")}, {InstanceId: aws.String("test-two")}, } @@ -158,7 +158,7 @@ func TestExpandPolicyAttributes(t *testing.T) { t.Fatalf("expected number of attributes to be 3, but got %d", len(attributes)) } - expected := &elb.PolicyAttribute{ + expected := &awstypes.PolicyAttribute{ AttributeName: aws.String("Protocol-TLSv1.2"), AttributeValue: aws.String(acctest.CtTrue), } @@ -194,7 +194,7 @@ func TestExpandPolicyAttributes_invalid(t *testing.T) { } attributes := tfelb.ExpandPolicyAttributes(expanded) - expected := &elb.PolicyAttribute{ + expected := &awstypes.PolicyAttribute{ AttributeName: aws.String("Protocol-TLSv1.2"), AttributeValue: aws.String(acctest.CtFalse), } @@ -211,11 +211,11 @@ func TestFlattenPolicyAttributes(t *testing.T) { t.Parallel() cases := []struct { - Input []*elb.PolicyAttributeDescription + Input []awstypes.PolicyAttributeDescription Output []interface{} }{ { - Input: []*elb.PolicyAttributeDescription{ + Input: []awstypes.PolicyAttributeDescription{ { AttributeName: aws.String("Protocol-TLSv1.2"), AttributeValue: aws.String(acctest.CtTrue), diff --git a/internal/service/elb/sweep.go b/internal/service/elb/sweep.go index b36331b761a..d5173390947 100644 --- a/internal/service/elb/sweep.go +++ b/internal/service/elb/sweep.go @@ -7,11 +7,11 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/sweep" - "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv1" + "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2" ) func RegisterSweepers() { @@ -27,33 +27,31 @@ func sweepLoadBalancers(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.ELBConn(ctx) - input := &elb.DescribeLoadBalancersInput{} + conn := client.ELBClient(ctx) + input := &elasticloadbalancing.DescribeLoadBalancersInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeLoadBalancersPagesWithContext(ctx, input, func(page *elb.DescribeLoadBalancersOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := elasticloadbalancing.NewDescribeLoadBalancersPaginator(conn, input) + + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping ELB Classic Load Balancer sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing ELB Classic Load Balancers (%s): %w", region, err) } for _, v := range page.LoadBalancerDescriptions { r := ResourceLoadBalancer() d := r.Data(nil) - d.SetId(aws.StringValue(v.LoadBalancerName)) + d.SetId(aws.ToString(v.LoadBalancerName)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping ELB Classic Load Balancer sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing ELB Classic Load Balancers (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) From 79ba7ba37caf0894e8be3471f4dc7f36878912bc Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:25:51 +0100 Subject: [PATCH 14/37] r/autoscaling_group: Migrate to AWS SDK v2 (elb) --- internal/service/autoscaling/group.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/service/autoscaling/group.go b/internal/service/autoscaling/group.go index 11c76a19cd4..f1a8f203fe2 100644 --- a/internal/service/autoscaling/group.go +++ b/internal/service/autoscaling/group.go @@ -16,7 +16,7 @@ import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/autoscaling" awstypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types" - "github.com/aws/aws-sdk-go/service/elb" + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" "github.com/aws/aws-sdk-go/service/elbv2" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/go-cty/cty" @@ -1211,7 +1211,7 @@ func resourceGroupCreate(ctx context.Context, d *schema.ResourceData, meta inter return nil } - if err := waitGroupCapacitySatisfied(ctx, conn, meta.(*conns.AWSClient).ELBConn(ctx), meta.(*conns.AWSClient).ELBV2Conn(ctx), d.Id(), f, startTime, d.Get("ignore_failed_scaling_activities").(bool), timeout); err != nil { + if err := waitGroupCapacitySatisfied(ctx, conn, meta.(*conns.AWSClient).ELBClient(ctx), meta.(*conns.AWSClient).ELBV2Conn(ctx), d.Id(), f, startTime, d.Get("ignore_failed_scaling_activities").(bool), timeout); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Auto Scaling Group (%s) capacity satisfied: %s", d.Id(), err) } } @@ -1708,7 +1708,7 @@ func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, meta inter return nil } - if err := waitGroupCapacitySatisfied(ctx, conn, meta.(*conns.AWSClient).ELBConn(ctx), meta.(*conns.AWSClient).ELBV2Conn(ctx), d.Id(), f, startTime, d.Get("ignore_failed_scaling_activities").(bool), timeout); err != nil { + if err := waitGroupCapacitySatisfied(ctx, conn, meta.(*conns.AWSClient).ELBClient(ctx), meta.(*conns.AWSClient).ELBV2Conn(ctx), d.Id(), f, startTime, d.Get("ignore_failed_scaling_activities").(bool), timeout); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Auto Scaling Group (%s) capacity satisfied: %s", d.Id(), err) } } @@ -1965,16 +1965,16 @@ func drainWarmPool(ctx context.Context, conn *autoscaling.Client, name string, t return nil } -func findELBInstanceStates(ctx context.Context, conn *elb.ELB, g *awstypes.AutoScalingGroup) (map[string]map[string]string, error) { +func findELBInstanceStates(ctx context.Context, conn *elasticloadbalancing.Client, g *awstypes.AutoScalingGroup) (map[string]map[string]string, error) { instanceStates := make(map[string]map[string]string) for _, v := range g.LoadBalancerNames { lbName := v - input := &elb.DescribeInstanceHealthInput{ + input := &elasticloadbalancing.DescribeInstanceHealthInput{ LoadBalancerName: aws.String(lbName), } - output, err := conn.DescribeInstanceHealthWithContext(ctx, input) + output, err := conn.DescribeInstanceHealth(ctx, input) if err != nil { return nil, fmt.Errorf("reading load balancer (%s) instance health: %w", lbName, err) @@ -2284,7 +2284,7 @@ func findWarmPoolByName(ctx context.Context, conn *autoscaling.Client, name stri return findWarmPool(ctx, conn, input) } -func statusGroupCapacity(ctx context.Context, conn *autoscaling.Client, elbconn *elb.ELB, elbv2conn *elbv2.ELBV2, name string, cb func(int, int) error, startTime time.Time, ignoreFailedScalingActivities bool) retry.StateRefreshFunc { +func statusGroupCapacity(ctx context.Context, conn *autoscaling.Client, elbconn *elasticloadbalancing.Client, elbv2conn *elbv2.ELBV2, name string, cb func(int, int) error, startTime time.Time, ignoreFailedScalingActivities bool) retry.StateRefreshFunc { return func() (interface{}, string, error) { if !ignoreFailedScalingActivities { // Check for fatal error in activity logs. @@ -2539,7 +2539,7 @@ func statusWarmPoolInstanceCount(ctx context.Context, conn *autoscaling.Client, } } -func waitGroupCapacitySatisfied(ctx context.Context, conn *autoscaling.Client, elbconn *elb.ELB, elbv2conn *elbv2.ELBV2, name string, cb func(int, int) error, startTime time.Time, ignoreFailedScalingActivities bool, timeout time.Duration) error { +func waitGroupCapacitySatisfied(ctx context.Context, conn *autoscaling.Client, elbconn *elasticloadbalancing.Client, elbv2conn *elbv2.ELBV2, name string, cb func(int, int) error, startTime time.Time, ignoreFailedScalingActivities bool, timeout time.Duration) error { stateConf := &retry.StateChangeConf{ Target: []string{"ok"}, Refresh: statusGroupCapacity(ctx, conn, elbconn, elbv2conn, name, cb, startTime, ignoreFailedScalingActivities), From 77579f24936d4bad561c0e423bda8c2f4376d43d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 11:23:20 -0400 Subject: [PATCH 15/37] elb: Tidy up 'flex'. --- internal/service/elb/flex.go | 220 +++++++++--------- .../service/elb/lb_ssl_negotiation_policy.go | 2 +- internal/service/elb/load_balancer.go | 14 +- .../service/elb/load_balancer_data_source.go | 4 +- internal/service/elb/policy.go | 4 +- 5 files changed, 122 insertions(+), 122 deletions(-) diff --git a/internal/service/elb/flex.go b/internal/service/elb/flex.go index 2454b10548d..8ebcbd5facb 100644 --- a/internal/service/elb/flex.go +++ b/internal/service/elb/flex.go @@ -10,112 +10,112 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/names" ) -// Flattens an access log into something that flatmap.Flatten() can handle -func flattenAccessLog(l *awstypes.AccessLog) []map[string]interface{} { - result := make([]map[string]interface{}, 0, 1) - - if l == nil { +func flattenAccessLog(apiObject *awstypes.AccessLog) []interface{} { + if apiObject == nil { return nil } - r := make(map[string]interface{}) - if l.S3BucketName != nil { - r[names.AttrBucket] = aws.ToString(l.S3BucketName) + tfList := make([]interface{}, 0, 1) + tfMap := make(map[string]interface{}) + + if apiObject.S3BucketName != nil { + tfMap[names.AttrBucket] = aws.ToString(apiObject.S3BucketName) } - if l.S3BucketPrefix != nil { - r[names.AttrBucketPrefix] = aws.ToString(l.S3BucketPrefix) + if apiObject.S3BucketPrefix != nil { + tfMap[names.AttrBucketPrefix] = aws.ToString(apiObject.S3BucketPrefix) } - if l.EmitInterval != nil { - r[names.AttrInterval] = aws.ToInt32(l.EmitInterval) + if apiObject.EmitInterval != nil { + tfMap[names.AttrInterval] = aws.ToInt32(apiObject.EmitInterval) } - r[names.AttrEnabled] = l.Enabled + tfMap[names.AttrEnabled] = apiObject.Enabled - result = append(result, r) + tfList = append(tfList, tfMap) - return result + return tfList } -// Flattens an array of Backend Descriptions into a a map of instance_port to policy names. -func flattenBackendPolicies(backends []awstypes.BackendServerDescription) map[int32][]string { - policies := make(map[int32][]string) - for _, i := range backends { - for _, p := range i.PolicyNames { - policies[*i.InstancePort] = append(policies[*i.InstancePort], p) +func flattenBackendPolicies(apiObjects []awstypes.BackendServerDescription) map[int32][]string { + tfMap := make(map[int32][]string) + + for _, apiObject := range apiObjects { + k := aws.ToInt32(apiObject.InstancePort) + + for _, v := range apiObject.PolicyNames { + tfMap[k] = append(tfMap[k], v) } - sort.Strings(policies[*i.InstancePort]) + + sort.Strings(tfMap[k]) } - return policies + + return tfMap } -// Flattens a health check into something that flatmap.Flatten() -// can handle -func FlattenHealthCheck(check *awstypes.HealthCheck) []map[string]interface{} { - result := make([]map[string]interface{}, 0, 1) +func flattenHealthCheck(apiObject *awstypes.HealthCheck) []interface{} { + if apiObject == nil { + return nil + } + + tfList := make([]interface{}, 0, 1) + tfMap := make(map[string]interface{}) - chk := make(map[string]interface{}) - chk["unhealthy_threshold"] = aws.ToInt32(check.UnhealthyThreshold) - chk["healthy_threshold"] = aws.ToInt32(check.HealthyThreshold) - chk[names.AttrTarget] = aws.ToString(check.Target) - chk[names.AttrTimeout] = aws.ToInt32(check.Timeout) - chk[names.AttrInterval] = aws.ToInt32(check.Interval) + tfMap["unhealthy_threshold"] = aws.ToInt32(apiObject.UnhealthyThreshold) + tfMap["healthy_threshold"] = aws.ToInt32(apiObject.HealthyThreshold) + tfMap[names.AttrTarget] = aws.ToString(apiObject.Target) + tfMap[names.AttrTimeout] = aws.ToInt32(apiObject.Timeout) + tfMap[names.AttrInterval] = aws.ToInt32(apiObject.Interval) - result = append(result, chk) + tfList = append(tfList, tfMap) - return result + return tfList } -// Flattens an array of Instances into a []string -func flattenInstances(list []awstypes.Instance) []string { - result := make([]string, 0, len(list)) - for _, i := range list { - result = append(result, *i.InstanceId) - } - return result +func flattenInstances(apiObjects []awstypes.Instance) []string { + return tfslices.ApplyToAll(apiObjects, func(v awstypes.Instance) string { + return aws.ToString(v.InstanceId) + }) } -// Expands an array of String Instance IDs into a []Instances -func ExpandInstanceString(list []interface{}) []awstypes.Instance { - result := make([]awstypes.Instance, 0, len(list)) - for _, i := range list { - result = append(result, awstypes.Instance{InstanceId: aws.String(i.(string))}) - } - return result +func expandInstances(tfList []interface{}) []awstypes.Instance { + return tfslices.ApplyToAll(tfList, func(v interface{}) awstypes.Instance { + return awstypes.Instance{ + InstanceId: aws.String(v.(string)), + } + }) } -// Takes the result of flatmap.Expand for an array of listeners and -// returns ELB API compatible objects -func ExpandListeners(configured []interface{}) ([]awstypes.Listener, error) { - listeners := make([]awstypes.Listener, 0, len(configured)) - - // Loop over our configured listeners and create - // an array of aws-sdk-go compatible objects - for _, lRaw := range configured { - data := lRaw.(map[string]interface{}) - - ip := int32(data["instance_port"].(int)) - lp := int32(data["lb_port"].(int)) - l := awstypes.Listener{ - InstancePort: &ip, - InstanceProtocol: aws.String(data["instance_protocol"].(string)), - LoadBalancerPort: lp, - Protocol: aws.String(data["lb_protocol"].(string)), +func expandListeners(tfList []interface{}) ([]awstypes.Listener, error) { + apiObjects := make([]awstypes.Listener, 0) + + for _, tfMapRaw := range tfList { + tfMap, ok := tfMapRaw.(map[string]interface{}) + if !ok { + continue + } + + apiObject := awstypes.Listener{ + InstancePort: aws.Int32(int32(tfMap["instance_port"].(int))), + InstanceProtocol: aws.String(tfMap["instance_protocol"].(string)), + LoadBalancerPort: int32(tfMap["lb_port"].(int)), + Protocol: aws.String(tfMap["lb_protocol"].(string)), } - if v, ok := data["ssl_certificate_id"]; ok { - l.SSLCertificateId = aws.String(v.(string)) + if v, ok := tfMap["ssl_certificate_id"]; ok { + apiObject.SSLCertificateId = aws.String(v.(string)) } var valid bool - if aws.ToString(l.SSLCertificateId) != "" { + + if aws.ToString(apiObject.SSLCertificateId) != "" { // validate the protocol is correct for _, p := range []string{"https", "ssl"} { - if (strings.ToLower(*l.InstanceProtocol) == p) || (strings.ToLower(*l.Protocol) == p) { + if (strings.ToLower(aws.ToString(apiObject.InstanceProtocol)) == p) || (strings.ToLower(aws.ToString(apiObject.Protocol)) == p) { valid = true } } @@ -123,68 +123,68 @@ func ExpandListeners(configured []interface{}) ([]awstypes.Listener, error) { valid = true } - if valid { - listeners = append(listeners, l) - } else { + if !valid { return nil, errors.New(`"ssl_certificate_id" may be set only when "protocol" is "https" or "ssl"`) } + + apiObjects = append(apiObjects, apiObject) } - return listeners, nil + return apiObjects, nil } -// Flattens an array of Listeners into a []map[string]interface{} -func flattenListeners(list []awstypes.ListenerDescription) []map[string]interface{} { - result := make([]map[string]interface{}, 0, len(list)) - for _, i := range list { - l := map[string]interface{}{ - "instance_port": *i.Listener.InstancePort, - "instance_protocol": strings.ToLower(*i.Listener.InstanceProtocol), - "lb_port": i.Listener.LoadBalancerPort, - "lb_protocol": strings.ToLower(*i.Listener.Protocol), +func flattenListenerDescriptions(apiObjects []awstypes.ListenerDescription) []interface{} { + tfList := make([]interface{}, 0, len(apiObjects)) + + for _, apiObject := range apiObjects { + tfMap := map[string]interface{}{ + "instance_port": aws.ToInt32(apiObject.Listener.InstancePort), + "instance_protocol": strings.ToLower(aws.ToString(apiObject.Listener.InstanceProtocol)), + "lb_port": apiObject.Listener.LoadBalancerPort, + "lb_protocol": strings.ToLower(*apiObject.Listener.Protocol), } - // SSLCertificateID is optional, and may be nil - if i.Listener.SSLCertificateId != nil { - l["ssl_certificate_id"] = aws.ToString(i.Listener.SSLCertificateId) + + if apiObject.Listener.SSLCertificateId != nil { + tfMap["ssl_certificate_id"] = aws.ToString(apiObject.Listener.SSLCertificateId) } - result = append(result, l) + + tfList = append(tfList, tfMap) } - return result + + return tfList } -// Takes the result of flatmap.Expand for an array of policy attributes and -// returns ELB API compatible objects -func ExpandPolicyAttributes(configured []interface{}) []awstypes.PolicyAttribute { - attributes := make([]awstypes.PolicyAttribute, 0, len(configured)) +func expandPolicyAttributes(tfList []interface{}) []awstypes.PolicyAttribute { + apiObjects := make([]awstypes.PolicyAttribute, 0) - // Loop over our configured attributes and create - // an array of aws-sdk-go compatible objects - for _, lRaw := range configured { - data := lRaw.(map[string]interface{}) + for _, tfMapRaw := range tfList { + tfMap, ok := tfMapRaw.(map[string]interface{}) + if !ok { + continue + } - a := awstypes.PolicyAttribute{ - AttributeName: aws.String(data[names.AttrName].(string)), - AttributeValue: aws.String(data[names.AttrValue].(string)), + apiObject := awstypes.PolicyAttribute{ + AttributeName: aws.String(tfMap[names.AttrName].(string)), + AttributeValue: aws.String(tfMap[names.AttrValue].(string)), } - attributes = append(attributes, a) + apiObjects = append(apiObjects, apiObject) } - return attributes + return apiObjects } -// Flattens an array of PolicyAttributes into a []interface{} -func FlattenPolicyAttributes(list []awstypes.PolicyAttributeDescription) []interface{} { - var attributes []interface{} +func flattenPolicyAttributeDescriptions(apiObjects []awstypes.PolicyAttributeDescription) []interface{} { + var tfList []interface{} - for _, attrdef := range list { - attribute := map[string]string{ - names.AttrName: aws.ToString(attrdef.AttributeName), - names.AttrValue: aws.ToString(attrdef.AttributeValue), + for _, apiObject := range apiObjects { + tfMap := map[string]string{ + names.AttrName: aws.ToString(apiObject.AttributeName), + names.AttrValue: aws.ToString(apiObject.AttributeValue), } - attributes = append(attributes, attribute) + tfList = append(tfList, tfMap) } - return attributes + return tfList } diff --git a/internal/service/elb/lb_ssl_negotiation_policy.go b/internal/service/elb/lb_ssl_negotiation_policy.go index 49f48e5caf9..d7c059b064f 100644 --- a/internal/service/elb/lb_ssl_negotiation_policy.go +++ b/internal/service/elb/lb_ssl_negotiation_policy.go @@ -87,7 +87,7 @@ func resourceSSLNegotiationPolicyCreate(ctx context.Context, d *schema.ResourceD } if v, ok := d.GetOk("attribute"); ok && v.(*schema.Set).Len() > 0 { - input.PolicyAttributes = ExpandPolicyAttributes(v.(*schema.Set).List()) + input.PolicyAttributes = expandPolicyAttributes(v.(*schema.Set).List()) } _, err := conn.CreateLoadBalancerPolicy(ctx, input) diff --git a/internal/service/elb/load_balancer.go b/internal/service/elb/load_balancer.go index 9baa893527d..1271cd63724 100644 --- a/internal/service/elb/load_balancer.go +++ b/internal/service/elb/load_balancer.go @@ -273,7 +273,7 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, met var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - listeners, err := ExpandListeners(d.Get("listener").(*schema.Set).List()) + listeners, err := expandListeners(d.Get("listener").(*schema.Set).List()) if err != nil { return sdkdiag.AppendFromErr(diags, err) } @@ -362,7 +362,7 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta scheme = aws.ToString(lb.Scheme) == "internal" } d.Set("internal", scheme) - d.Set("listener", flattenListeners(lb.ListenerDescriptions)) + d.Set("listener", flattenListenerDescriptions(lb.ListenerDescriptions)) d.Set(names.AttrName, lb.LoadBalancerName) d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(lb.LoadBalancerName))) d.Set(names.AttrSecurityGroups, flex.FlattenStringValueList(lb.SecurityGroups)) @@ -422,7 +422,7 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta // There's only one health check, so save that to state as we // currently can if aws.ToString(lb.HealthCheck.Target) != "" { - if err := d.Set(names.AttrHealthCheck, FlattenHealthCheck(lb.HealthCheck)); err != nil { + if err := d.Set(names.AttrHealthCheck, flattenHealthCheck(lb.HealthCheck)); err != nil { return sdkdiag.AppendErrorf(diags, "setting health_check: %s", err) } } @@ -439,8 +439,8 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met os := o.(*schema.Set) ns := n.(*schema.Set) - remove, _ := ExpandListeners(os.Difference(ns).List()) - add, err := ExpandListeners(ns.Difference(os).List()) + remove, _ := expandListeners(os.Difference(ns).List()) + add, err := expandListeners(ns.Difference(os).List()) if err != nil { return sdkdiag.AppendFromErr(diags, err) @@ -500,8 +500,8 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met o, n := d.GetChange("instances") os := o.(*schema.Set) ns := n.(*schema.Set) - remove := ExpandInstanceString(os.Difference(ns).List()) - add := ExpandInstanceString(ns.Difference(os).List()) + remove := expandInstances(os.Difference(ns).List()) + add := expandInstances(ns.Difference(os).List()) if len(add) > 0 { input := &elasticloadbalancing.RegisterInstancesWithLoadBalancerInput{ diff --git a/internal/service/elb/load_balancer_data_source.go b/internal/service/elb/load_balancer_data_source.go index 9dd4f63ea26..4a57ce7b45e 100644 --- a/internal/service/elb/load_balancer_data_source.go +++ b/internal/service/elb/load_balancer_data_source.go @@ -252,7 +252,7 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met d.Set("internal", scheme) d.Set(names.AttrAvailabilityZones, flex.FlattenStringValueList(lb.AvailabilityZones)) d.Set("instances", flattenInstances(lb.Instances)) - d.Set("listener", flattenListeners(lb.ListenerDescriptions)) + d.Set("listener", flattenListenerDescriptions(lb.ListenerDescriptions)) d.Set(names.AttrSecurityGroups, flex.FlattenStringValueList(lb.SecurityGroups)) if lb.SourceSecurityGroup != nil { group := lb.SourceSecurityGroup.GroupName @@ -325,7 +325,7 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met // There's only one health check, so save that to state as we // currently can if aws.ToString(lb.HealthCheck.Target) != "" { - d.Set(names.AttrHealthCheck, FlattenHealthCheck(lb.HealthCheck)) + d.Set(names.AttrHealthCheck, flattenHealthCheck(lb.HealthCheck)) } return diags diff --git a/internal/service/elb/policy.go b/internal/service/elb/policy.go index 7908f09235d..417e9cfa5c5 100644 --- a/internal/service/elb/policy.go +++ b/internal/service/elb/policy.go @@ -87,7 +87,7 @@ func resourcePolicyCreate(ctx context.Context, d *schema.ResourceData, meta inte } if v, ok := d.GetOk("policy_attribute"); ok && v.(*schema.Set).Len() > 0 { - input.PolicyAttributes = ExpandPolicyAttributes(v.(*schema.Set).List()) + input.PolicyAttributes = expandPolicyAttributes(v.(*schema.Set).List()) } _, err := conn.CreateLoadBalancerPolicy(ctx, input) @@ -124,7 +124,7 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf } d.Set("load_balancer_name", lbName) - if err := d.Set("policy_attribute", FlattenPolicyAttributes(policy.PolicyAttributeDescriptions)); err != nil { + if err := d.Set("policy_attribute", flattenPolicyAttributeDescriptions(policy.PolicyAttributeDescriptions)); err != nil { return sdkdiag.AppendErrorf(diags, "setting policy_attribute: %s", err) } d.Set("policy_name", policyName) From 81796ca08fd04abe4ce8d338cbdfbe4765e87603 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 11:37:54 -0400 Subject: [PATCH 16/37] r/aws_app_cookie_stickiness_policy: Reduce visibility. --- .../elb/app_cookie_stickiness_policy.go | 45 ++++++++++--------- internal/service/elb/backend_server_policy.go | 2 +- internal/service/elb/exports_test.go | 14 ++++++ .../elb/lb_cookie_stickiness_policy.go | 2 +- .../service/elb/lb_ssl_negotiation_policy.go | 2 +- internal/service/elb/listener_policy.go | 2 +- internal/service/elb/load_balancer.go | 19 +------- .../service/elb/load_balancer_data_source.go | 2 +- internal/service/elb/policy.go | 2 +- internal/service/elb/service_package_gen.go | 3 +- 10 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 internal/service/elb/exports_test.go diff --git a/internal/service/elb/app_cookie_stickiness_policy.go b/internal/service/elb/app_cookie_stickiness_policy.go index e13cc3e55f0..d9eed102fd0 100644 --- a/internal/service/elb/app_cookie_stickiness_policy.go +++ b/internal/service/elb/app_cookie_stickiness_policy.go @@ -24,8 +24,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_app_cookie_stickiness_policy") -func ResourceAppCookieStickinessPolicy() *schema.Resource { +// @SDKResource("aws_app_cookie_stickiness_policy", name="App Cookie Stickiness Policy") +func resourceAppCookieStickinessPolicy() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceAppCookieStickinessPolicyCreate, ReadWithoutTimeout: resourceAppCookieStickinessPolicyRead, @@ -75,7 +75,7 @@ func resourceAppCookieStickinessPolicyCreate(ctx context.Context, d *schema.Reso lbName := d.Get("load_balancer").(string) lbPort := d.Get("lb_port").(int) policyName := d.Get(names.AttrName).(string) - id := AppCookieStickinessPolicyCreateResourceID(lbName, lbPort, policyName) + id := appCookieStickinessPolicyCreateResourceID(lbName, lbPort, policyName) { input := &elasticloadbalancing.CreateAppCookieStickinessPolicyInput{ CookieName: aws.String(d.Get("cookie_name").(string)), @@ -83,11 +83,15 @@ func resourceAppCookieStickinessPolicyCreate(ctx context.Context, d *schema.Reso PolicyName: aws.String(policyName), } - if _, err := conn.CreateAppCookieStickinessPolicy(ctx, input); err != nil { + _, err := conn.CreateAppCookieStickinessPolicy(ctx, input) + + if err != nil { return sdkdiag.AppendErrorf(diags, "creating ELB Classic App Cookie Stickiness Policy (%s): %s", id, err) } } + d.SetId(id) + { input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), @@ -95,13 +99,13 @@ func resourceAppCookieStickinessPolicyCreate(ctx context.Context, d *schema.Reso PolicyNames: []string{policyName}, } - if _, err := conn.SetLoadBalancerPoliciesOfListener(ctx, input); err != nil { - return sdkdiag.AppendErrorf(diags, "setting ELB Classic App Cookie Stickiness Policy (%s): %s", id, err) + _, err := conn.SetLoadBalancerPoliciesOfListener(ctx, input) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "setting ELB Classic App Cookie Stickiness Policy (%s): %s", d.Id(), err) } } - d.SetId(id) - return append(diags, resourceAppCookieStickinessPolicyRead(ctx, d, meta)...) } @@ -109,13 +113,12 @@ func resourceAppCookieStickinessPolicyRead(ctx context.Context, d *schema.Resour var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, lbPort, policyName, err := AppCookieStickinessPolicyParseResourceID(d.Id()) - + lbName, lbPort, policyName, err := appCookieStickinessPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } - policy, err := FindLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) + policy, err := findLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ELB Classic App Cookie Stickiness Policy (%s) not found, removing from state", d.Id()) @@ -130,6 +133,7 @@ func resourceAppCookieStickinessPolicyRead(ctx context.Context, d *schema.Resour if len(policy.PolicyAttributeDescriptions) != 1 || aws.ToString(policy.PolicyAttributeDescriptions[0].AttributeName) != "CookieName" { return sdkdiag.AppendErrorf(diags, "cookie not found") } + cookieAttr := policy.PolicyAttributeDescriptions[0] d.Set("cookie_name", cookieAttr.AttributeValue) d.Set("lb_port", lbPort) @@ -143,10 +147,9 @@ func resourceAppCookieStickinessPolicyDelete(ctx context.Context, d *schema.Reso var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, lbPort, policyName, err := AppCookieStickinessPolicyParseResourceID(d.Id()) - + lbName, lbPort, policyName, err := appCookieStickinessPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } // Perversely, if we Set an empty list of PolicyNames, we detach the @@ -177,7 +180,7 @@ func resourceAppCookieStickinessPolicyDelete(ctx context.Context, d *schema.Reso return diags } -func FindLoadBalancerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName, policyName string) (*awstypes.PolicyDescription, error) { +func findLoadBalancerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName, policyName string) (*awstypes.PolicyDescription, error) { input := &elasticloadbalancing.DescribeLoadBalancerPoliciesInput{ LoadBalancerName: aws.String(lbName), PolicyNames: []string{policyName}, @@ -199,14 +202,14 @@ func FindLoadBalancerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadba return tfresource.AssertSingleValueResult(output.PolicyDescriptions) } -func FindLoadBalancerListenerPolicyByThreePartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, lbPort int, policyName string) (*awstypes.PolicyDescription, error) { - policy, err := FindLoadBalancerPolicyByTwoPartKey(ctx, conn, lbName, policyName) +func findLoadBalancerListenerPolicyByThreePartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, lbPort int, policyName string) (*awstypes.PolicyDescription, error) { + policy, err := findLoadBalancerPolicyByTwoPartKey(ctx, conn, lbName, policyName) if err != nil { return nil, err } - lb, err := FindLoadBalancerByName(ctx, conn, lbName) + lb, err := findLoadBalancerByName(ctx, conn, lbName) if err != nil { return nil, err @@ -233,14 +236,14 @@ func FindLoadBalancerListenerPolicyByThreePartKey(ctx context.Context, conn *ela const appCookieStickinessPolicyResourceIDSeparator = ":" -func AppCookieStickinessPolicyCreateResourceID(lbName string, lbPort int, policyName string) string { +func appCookieStickinessPolicyCreateResourceID(lbName string, lbPort int, policyName string) string { parts := []string{lbName, strconv.Itoa(lbPort), policyName} id := strings.Join(parts, appCookieStickinessPolicyResourceIDSeparator) return id } -func AppCookieStickinessPolicyParseResourceID(id string) (string, int, string, error) { +func appCookieStickinessPolicyParseResourceID(id string) (string, int, string, error) { parts := strings.Split(id, appCookieStickinessPolicyResourceIDSeparator) if len(parts) == 3 && parts[0] != "" && parts[1] != "" && parts[2] != "" { diff --git a/internal/service/elb/backend_server_policy.go b/internal/service/elb/backend_server_policy.go index 04bce7b9dc6..d567968e683 100644 --- a/internal/service/elb/backend_server_policy.go +++ b/internal/service/elb/backend_server_policy.go @@ -129,7 +129,7 @@ func resourceBackendServerPolicyDelete(ctx context.Context, d *schema.ResourceDa } func FindLoadBalancerBackendServerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, instancePort int) ([]string, error) { - lb, err := FindLoadBalancerByName(ctx, conn, lbName) + lb, err := findLoadBalancerByName(ctx, conn, lbName) if err != nil { return nil, err diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go new file mode 100644 index 00000000000..86fb8ba47aa --- /dev/null +++ b/internal/service/elb/exports_test.go @@ -0,0 +1,14 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package elb + +// Exports for use in tests only. +var ( + ResourceAppCookieStickinessPolicy = resourceAppCookieStickinessPolicy + + AppCookieStickinessPolicyParseResourceID = appCookieStickinessPolicyParseResourceID + FindLoadBalancerByName = findLoadBalancerByName + FindLoadBalancerListenerPolicyByThreePartKey = findLoadBalancerListenerPolicyByThreePartKey + FindLoadBalancerPolicyByTwoPartKey = findLoadBalancerPolicyByTwoPartKey +) diff --git a/internal/service/elb/lb_cookie_stickiness_policy.go b/internal/service/elb/lb_cookie_stickiness_policy.go index 4399d76ab85..0ad36b5be58 100644 --- a/internal/service/elb/lb_cookie_stickiness_policy.go +++ b/internal/service/elb/lb_cookie_stickiness_policy.go @@ -108,7 +108,7 @@ func resourceCookieStickinessPolicyRead(ctx context.Context, d *schema.ResourceD return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) } - policy, err := FindLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) + policy, err := findLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ELB Classic LB Cookie Stickiness Policy (%s) not found, removing from state", d.Id()) diff --git a/internal/service/elb/lb_ssl_negotiation_policy.go b/internal/service/elb/lb_ssl_negotiation_policy.go index d7c059b064f..2dc501b9df2 100644 --- a/internal/service/elb/lb_ssl_negotiation_policy.go +++ b/internal/service/elb/lb_ssl_negotiation_policy.go @@ -126,7 +126,7 @@ func resourceSSLNegotiationPolicyRead(ctx context.Context, d *schema.ResourceDat return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) } - _, err = FindLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) + _, err = findLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ELB Classic SSL Negotiation Policy (%s) not found, removing from state", d.Id()) diff --git a/internal/service/elb/listener_policy.go b/internal/service/elb/listener_policy.go index 2462a8b0fdb..dc0bec8dd66 100644 --- a/internal/service/elb/listener_policy.go +++ b/internal/service/elb/listener_policy.go @@ -135,7 +135,7 @@ func resourceListenerPolicyDelete(ctx context.Context, d *schema.ResourceData, m } func FindLoadBalancerListenerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, lbPort int) ([]string, error) { - lb, err := FindLoadBalancerByName(ctx, conn, lbName) + lb, err := findLoadBalancerByName(ctx, conn, lbName) if err != nil { return nil, err diff --git a/internal/service/elb/load_balancer.go b/internal/service/elb/load_balancer.go index 1271cd63724..ce29931e2cc 100644 --- a/internal/service/elb/load_balancer.go +++ b/internal/service/elb/load_balancer.go @@ -322,7 +322,7 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lb, err := FindLoadBalancerByName(ctx, conn, d.Id()) + lb, err := findLoadBalancerByName(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ELB Classic Load Balancer (%s) not found, removing from state", d.Id()) @@ -746,7 +746,7 @@ func resourceLoadBalancerDelete(ctx context.Context, d *schema.ResourceData, met return diags } -func FindLoadBalancerByName(ctx context.Context, conn *elasticloadbalancing.Client, name string) (*awstypes.LoadBalancerDescription, error) { +func findLoadBalancerByName(ctx context.Context, conn *elasticloadbalancing.Client, name string) (*awstypes.LoadBalancerDescription, error) { input := &elasticloadbalancing.DescribeLoadBalancersInput{ LoadBalancerNames: []string{name}, } @@ -764,21 +764,6 @@ func FindLoadBalancerByName(ctx context.Context, conn *elasticloadbalancing.Clie return nil, err } - if output == nil || len(output.LoadBalancerDescriptions) == 0 { - return nil, tfresource.NewEmptyResultError(input) - } - - if count := len(output.LoadBalancerDescriptions); count > 1 { - return nil, tfresource.NewTooManyResultsError(count, input) - } - - // Eventual consistency check. - if aws.ToString(output.LoadBalancerDescriptions[0].LoadBalancerName) != name { - return nil, &retry.NotFoundError{ - LastRequest: input, - } - } - return tfresource.AssertSingleValueResult(output.LoadBalancerDescriptions) } diff --git a/internal/service/elb/load_balancer_data_source.go b/internal/service/elb/load_balancer_data_source.go index 4a57ce7b45e..37a7cb0cb62 100644 --- a/internal/service/elb/load_balancer_data_source.go +++ b/internal/service/elb/load_balancer_data_source.go @@ -213,7 +213,7 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig lbName := d.Get(names.AttrName).(string) - lb, err := FindLoadBalancerByName(ctx, conn, lbName) + lb, err := findLoadBalancerByName(ctx, conn, lbName) if err != nil { return sdkdiag.AppendErrorf(diags, "reading ELB Classic Load Balancer (%s): %s", lbName, err) diff --git a/internal/service/elb/policy.go b/internal/service/elb/policy.go index 417e9cfa5c5..db4199011f7 100644 --- a/internal/service/elb/policy.go +++ b/internal/service/elb/policy.go @@ -111,7 +111,7 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) } - policy, err := FindLoadBalancerPolicyByTwoPartKey(ctx, conn, lbName, policyName) + policy, err := findLoadBalancerPolicyByTwoPartKey(ctx, conn, lbName, policyName) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ELB Classic Load Balancer Policy (%s) not found, removing from state", d.Id()) diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index edc828068cc..73c6b1dcce2 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -42,8 +42,9 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { return []*types.ServicePackageSDKResource{ { - Factory: ResourceAppCookieStickinessPolicy, + Factory: resourceAppCookieStickinessPolicy, TypeName: "aws_app_cookie_stickiness_policy", + Name: "App Cookie Stickiness Policy", }, { Factory: ResourceLoadBalancer, From 2c5b6cf24c7e8e5d5db97e7b60044b9f4c8d7ae2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 12:22:11 -0400 Subject: [PATCH 17/37] r/aws_elb_attachment: Reduce visibility. --- .../elb/app_cookie_stickiness_policy_test.go | 6 - internal/service/elb/attachment.go | 115 ++++---- internal/service/elb/attachment_test.go | 257 ++++++------------ internal/service/elb/errors.go | 8 + internal/service/elb/exports_test.go | 2 + internal/service/elb/service_package_gen.go | 3 +- 6 files changed, 144 insertions(+), 247 deletions(-) create mode 100644 internal/service/elb/errors.go diff --git a/internal/service/elb/app_cookie_stickiness_policy_test.go b/internal/service/elb/app_cookie_stickiness_policy_test.go index 96ad7d34988..75fc6ad82d3 100644 --- a/internal/service/elb/app_cookie_stickiness_policy_test.go +++ b/internal/service/elb/app_cookie_stickiness_policy_test.go @@ -111,7 +111,6 @@ func testAccCheckAppCookieStickinessPolicyDestroy(ctx context.Context) resource. } lbName, lbPort, policyName, err := tfelb.AppCookieStickinessPolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -140,12 +139,7 @@ func testAccCheckAppCookieStickinessPolicyExists(ctx context.Context, n string) return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No ELB Classic App Cookie Stickiness Policy ID is set") - } - lbName, lbPort, policyName, err := tfelb.AppCookieStickinessPolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } diff --git a/internal/service/elb/attachment.go b/internal/service/elb/attachment.go index 56b62d97964..d2f4a692eac 100644 --- a/internal/service/elb/attachment.go +++ b/internal/service/elb/attachment.go @@ -7,24 +7,23 @@ import ( "context" "fmt" "log" + "slices" "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) -// @SDKResource("aws_elb_attachment") -func ResourceAttachment() *schema.Resource { +// @SDKResource("aws_elb_attachment", name="Attachment") +func resourceAttachment() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceAttachmentCreate, ReadWithoutTimeout: resourceAttachmentRead, @@ -36,7 +35,6 @@ func ResourceAttachment() *schema.Resource { ForceNew: true, Required: true, }, - "instance": { Type: schema.TypeString, ForceNew: true, @@ -49,39 +47,27 @@ func ResourceAttachment() *schema.Resource { func resourceAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - elbName := d.Get("elb").(string) + lbName := d.Get("elb").(string) instance := d.Get("instance").(string) - - registerInstancesOpts := elasticloadbalancing.RegisterInstancesWithLoadBalancerInput{ - LoadBalancerName: aws.String(elbName), - Instances: []awstypes.Instance{{InstanceId: aws.String(instance)}}, + input := &elasticloadbalancing.RegisterInstancesWithLoadBalancerInput{ + Instances: expandInstances([]interface{}{instance}), + LoadBalancerName: aws.String(lbName), } - log.Printf("[INFO] registering instance %s with ELB %s", instance, elbName) - - err := retry.RetryContext(ctx, 10*time.Minute, func() *retry.RetryError { - _, err := conn.RegisterInstancesWithLoadBalancer(ctx, ®isterInstancesOpts) - - if tfawserr.ErrCodeEquals(err, "InvalidTarget") { - return retry.RetryableError(fmt.Errorf("attaching instance to ELB, retrying: %s", err)) - } + const ( + timeout = 10 * time.Minute + ) + _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, timeout, func() (interface{}, error) { + return conn.RegisterInstancesWithLoadBalancer(ctx, input) + }, errCodeInvalidTarget) - if err != nil { - return retry.NonRetryableError(err) - } - - return nil - }) - if tfresource.TimedOut(err) { - _, err = conn.RegisterInstancesWithLoadBalancer(ctx, ®isterInstancesOpts) - } if err != nil { - return sdkdiag.AppendErrorf(diags, "Failure registering instances with ELB: %s", err) + return sdkdiag.AppendErrorf(diags, "creating ELB Classic Attachment (%s/%s): %s", lbName, instance, err) } //lintignore:R016 // Allow legacy unstable ID usage in managed resource - d.SetId(id.PrefixedUniqueId(fmt.Sprintf("%s-", elbName))) + d.SetId(id.PrefixedUniqueId(fmt.Sprintf("%s-", lbName))) return diags } @@ -89,43 +75,19 @@ func resourceAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta func resourceAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - elbName := d.Get("elb").(string) - // only add the instance that was previously defined for this resource - expected := d.Get("instance").(string) - - // Retrieve the ELB properties to get a list of attachments - describeElbOpts := &elasticloadbalancing.DescribeLoadBalancersInput{ - LoadBalancerNames: []string{elbName}, - } + lbName := d.Get("elb").(string) + instance := d.Get("instance").(string) + err := findLoadBalancerAttachmentByTwoPartKey(ctx, conn, lbName, instance) - resp, err := conn.DescribeLoadBalancers(ctx, describeElbOpts) - if err != nil { - if !d.IsNewResource() && errs.IsA[*awstypes.AccessPointNotFoundException](err) { - log.Printf("[WARN] ELB Classic LB (%s) not found, removing from state", elbName) - d.SetId("") - return diags - } - return sdkdiag.AppendErrorf(diags, "retrieving ELB Classic LB (%s): %s", elbName, err) - } - if !d.IsNewResource() && len(resp.LoadBalancerDescriptions) != 1 { - log.Printf("[WARN] ELB Classic LB (%s) not found, removing from state", elbName) + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] ELB Classic Attachment (%s/%s) not found, removing from state", lbName, instance) d.SetId("") return diags } - // only set the instance Id that this resource manages - found := false - for _, i := range resp.LoadBalancerDescriptions[0].Instances { - if expected == aws.ToString(i.InstanceId) { - d.Set("instance", expected) - found = true - } - } - - if !d.IsNewResource() && !found { - log.Printf("[WARN] instance %s not found in elb attachments", expected) - d.SetId("") + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading ELB Classic Attachment (%s/%s): %s", lbName, instance, err) } return diags @@ -134,21 +96,38 @@ func resourceAttachmentRead(ctx context.Context, d *schema.ResourceData, meta in func resourceAttachmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - elbName := d.Get("elb").(string) + lbName := d.Get("elb").(string) instance := d.Get("instance").(string) + input := &elasticloadbalancing.DeregisterInstancesFromLoadBalancerInput{ + Instances: expandInstances([]interface{}{instance}), + LoadBalancerName: aws.String(lbName), + } - log.Printf("[INFO] Deleting Attachment %s from: %s", instance, elbName) + log.Printf("[DEBUG] Deleting ELB Classic Attachment: %s", d.Id()) + _, err := conn.DeregisterInstancesFromLoadBalancer(ctx, input) - deRegisterInstancesOpts := elasticloadbalancing.DeregisterInstancesFromLoadBalancerInput{ - LoadBalancerName: aws.String(elbName), - Instances: []awstypes.Instance{{InstanceId: aws.String(instance)}}, + if err != nil { + return sdkdiag.AppendErrorf(diags, "deleting ELB Classic Attachment (%s/%s): %s", lbName, instance, err) } - _, err := conn.DeregisterInstancesFromLoadBalancer(ctx, &deRegisterInstancesOpts) + return diags +} + +func findLoadBalancerAttachmentByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName, instance string) error { + lb, err := findLoadBalancerByName(ctx, conn, lbName) + if err != nil { - return sdkdiag.AppendErrorf(diags, "Failure deregistering instances from ELB: %s", err) + return err } - return diags + attached := slices.ContainsFunc(lb.Instances, func(v awstypes.Instance) bool { + return aws.ToString(v.InstanceId) == instance + }) + + if !attached { + return &retry.NotFoundError{} + } + + return nil } diff --git a/internal/service/elb/attachment_test.go b/internal/service/elb/attachment_test.go index a6e18f2c289..1e4679d1966 100644 --- a/internal/service/elb/attachment_test.go +++ b/internal/service/elb/attachment_test.go @@ -4,214 +4,136 @@ package elb_test import ( + "context" "fmt" - "log" "testing" - "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" + tfelb "github.com/hashicorp/terraform-provider-aws/internal/service/elb" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccELBAttachment_basic(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription - resourceName := "aws_elasticloadbalancing.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + lbResourceName := "aws_elb.test" + resourceName1 := "aws_elb_attachment.test1" + resourceName2 := "aws_elb_attachment.test2" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.ELBServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckLoadBalancerDestroy(ctx), + CheckDestroy: testAccCheckAttachmentDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccAttachmentConfig_1(), + Config: testAccAttachmentConfig_1(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, resourceName, &conf), + testAccCheckAttachmentExists(ctx, resourceName1), + testAccCheckLoadBalancerExists(ctx, lbResourceName, &conf), testAccAttachmentCheckInstanceCount(&conf, 1), ), }, { - Config: testAccAttachmentConfig_2(), + Config: testAccAttachmentConfig_2(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, resourceName, &conf), + testAccCheckAttachmentExists(ctx, resourceName1), + testAccCheckAttachmentExists(ctx, resourceName2), + testAccCheckLoadBalancerExists(ctx, lbResourceName, &conf), testAccAttachmentCheckInstanceCount(&conf, 2), ), }, - { - Config: testAccAttachmentConfig_3(), - Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, resourceName, &conf), - testAccAttachmentCheckInstanceCount(&conf, 2), - ), - }, - { - Config: testAccAttachmentConfig_4(), - Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, resourceName, &conf), - testAccAttachmentCheckInstanceCount(&conf, 0), - ), - }, }, }) } -// remove and instance and check that it's correctly re-attached. -func TestAccELBAttachment_drift(t *testing.T) { +func TestAccELBAttachment_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf awstypes.LoadBalancerDescription - resourceName := "aws_elasticloadbalancing.test" - - testAccAttachmentConfig_deregInstance := func() { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) - - deRegisterInstancesOpts := elasticloadbalancing.DeregisterInstancesFromLoadBalancerInput{ - LoadBalancerName: conf.LoadBalancerName, - Instances: conf.Instances, - } - - log.Printf("[DEBUG] deregistering instance %v from ELB", *conf.Instances[0].InstanceId) - - _, err := conn.DeregisterInstancesFromLoadBalancer(ctx, &deRegisterInstancesOpts) - if err != nil { - t.Fatalf("Failure deregistering instances from ELB: %s", err) - } - } + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_elb_attachment.test1" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.ELBServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckLoadBalancerDestroy(ctx), + CheckDestroy: testAccCheckAttachmentDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccAttachmentConfig_1(), - Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, resourceName, &conf), - testAccAttachmentCheckInstanceCount(&conf, 1), - ), - }, - // remove an instance from the ELB, and make sure it gets re-added - { - Config: testAccAttachmentConfig_1(), - PreConfig: testAccAttachmentConfig_deregInstance, + Config: testAccAttachmentConfig_1(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, resourceName, &conf), - testAccAttachmentCheckInstanceCount(&conf, 1), + testAccCheckAttachmentExists(ctx, resourceName), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tfelb.ResourceAttachment(), resourceName), ), + ExpectNonEmptyPlan: true, }, }, }) } -func testAccAttachmentCheckInstanceCount(conf *awstypes.LoadBalancerDescription, expected int) resource.TestCheckFunc { - return func(*terraform.State) error { - if actual := len(conf.Instances); actual != expected { - return fmt.Errorf("instance count does not match: expected %d, got %d", expected, actual) - } - return nil - } -} - -// add one attachment -func testAccAttachmentConfig_1() string { - return acctest.ConfigCompose(acctest.ConfigLatestAmazonLinux2HVMEBSX8664AMI(), ` -data "aws_availability_zones" "available" { - state = "available" +func testAccCheckAttachmentDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) - filter { - name = "opt-in-status" - values = ["opt-in-not-required"] - } -} + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_elb_attachment" { + continue + } -resource "aws_elb" "test" { - availability_zones = data.aws_availability_zones.available.names + err := tfelb.FindLoadBalancerAttachmentByTwoPartKey(ctx, conn, rs.Primary.Attributes["elb"], rs.Primary.Attributes["instance"]) - listener { - instance_port = 8000 - instance_protocol = "http" - lb_port = 80 - lb_protocol = "http" - } -} - -resource "aws_instance" "foo1" { - ami = data.aws_ami.amzn2-ami-minimal-hvm-ebs-x86_64.id - instance_type = "t2.micro" -} - -resource "aws_elb_attachment" "foo1" { - elb = aws_elasticloadbalancing.test.id - instance = aws_instance.foo1.id -} -`) -} + if tfresource.NotFound(err) { + continue + } -// add a second attachment -func testAccAttachmentConfig_2() string { - return acctest.ConfigCompose(acctest.ConfigLatestAmazonLinux2HVMEBSX8664AMI(), ` -data "aws_availability_zones" "available" { - state = "available" + if err != nil { + return err + } - filter { - name = "opt-in-status" - values = ["opt-in-not-required"] - } -} - -resource "aws_elb" "test" { - availability_zones = data.aws_availability_zones.available.names + return fmt.Errorf("ELB Classic Attachment %s still exists", rs.Primary.ID) + } - listener { - instance_port = 8000 - instance_protocol = "http" - lb_port = 80 - lb_protocol = "http" - } + return nil + } } -resource "aws_instance" "foo1" { - ami = data.aws_ami.amzn2-ami-minimal-hvm-ebs-x86_64.id - instance_type = "t2.micro" -} +func testAccCheckAttachmentExists(ctx context.Context, n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } -resource "aws_instance" "foo2" { - ami = data.aws_ami.amzn2-ami-minimal-hvm-ebs-x86_64.id - instance_type = "t2.micro" -} + conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) -resource "aws_elb_attachment" "foo1" { - elb = aws_elasticloadbalancing.test.id - instance = aws_instance.foo1.id -} + err := tfelb.FindLoadBalancerAttachmentByTwoPartKey(ctx, conn, rs.Primary.Attributes["elb"], rs.Primary.Attributes["instance"]) -resource "aws_elb_attachment" "foo2" { - elb = aws_elasticloadbalancing.test.id - instance = aws_instance.foo2.id -} -`) + return err + } } -// swap attachments between resources -func testAccAttachmentConfig_3() string { - return acctest.ConfigCompose(acctest.ConfigLatestAmazonLinux2HVMEBSX8664AMI(), ` -data "aws_availability_zones" "available" { - state = "available" - - filter { - name = "opt-in-status" - values = ["opt-in-not-required"] - } +func testAccAttachmentCheckInstanceCount(v *awstypes.LoadBalancerDescription, expected int) resource.TestCheckFunc { + return func(*terraform.State) error { + if actual := len(v.Instances); actual != expected { + return fmt.Errorf("instance count does not match: expected %d, got %d", expected, actual) + } + return nil + } } +func testAccAttachmentConfig_base(rName string) string { + return acctest.ConfigCompose(acctest.ConfigLatestAmazonLinux2HVMEBSX8664AMI(), acctest.ConfigAvailableAZsNoOptInDefaultExclude(), fmt.Sprintf(` resource "aws_elb" "test" { availability_zones = data.aws_availability_zones.available.names + name = %[1]q + listener { instance_port = 8000 instance_protocol = "http" @@ -219,50 +141,41 @@ resource "aws_elb" "test" { lb_protocol = "http" } } - -resource "aws_instance" "foo1" { - ami = data.aws_ami.amzn2-ami-minimal-hvm-ebs-x86_64.id - instance_type = "t2.micro" +`)) } -resource "aws_instance" "foo2" { +func testAccAttachmentConfig_1(rName string) string { + return acctest.ConfigCompose(testAccAttachmentConfig_base(rName), fmt.Sprintf(` +resource "aws_instance" "test1" { ami = data.aws_ami.amzn2-ami-minimal-hvm-ebs-x86_64.id instance_type = "t2.micro" -} -resource "aws_elb_attachment" "foo1" { - elb = aws_elasticloadbalancing.test.id - instance = aws_instance.foo2.id + tags = { + Name = %[1]q + } } -resource "aws_elb_attachment" "foo2" { - elb = aws_elasticloadbalancing.test.id - instance = aws_instance.foo1.id +resource "aws_elb_attachment" "test1" { + elb = aws_elb.test.id + instance = aws_instance.test1.id } -`) +`, rName)) } -// destroy attachments -func testAccAttachmentConfig_4() string { - return ` -data "aws_availability_zones" "available" { - state = "available" +func testAccAttachmentConfig_2(rName string) string { + return acctest.ConfigCompose(testAccAttachmentConfig_1(rName), fmt.Sprintf(` +resource "aws_instance" "test2" { + ami = data.aws_ami.amzn2-ami-minimal-hvm-ebs-x86_64.id + instance_type = "t2.micro" - filter { - name = "opt-in-status" - values = ["opt-in-not-required"] + tags = { + Name = %[1]q } } -resource "aws_elb" "test" { - availability_zones = data.aws_availability_zones.available.names - - listener { - instance_port = 8000 - instance_protocol = "http" - lb_port = 80 - lb_protocol = "http" - } +resource "aws_elb_attachment" "test2" { + elb = aws_elb.test.id + instance = aws_instance.test2.id } -` +`, rName)) } diff --git a/internal/service/elb/errors.go b/internal/service/elb/errors.go new file mode 100644 index 00000000000..0b4c394f4b9 --- /dev/null +++ b/internal/service/elb/errors.go @@ -0,0 +1,8 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package elb + +const ( + errCodeInvalidTarget = "InvalidTarget" +) diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index 86fb8ba47aa..108eb12f360 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -6,8 +6,10 @@ package elb // Exports for use in tests only. var ( ResourceAppCookieStickinessPolicy = resourceAppCookieStickinessPolicy + ResourceAttachment = resourceAttachment AppCookieStickinessPolicyParseResourceID = appCookieStickinessPolicyParseResourceID + FindLoadBalancerAttachmentByTwoPartKey = findLoadBalancerAttachmentByTwoPartKey FindLoadBalancerByName = findLoadBalancerByName FindLoadBalancerListenerPolicyByThreePartKey = findLoadBalancerListenerPolicyByThreePartKey FindLoadBalancerPolicyByTwoPartKey = findLoadBalancerPolicyByTwoPartKey diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index 73c6b1dcce2..f3a995275f0 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -55,8 +55,9 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka }, }, { - Factory: ResourceAttachment, + Factory: resourceAttachment, TypeName: "aws_elb_attachment", + Name: "Attachment", }, { Factory: ResourceCookieStickinessPolicy, From 7553741f0a3c2bb89bab7f7320c9807e62105349 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 12:30:32 -0400 Subject: [PATCH 18/37] r/aws_load_balancer_backend_server_policy: Reduce visibility. --- internal/service/elb/backend_server_policy.go | 32 ++++++++----------- .../service/elb/backend_server_policy_test.go | 6 ---- internal/service/elb/exports_test.go | 13 +++++--- internal/service/elb/service_package_gen.go | 3 +- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/internal/service/elb/backend_server_policy.go b/internal/service/elb/backend_server_policy.go index d567968e683..53ebe56a274 100644 --- a/internal/service/elb/backend_server_policy.go +++ b/internal/service/elb/backend_server_policy.go @@ -20,8 +20,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) -// @SDKResource("aws_load_balancer_backend_server_policy") -func ResourceBackendServerPolicy() *schema.Resource { +// @SDKResource("aws_load_balancer_backend_server_policy", name="Backend Server Policy") +func resourceBackendServerPolicy() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceBackendServerPolicySet, ReadWithoutTimeout: resourceBackendServerPolicyRead, @@ -52,7 +52,7 @@ func resourceBackendServerPolicySet(ctx context.Context, d *schema.ResourceData, instancePort := d.Get("instance_port").(int) lbName := d.Get("load_balancer_name").(string) - id := BackendServerPolicyCreateResourceID(lbName, instancePort) + id := backendServerPolicyCreateResourceID(lbName, instancePort) input := &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ InstancePort: aws.Int32(int32(instancePort)), LoadBalancerName: aws.String(lbName), @@ -77,13 +77,12 @@ func resourceBackendServerPolicyRead(ctx context.Context, d *schema.ResourceData var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, instancePort, err := BackendServerPolicyParseResourceID(d.Id()) - + lbName, instancePort, err := backendServerPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } - policyNames, err := FindLoadBalancerBackendServerPolicyByTwoPartKey(ctx, conn, lbName, instancePort) + policyNames, err := findLoadBalancerBackendServerPolicyByTwoPartKey(ctx, conn, lbName, instancePort) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ELB Classic Backend Server Policy (%s) not found, removing from state", d.Id()) @@ -106,20 +105,17 @@ func resourceBackendServerPolicyDelete(ctx context.Context, d *schema.ResourceDa var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, instancePort, err := BackendServerPolicyParseResourceID(d.Id()) - + lbName, instancePort, err := backendServerPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } - input := &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ + log.Printf("[DEBUG] Deleting ELB Classic Backend Server Policy: %s", d.Id()) + _, err = conn.SetLoadBalancerPoliciesForBackendServer(ctx, &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ InstancePort: aws.Int32(int32(instancePort)), LoadBalancerName: aws.String(lbName), PolicyNames: []string{}, - } - - log.Printf("[DEBUG] Deleting ELB Classic Backend Server Policy: %s", d.Id()) - _, err = conn.SetLoadBalancerPoliciesForBackendServer(ctx, input) + }) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic Backend Server Policy (%s): %s", d.Id(), err) @@ -128,7 +124,7 @@ func resourceBackendServerPolicyDelete(ctx context.Context, d *schema.ResourceDa return diags } -func FindLoadBalancerBackendServerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, instancePort int) ([]string, error) { +func findLoadBalancerBackendServerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, instancePort int) ([]string, error) { lb, err := findLoadBalancerByName(ctx, conn, lbName) if err != nil { @@ -150,14 +146,14 @@ func FindLoadBalancerBackendServerPolicyByTwoPartKey(ctx context.Context, conn * const backendServerPolicyResourceIDSeparator = ":" -func BackendServerPolicyCreateResourceID(lbName string, instancePort int) string { +func backendServerPolicyCreateResourceID(lbName string, instancePort int) string { parts := []string{lbName, strconv.Itoa(instancePort)} id := strings.Join(parts, backendServerPolicyResourceIDSeparator) return id } -func BackendServerPolicyParseResourceID(id string) (string, int, error) { +func backendServerPolicyParseResourceID(id string) (string, int, error) { parts := strings.Split(id, backendServerPolicyResourceIDSeparator) if len(parts) == 2 && parts[0] != "" && parts[1] != "" { diff --git a/internal/service/elb/backend_server_policy_test.go b/internal/service/elb/backend_server_policy_test.go index 7baa0a7f533..f7a4c2dc7b1 100644 --- a/internal/service/elb/backend_server_policy_test.go +++ b/internal/service/elb/backend_server_policy_test.go @@ -123,7 +123,6 @@ func testAccCheckBackendServerPolicyDestroy(ctx context.Context) resource.TestCh } lbName, instancePort, err := tfelb.BackendServerPolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -152,12 +151,7 @@ func testAccCheckBackendServerPolicyExists(ctx context.Context, n string) resour return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No ELB Classic Backend Server Policy ID is set") - } - lbName, instancePort, err := tfelb.BackendServerPolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index 108eb12f360..12ed4867d33 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -7,10 +7,13 @@ package elb var ( ResourceAppCookieStickinessPolicy = resourceAppCookieStickinessPolicy ResourceAttachment = resourceAttachment + ResourceBackendServerPolicy = resourceBackendServerPolicy - AppCookieStickinessPolicyParseResourceID = appCookieStickinessPolicyParseResourceID - FindLoadBalancerAttachmentByTwoPartKey = findLoadBalancerAttachmentByTwoPartKey - FindLoadBalancerByName = findLoadBalancerByName - FindLoadBalancerListenerPolicyByThreePartKey = findLoadBalancerListenerPolicyByThreePartKey - FindLoadBalancerPolicyByTwoPartKey = findLoadBalancerPolicyByTwoPartKey + AppCookieStickinessPolicyParseResourceID = appCookieStickinessPolicyParseResourceID + BackendServerPolicyParseResourceID = backendServerPolicyParseResourceID + FindLoadBalancerAttachmentByTwoPartKey = findLoadBalancerAttachmentByTwoPartKey + FindLoadBalancerBackendServerPolicyByTwoPartKey = findLoadBalancerBackendServerPolicyByTwoPartKey + FindLoadBalancerByName = findLoadBalancerByName + FindLoadBalancerListenerPolicyByThreePartKey = findLoadBalancerListenerPolicyByThreePartKey + FindLoadBalancerPolicyByTwoPartKey = findLoadBalancerPolicyByTwoPartKey ) diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index f3a995275f0..b39f721c42a 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -68,8 +68,9 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka TypeName: "aws_lb_ssl_negotiation_policy", }, { - Factory: ResourceBackendServerPolicy, + Factory: resourceBackendServerPolicy, TypeName: "aws_load_balancer_backend_server_policy", + Name: "Backend Server Policy", }, { Factory: ResourceListenerPolicy, From 809ff6eff95f3c124574a7fe96a87f23d46d422b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 12:37:42 -0400 Subject: [PATCH 19/37] Remove some constants. --- internal/service/autoscaling/consts.go | 4 ++++ internal/service/autoscaling/group.go | 3 +-- internal/service/elb/enum.go | 13 ------------- internal/service/elb/policy_test.go | 16 ++++++++-------- 4 files changed, 13 insertions(+), 23 deletions(-) delete mode 100644 internal/service/elb/enum.go diff --git a/internal/service/autoscaling/consts.go b/internal/service/autoscaling/consts.go index 3edf0cf99c7..c61a28eb52e 100644 --- a/internal/service/autoscaling/consts.go +++ b/internal/service/autoscaling/consts.go @@ -121,3 +121,7 @@ func (lifecycleHookLifecycleTransition) Values() []lifecycleHookLifecycleTransit lifecycleHookLifecycleTransitionInstanceTerminating, } } + +const ( + elbInstanceStateInService = "InService" +) diff --git a/internal/service/autoscaling/group.go b/internal/service/autoscaling/group.go index f1a8f203fe2..105ffd082f4 100644 --- a/internal/service/autoscaling/group.go +++ b/internal/service/autoscaling/group.go @@ -33,7 +33,6 @@ import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/sdkv2/types/nullable" - tfelb "github.com/hashicorp/terraform-provider-aws/internal/service/elb" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -2359,7 +2358,7 @@ func statusGroupCapacity(ctx context.Context, conn *autoscaling.Client, elbconn inAll := true for _, v := range lbInstanceStates { - if state, ok := v[instanceID]; ok && state != tfelb.InstanceStateInService { + if state, ok := v[instanceID]; ok && state != elbInstanceStateInService { inAll = false break } diff --git a/internal/service/elb/enum.go b/internal/service/elb/enum.go deleted file mode 100644 index 527a0fe0999..00000000000 --- a/internal/service/elb/enum.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package elb - -const ( - InstanceStateInService = "InService" -) - -const ( - ReferenceSecurityPolicy = "Reference-Security-Policy" - SSLNegotiationPolicyType = "SSLNegotiationPolicyType" -) diff --git a/internal/service/elb/policy_test.go b/internal/service/elb/policy_test.go index 897e84b9a37..361225035e1 100644 --- a/internal/service/elb/policy_test.go +++ b/internal/service/elb/policy_test.go @@ -104,10 +104,10 @@ func TestAccELBPolicy_SSLNegotiationPolicyType_computedAttributesOnly(t *testing CheckDestroy: testAccCheckPolicyDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccPolicyConfig_typeNameOnly(rName, tfelb.SSLNegotiationPolicyType), + Config: testAccPolicyConfig_typeNameOnly(rName, "SSLNegotiationPolicyType"), Check: resource.ComposeTestCheckFunc( testAccCheckPolicyExists(ctx, resourceName, &policy), - resource.TestCheckResourceAttr(resourceName, "policy_type_name", tfelb.SSLNegotiationPolicyType), + resource.TestCheckResourceAttr(resourceName, "policy_type_name", "SSLNegotiationPolicyType"), resource.TestMatchResourceAttr(resourceName, "policy_attribute.#", regexache.MustCompile(`[^0]+`)), ), }, @@ -132,7 +132,7 @@ func TestAccELBPolicy_SSLNegotiationPolicyType_customPolicy(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckPolicyExists(ctx, resourceName, &policy), resource.TestCheckResourceAttr(resourceName, "policy_name", rName), - resource.TestCheckResourceAttr(resourceName, "policy_type_name", tfelb.SSLNegotiationPolicyType), + resource.TestCheckResourceAttr(resourceName, "policy_type_name", "SSLNegotiationPolicyType"), resource.TestCheckResourceAttr(resourceName, "policy_attribute.#", acctest.Ct2), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "policy_attribute.*", map[string]string{ names.AttrName: "Protocol-TLSv1.1", @@ -149,7 +149,7 @@ func TestAccELBPolicy_SSLNegotiationPolicyType_customPolicy(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckPolicyExists(ctx, resourceName, &policy), resource.TestCheckResourceAttr(resourceName, "policy_name", rName), - resource.TestCheckResourceAttr(resourceName, "policy_type_name", tfelb.SSLNegotiationPolicyType), + resource.TestCheckResourceAttr(resourceName, "policy_type_name", "SSLNegotiationPolicyType"), resource.TestCheckResourceAttr(resourceName, "policy_attribute.#", acctest.Ct2), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "policy_attribute.*", map[string]string{ names.AttrName: "Protocol-TLSv1.2", @@ -185,10 +185,10 @@ func TestAccELBPolicy_SSLSecurityPolicy_predefined(t *testing.T) { testAccCheckPolicyExists(ctx, resourceName, &policy), resource.TestCheckResourceAttr(resourceName, "policy_attribute.#", acctest.Ct1), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "policy_attribute.*", map[string]string{ - names.AttrName: tfelb.ReferenceSecurityPolicy, + names.AttrName: "Reference-Security-Policy", names.AttrValue: predefinedSecurityPolicy, }), - resource.TestCheckResourceAttr(resourceName, "policy_type_name", tfelb.SSLNegotiationPolicyType), + resource.TestCheckResourceAttr(resourceName, "policy_type_name", "SSLNegotiationPolicyType"), ), }, { @@ -197,10 +197,10 @@ func TestAccELBPolicy_SSLSecurityPolicy_predefined(t *testing.T) { testAccCheckPolicyExists(ctx, resourceName, &policy), resource.TestCheckResourceAttr(resourceName, "policy_attribute.#", acctest.Ct1), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "policy_attribute.*", map[string]string{ - names.AttrName: tfelb.ReferenceSecurityPolicy, + names.AttrName: "Reference-Security-Policy", names.AttrValue: predefinedSecurityPolicyUpdated, }), - resource.TestCheckResourceAttr(resourceName, "policy_type_name", tfelb.SSLNegotiationPolicyType), + resource.TestCheckResourceAttr(resourceName, "policy_type_name", "SSLNegotiationPolicyType"), ), }, }, From 7d63c34cebfce89e7c4f2a980f30e04051e04f94 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 13:06:01 -0400 Subject: [PATCH 20/37] d/aws_elb_hosted_zone_id: Reduce visibility. --- internal/service/elb/exports_test.go | 1 + internal/service/elb/hosted_zone_id_data_source.go | 13 ++++++------- .../service/elb/hosted_zone_id_data_source_test.go | 2 +- internal/service/elb/service_package_gen.go | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index 12ed4867d33..64b2c3c8304 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -16,4 +16,5 @@ var ( FindLoadBalancerByName = findLoadBalancerByName FindLoadBalancerListenerPolicyByThreePartKey = findLoadBalancerListenerPolicyByThreePartKey FindLoadBalancerPolicyByTwoPartKey = findLoadBalancerPolicyByTwoPartKey + HostedZoneIDPerRegionMap = hostedZoneIDPerRegionMap ) diff --git a/internal/service/elb/hosted_zone_id_data_source.go b/internal/service/elb/hosted_zone_id_data_source.go index e78d6e03f4b..5dafb0e4c3a 100644 --- a/internal/service/elb/hosted_zone_id_data_source.go +++ b/internal/service/elb/hosted_zone_id_data_source.go @@ -14,9 +14,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// See https://docs.aws.amazon.com/general/latest/gr/elb.html#elb_region - -var HostedZoneIdPerRegionMap = map[string]string{ +// See https://docs.aws.amazon.com/general/latest/gr/elb.html#elb_region. +var hostedZoneIDPerRegionMap = map[string]string{ endpoints.AfSouth1RegionID: "Z268VQBMOI5EKX", endpoints.ApEast1RegionID: "Z3DQVH9N71FHZ0", endpoints.ApNortheast1RegionID: "Z14GRHDCWA56QT", @@ -52,8 +51,8 @@ var HostedZoneIdPerRegionMap = map[string]string{ endpoints.UsWest2RegionID: "Z1H1FL5HABSF5", } -// @SDKDataSource("aws_elb_hosted_zone_id") -func DataSourceHostedZoneID() *schema.Resource { +// @SDKDataSource("aws_elb_hosted_zone_id", name="Hosted Zone ID") +func dataSourceHostedZoneID() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceHostedZoneIDRead, @@ -73,10 +72,10 @@ func dataSourceHostedZoneIDRead(ctx context.Context, d *schema.ResourceData, met region = v.(string) } - if zoneId, ok := HostedZoneIdPerRegionMap[region]; ok { + if zoneId, ok := hostedZoneIDPerRegionMap[region]; ok { d.SetId(zoneId) return diags } - return sdkdiag.AppendErrorf(diags, "Unknown region (%q)", region) + return sdkdiag.AppendErrorf(diags, "Unknown region (%s)", region) } diff --git a/internal/service/elb/hosted_zone_id_data_source_test.go b/internal/service/elb/hosted_zone_id_data_source_test.go index 4c47eac14e8..2028b54da8f 100644 --- a/internal/service/elb/hosted_zone_id_data_source_test.go +++ b/internal/service/elb/hosted_zone_id_data_source_test.go @@ -22,7 +22,7 @@ func TestAccELBHostedZoneIDDataSource_basic(t *testing.T) { { Config: testAccHostedZoneIDDataSourceConfig_basic, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.main", names.AttrID, tfelb.HostedZoneIdPerRegionMap[acctest.Region()]), + resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.main", names.AttrID, tfelb.HostedZoneIDPerRegionMap[acctest.Region()]), ), }, { diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index b39f721c42a..02cd31c2df8 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -29,8 +29,9 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac TypeName: "aws_elb", }, { - Factory: DataSourceHostedZoneID, + Factory: dataSourceHostedZoneID, TypeName: "aws_elb_hosted_zone_id", + Name: "Hosted Zone ID", }, { Factory: DataSourceServiceAccount, From c4fcd66850fd7ca39d62d2224c1650a8f944391f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 14:19:04 -0400 Subject: [PATCH 21/37] r/aws_lb_cookie_stickiness_policy: Reduce visibility. --- internal/service/elb/exports_test.go | 2 ++ .../elb/lb_cookie_stickiness_policy.go | 28 ++++++++----------- .../elb/lb_cookie_stickiness_policy_test.go | 6 ---- internal/service/elb/service_package_gen.go | 3 +- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index 64b2c3c8304..9907575e4f8 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -8,6 +8,7 @@ var ( ResourceAppCookieStickinessPolicy = resourceAppCookieStickinessPolicy ResourceAttachment = resourceAttachment ResourceBackendServerPolicy = resourceBackendServerPolicy + ResourceCookieStickinessPolicy = resourceCookieStickinessPolicy AppCookieStickinessPolicyParseResourceID = appCookieStickinessPolicyParseResourceID BackendServerPolicyParseResourceID = backendServerPolicyParseResourceID @@ -17,4 +18,5 @@ var ( FindLoadBalancerListenerPolicyByThreePartKey = findLoadBalancerListenerPolicyByThreePartKey FindLoadBalancerPolicyByTwoPartKey = findLoadBalancerPolicyByTwoPartKey HostedZoneIDPerRegionMap = hostedZoneIDPerRegionMap + LBCookieStickinessPolicyParseResourceID = lbCookieStickinessPolicyParseResourceID ) diff --git a/internal/service/elb/lb_cookie_stickiness_policy.go b/internal/service/elb/lb_cookie_stickiness_policy.go index 0ad36b5be58..322a1f0d8db 100644 --- a/internal/service/elb/lb_cookie_stickiness_policy.go +++ b/internal/service/elb/lb_cookie_stickiness_policy.go @@ -17,12 +17,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_lb_cookie_stickiness_policy") -func ResourceCookieStickinessPolicy() *schema.Resource { +// @SDKResource("aws_lb_cookie_stickiness_policy", name="LB Cookie Stickiness Policy") +func resourceCookieStickinessPolicy() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceCookieStickinessPolicyCreate, ReadWithoutTimeout: resourceCookieStickinessPolicyRead, @@ -61,7 +62,7 @@ func resourceCookieStickinessPolicyCreate(ctx context.Context, d *schema.Resourc lbName := d.Get("load_balancer").(string) lbPort := d.Get("lb_port").(int) policyName := d.Get(names.AttrName).(string) - id := LBCookieStickinessPolicyCreateResourceID(lbName, lbPort, policyName) + id := lbCookieStickinessPolicyCreateResourceID(lbName, lbPort, policyName) { input := &elasticloadbalancing.CreateLBCookieStickinessPolicyInput{ LoadBalancerName: aws.String(lbName), @@ -102,10 +103,9 @@ func resourceCookieStickinessPolicyRead(ctx context.Context, d *schema.ResourceD var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, lbPort, policyName, err := LBCookieStickinessPolicyParseResourceID(d.Id()) - + lbName, lbPort, policyName, err := lbCookieStickinessPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } policy, err := findLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) @@ -123,11 +123,8 @@ func resourceCookieStickinessPolicyRead(ctx context.Context, d *schema.ResourceD if len(policy.PolicyAttributeDescriptions) != 1 || aws.ToString(policy.PolicyAttributeDescriptions[0].AttributeName) != "CookieExpirationPeriod" { return sdkdiag.AppendErrorf(diags, "cookie expiration period not found") } - if v, err := strconv.Atoi(aws.ToString(policy.PolicyAttributeDescriptions[0].AttributeValue)); err != nil { - return sdkdiag.AppendErrorf(diags, "parsing cookie expiration period: %s", err) - } else { - d.Set("cookie_expiration_period", v) - } + + d.Set("cookie_expiration_period", flex.StringToIntValue(policy.PolicyAttributeDescriptions[0].AttributeValue)) d.Set("lb_port", lbPort) d.Set("load_balancer", lbName) d.Set(names.AttrName, policyName) @@ -139,10 +136,9 @@ func resourceCookieStickinessPolicyDelete(ctx context.Context, d *schema.Resourc var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, lbPort, policyName, err := LBCookieStickinessPolicyParseResourceID(d.Id()) - + lbName, lbPort, policyName, err := lbCookieStickinessPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } // Perversely, if we Set an empty list of PolicyNames, we detach the @@ -175,14 +171,14 @@ func resourceCookieStickinessPolicyDelete(ctx context.Context, d *schema.Resourc const lbCookieStickinessPolicyResourceIDSeparator = ":" -func LBCookieStickinessPolicyCreateResourceID(lbName string, lbPort int, policyName string) string { +func lbCookieStickinessPolicyCreateResourceID(lbName string, lbPort int, policyName string) string { parts := []string{lbName, strconv.Itoa(lbPort), policyName} id := strings.Join(parts, lbCookieStickinessPolicyResourceIDSeparator) return id } -func LBCookieStickinessPolicyParseResourceID(id string) (string, int, string, error) { +func lbCookieStickinessPolicyParseResourceID(id string) (string, int, string, error) { parts := strings.Split(id, lbCookieStickinessPolicyResourceIDSeparator) if len(parts) == 3 && parts[0] != "" && parts[1] != "" && parts[2] != "" { diff --git a/internal/service/elb/lb_cookie_stickiness_policy_test.go b/internal/service/elb/lb_cookie_stickiness_policy_test.go index 1598edf4a09..3caec2d223d 100644 --- a/internal/service/elb/lb_cookie_stickiness_policy_test.go +++ b/internal/service/elb/lb_cookie_stickiness_policy_test.go @@ -106,7 +106,6 @@ func testAccCheckLBCookieStickinessPolicyDestroy(ctx context.Context) resource.T } lbName, lbPort, policyName, err := tfelb.LBCookieStickinessPolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -135,12 +134,7 @@ func testAccCheckLBCookieStickinessPolicyExists(ctx context.Context, n string) r return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No ELB Classic LB Cookie Stickiness Policy ID is set") - } - lbName, lbPort, policyName, err := tfelb.LBCookieStickinessPolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index 02cd31c2df8..35f21c729fa 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -61,8 +61,9 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka Name: "Attachment", }, { - Factory: ResourceCookieStickinessPolicy, + Factory: resourceCookieStickinessPolicy, TypeName: "aws_lb_cookie_stickiness_policy", + Name: "LB Cookie Stickiness Policy", }, { Factory: ResourceSSLNegotiationPolicy, From f0aaa63bfbfb3eba55f2a1a9917c5783c3e599fe Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 14:24:12 -0400 Subject: [PATCH 22/37] r/aws_lb_ssl_negotiation_policy: Reduce visibility. --- internal/service/elb/exports_test.go | 2 ++ .../service/elb/lb_ssl_negotiation_policy.go | 20 +++++++++---------- .../elb/lb_ssl_negotiation_policy_test.go | 6 ------ internal/service/elb/service_package_gen.go | 3 ++- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index 9907575e4f8..d159b0316e1 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -9,6 +9,7 @@ var ( ResourceAttachment = resourceAttachment ResourceBackendServerPolicy = resourceBackendServerPolicy ResourceCookieStickinessPolicy = resourceCookieStickinessPolicy + ResourceSSLNegotiationPolicy = resourceSSLNegotiationPolicy AppCookieStickinessPolicyParseResourceID = appCookieStickinessPolicyParseResourceID BackendServerPolicyParseResourceID = backendServerPolicyParseResourceID @@ -19,4 +20,5 @@ var ( FindLoadBalancerPolicyByTwoPartKey = findLoadBalancerPolicyByTwoPartKey HostedZoneIDPerRegionMap = hostedZoneIDPerRegionMap LBCookieStickinessPolicyParseResourceID = lbCookieStickinessPolicyParseResourceID + SSLNegotiationPolicyParseResourceID = sslNegotiationPolicyParseResourceID ) diff --git a/internal/service/elb/lb_ssl_negotiation_policy.go b/internal/service/elb/lb_ssl_negotiation_policy.go index 2dc501b9df2..755399df03a 100644 --- a/internal/service/elb/lb_ssl_negotiation_policy.go +++ b/internal/service/elb/lb_ssl_negotiation_policy.go @@ -20,8 +20,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_lb_ssl_negotiation_policy") -func ResourceSSLNegotiationPolicy() *schema.Resource { +// @SDKResource("aws_lb_ssl_negotiation_policy", name="SSL Negotiation Policy") +func resourceSSLNegotiationPolicy() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceSSLNegotiationPolicyCreate, ReadWithoutTimeout: resourceSSLNegotiationPolicyRead, @@ -77,7 +77,7 @@ func resourceSSLNegotiationPolicyCreate(ctx context.Context, d *schema.ResourceD lbName := d.Get("load_balancer").(string) lbPort := d.Get("lb_port").(int) policyName := d.Get(names.AttrName).(string) - id := SSLNegotiationPolicyCreateResourceID(lbName, lbPort, policyName) + id := sslNegotiationPolicyCreateResourceID(lbName, lbPort, policyName) { input := &elasticloadbalancing.CreateLoadBalancerPolicyInput{ @@ -120,10 +120,9 @@ func resourceSSLNegotiationPolicyRead(ctx context.Context, d *schema.ResourceDat var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, lbPort, policyName, err := SSLNegotiationPolicyParseResourceID(d.Id()) - + lbName, lbPort, policyName, err := sslNegotiationPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } _, err = findLoadBalancerListenerPolicyByThreePartKey(ctx, conn, lbName, lbPort, policyName) @@ -164,10 +163,9 @@ func resourceSSLNegotiationPolicyDelete(ctx context.Context, d *schema.ResourceD var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, lbPort, policyName, err := SSLNegotiationPolicyParseResourceID(d.Id()) - + lbName, lbPort, policyName, err := sslNegotiationPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } // Perversely, if we Set an empty list of PolicyNames, we detach the @@ -199,14 +197,14 @@ func resourceSSLNegotiationPolicyDelete(ctx context.Context, d *schema.ResourceD const sslNegotiationPolicyResourceIDSeparator = ":" -func SSLNegotiationPolicyCreateResourceID(lbName string, lbPort int, policyName string) string { +func sslNegotiationPolicyCreateResourceID(lbName string, lbPort int, policyName string) string { parts := []string{lbName, strconv.Itoa(lbPort), policyName} id := strings.Join(parts, sslNegotiationPolicyResourceIDSeparator) return id } -func SSLNegotiationPolicyParseResourceID(id string) (string, int, string, error) { +func sslNegotiationPolicyParseResourceID(id string) (string, int, string, error) { parts := strings.Split(id, sslNegotiationPolicyResourceIDSeparator) if len(parts) == 3 && parts[0] != "" && parts[1] != "" && parts[2] != "" { diff --git a/internal/service/elb/lb_ssl_negotiation_policy_test.go b/internal/service/elb/lb_ssl_negotiation_policy_test.go index 781aff155fc..90f808d3523 100644 --- a/internal/service/elb/lb_ssl_negotiation_policy_test.go +++ b/internal/service/elb/lb_ssl_negotiation_policy_test.go @@ -112,7 +112,6 @@ func testAccCheckLBSSLNegotiationPolicyDestroy(ctx context.Context) resource.Tes } lbName, lbPort, policyName, err := tfelb.SSLNegotiationPolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -141,12 +140,7 @@ func testAccCheckLBSSLNegotiationPolicy(ctx context.Context, n string) resource. return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No ELB Classic SSL Negotiation Policy ID is set") - } - lbName, lbPort, policyName, err := tfelb.SSLNegotiationPolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index 35f21c729fa..76552ced568 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -66,8 +66,9 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka Name: "LB Cookie Stickiness Policy", }, { - Factory: ResourceSSLNegotiationPolicy, + Factory: resourceSSLNegotiationPolicy, TypeName: "aws_lb_ssl_negotiation_policy", + Name: "SSL Negotiation Policy", }, { Factory: resourceBackendServerPolicy, From 87108755e96d613368302feec3b9e107d745afa4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 14:56:15 -0400 Subject: [PATCH 23/37] r/aws_load_balancer_listener_policy: Reduce visibility. --- internal/service/elb/backend_server_policy.go | 4 ++- internal/service/elb/exports_test.go | 3 ++ internal/service/elb/listener_policy.go | 28 +++++++++---------- internal/service/elb/service_package_gen.go | 3 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/internal/service/elb/backend_server_policy.go b/internal/service/elb/backend_server_policy.go index 53ebe56a274..8f8aac82f62 100644 --- a/internal/service/elb/backend_server_policy.go +++ b/internal/service/elb/backend_server_policy.go @@ -68,7 +68,9 @@ func resourceBackendServerPolicySet(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "setting ELB Classic Backend Server Policy (%s): %s", id, err) } - d.SetId(id) + if d.IsNewResource() { + d.SetId(id) + } return append(diags, resourceBackendServerPolicyRead(ctx, d, meta)...) } diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index d159b0316e1..199cc5edf4c 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -9,6 +9,7 @@ var ( ResourceAttachment = resourceAttachment ResourceBackendServerPolicy = resourceBackendServerPolicy ResourceCookieStickinessPolicy = resourceCookieStickinessPolicy + ResourceListenerPolicy = resourceListenerPolicy ResourceSSLNegotiationPolicy = resourceSSLNegotiationPolicy AppCookieStickinessPolicyParseResourceID = appCookieStickinessPolicyParseResourceID @@ -17,8 +18,10 @@ var ( FindLoadBalancerBackendServerPolicyByTwoPartKey = findLoadBalancerBackendServerPolicyByTwoPartKey FindLoadBalancerByName = findLoadBalancerByName FindLoadBalancerListenerPolicyByThreePartKey = findLoadBalancerListenerPolicyByThreePartKey + FindLoadBalancerListenerPolicyByTwoPartKey = findLoadBalancerListenerPolicyByTwoPartKey FindLoadBalancerPolicyByTwoPartKey = findLoadBalancerPolicyByTwoPartKey HostedZoneIDPerRegionMap = hostedZoneIDPerRegionMap LBCookieStickinessPolicyParseResourceID = lbCookieStickinessPolicyParseResourceID + ListenerPolicyParseResourceID = listenerPolicyParseResourceID SSLNegotiationPolicyParseResourceID = sslNegotiationPolicyParseResourceID ) diff --git a/internal/service/elb/listener_policy.go b/internal/service/elb/listener_policy.go index dc0bec8dd66..e1d2235ba21 100644 --- a/internal/service/elb/listener_policy.go +++ b/internal/service/elb/listener_policy.go @@ -21,8 +21,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_load_balancer_listener_policy") -func ResourceListenerPolicy() *schema.Resource { +// @SDKResource("aws_load_balancer_listener_policy", name="Listener Policy") +func resourceListenerPolicy() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceListenerPolicySet, ReadWithoutTimeout: resourceListenerPolicyRead, @@ -58,7 +58,7 @@ func resourceListenerPolicySet(ctx context.Context, d *schema.ResourceData, meta lbName := d.Get("load_balancer_name").(string) lbPort := d.Get("load_balancer_port").(int) - id := ListenerPolicyCreateResourceID(lbName, lbPort) + id := listenerPolicyCreateResourceID(lbName, lbPort) input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(lbName), LoadBalancerPort: int32(lbPort), @@ -74,7 +74,9 @@ func resourceListenerPolicySet(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "setting ELB Classic Listener Policy (%s): %s", id, err) } - d.SetId(id) + if d.IsNewResource() { + d.SetId(id) + } return append(diags, resourceListenerPolicyRead(ctx, d, meta)...) } @@ -83,13 +85,12 @@ func resourceListenerPolicyRead(ctx context.Context, d *schema.ResourceData, met var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, lbPort, err := ListenerPolicyParseResourceID(d.Id()) - + lbName, lbPort, err := listenerPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } - policyNames, err := FindLoadBalancerListenerPolicyByTwoPartKey(ctx, conn, lbName, lbPort) + policyNames, err := findLoadBalancerListenerPolicyByTwoPartKey(ctx, conn, lbName, lbPort) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ELB Classic Listener Policy (%s) not found, removing from state", d.Id()) @@ -112,10 +113,9 @@ func resourceListenerPolicyDelete(ctx context.Context, d *schema.ResourceData, m var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, lbPort, err := ListenerPolicyParseResourceID(d.Id()) - + lbName, lbPort, err := listenerPolicyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ @@ -134,7 +134,7 @@ func resourceListenerPolicyDelete(ctx context.Context, d *schema.ResourceData, m return diags } -func FindLoadBalancerListenerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, lbPort int) ([]string, error) { +func findLoadBalancerListenerPolicyByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName string, lbPort int) ([]string, error) { lb, err := findLoadBalancerByName(ctx, conn, lbName) if err != nil { @@ -156,14 +156,14 @@ func FindLoadBalancerListenerPolicyByTwoPartKey(ctx context.Context, conn *elast const listenerPolicyResourceIDSeparator = ":" -func ListenerPolicyCreateResourceID(lbName string, lbPort int) string { +func listenerPolicyCreateResourceID(lbName string, lbPort int) string { parts := []string{lbName, strconv.Itoa(lbPort)} id := strings.Join(parts, listenerPolicyResourceIDSeparator) return id } -func ListenerPolicyParseResourceID(id string) (string, int, error) { +func listenerPolicyParseResourceID(id string) (string, int, error) { parts := strings.Split(id, listenerPolicyResourceIDSeparator) if len(parts) == 2 && parts[0] != "" && parts[1] != "" { diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index 76552ced568..f2fa62b2a13 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -76,8 +76,9 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka Name: "Backend Server Policy", }, { - Factory: ResourceListenerPolicy, + Factory: resourceListenerPolicy, TypeName: "aws_load_balancer_listener_policy", + Name: "Listener Policy", }, { Factory: ResourcePolicy, From a0a1464184b04586682e26fb920faeec6b42cc46 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 15:32:45 -0400 Subject: [PATCH 24/37] r/aws_load_balancer_policy: Reduce visibility. --- internal/service/elb/exports_test.go | 2 + internal/service/elb/policy.go | 240 +++++++++----------- internal/service/elb/policy_test.go | 6 - internal/service/elb/service_package_gen.go | 3 +- 4 files changed, 111 insertions(+), 140 deletions(-) diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index 199cc5edf4c..282231c0608 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -10,6 +10,7 @@ var ( ResourceBackendServerPolicy = resourceBackendServerPolicy ResourceCookieStickinessPolicy = resourceCookieStickinessPolicy ResourceListenerPolicy = resourceListenerPolicy + ResourcePolicy = resourcePolicy ResourceSSLNegotiationPolicy = resourceSSLNegotiationPolicy AppCookieStickinessPolicyParseResourceID = appCookieStickinessPolicyParseResourceID @@ -23,5 +24,6 @@ var ( HostedZoneIDPerRegionMap = hostedZoneIDPerRegionMap LBCookieStickinessPolicyParseResourceID = lbCookieStickinessPolicyParseResourceID ListenerPolicyParseResourceID = listenerPolicyParseResourceID + PolicyParseResourceID = policyParseResourceID SSLNegotiationPolicyParseResourceID = sslNegotiationPolicyParseResourceID ) diff --git a/internal/service/elb/policy.go b/internal/service/elb/policy.go index db4199011f7..64319c7f8ed 100644 --- a/internal/service/elb/policy.go +++ b/internal/service/elb/policy.go @@ -7,22 +7,24 @@ import ( "context" "fmt" "log" + "slices" "strings" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_load_balancer_policy") -func ResourcePolicy() *schema.Resource { +// @SDKResource("aws_load_balancer_policy", name="Load Balancer Policy") +func resourcePolicy() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourcePolicyCreate, ReadWithoutTimeout: resourcePolicyRead, @@ -79,7 +81,7 @@ func resourcePolicyCreate(ctx context.Context, d *schema.ResourceData, meta inte lbName := d.Get("load_balancer_name").(string) policyName := d.Get("policy_name").(string) - id := PolicyCreateResourceID(lbName, policyName) + id := policyCreateResourceID(lbName, policyName) input := &elasticloadbalancing.CreateLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), @@ -105,10 +107,9 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, policyName, err := PolicyParseResourceID(d.Id()) - + lbName, policyName, err := policyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } policy, err := findLoadBalancerPolicyByTwoPartKey(ctx, conn, lbName, policyName) @@ -136,49 +137,58 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - reassignments := Reassignment{} - - lbName, policyName, err := PolicyParseResourceID(d.Id()) + lbName, policyName, err := policyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) + return sdkdiag.AppendFromErr(diags, err) } - assigned, err := resourcePolicyAssigned(ctx, policyName, lbName, conn) - if err != nil { - return sdkdiag.AppendErrorf(diags, "determining assignment status of Load Balancer Policy %s: %s", policyName, err) - } + reassignments := &policyReassignments{} + + err = findPolicyAttachmentByTwoPartKey(ctx, conn, lbName, policyName) + switch { + case tfresource.NotFound(err): + // Policy not attached. + case err != nil: + return sdkdiag.AppendErrorf(diags, "reading ELB Classic Load Balancer Policy Attachment (%s/%s): %s", lbName, policyName, err) + default: + reassignments, err = unassignPolicy(ctx, conn, lbName, policyName) - if assigned { - reassignments, err = resourcePolicyUnassign(ctx, policyName, lbName, conn) if err != nil { - return sdkdiag.AppendErrorf(diags, "unassigning Load Balancer Policy %s: %s", policyName, err) + return sdkdiag.AppendFromErr(diags, err) } } - request := &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ + input := &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), } - if _, err := conn.DeleteLoadBalancerPolicy(ctx, request); err != nil { - return sdkdiag.AppendErrorf(diags, "deleting Load Balancer Policy %s: %s", d.Id(), err) + _, err = conn.DeleteLoadBalancerPolicy(ctx, input) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "deleting ELB Classic Load Balancer Policy (%s): %s", d.Id(), err) } diags = append(diags, sdkdiag.WrapDiagsf(resourcePolicyCreate(ctx, d, meta), "updating ELB Classic Policy (%s)", d.Id())...) + if diags.HasError() { return diags } - for _, listenerAssignment := range reassignments.listenerPolicies { - if _, err := conn.SetLoadBalancerPoliciesOfListener(ctx, listenerAssignment); err != nil { - return sdkdiag.AppendErrorf(diags, "setting LoadBalancerPoliciesOfListener: %s", err) + for _, input := range reassignments.listenerPolicies { + _, err := conn.SetLoadBalancerPoliciesOfListener(ctx, input) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "setting ELB Classic Listener Policy (%s): %s", lbName, err) } } - for _, backendServerAssignment := range reassignments.backendServerPolicies { - if _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, backendServerAssignment); err != nil { - return sdkdiag.AppendErrorf(diags, "setting LoadBalancerPoliciesForBackendServer: %s", err) + for _, input := range reassignments.backendServerPolicies { + _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, input) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "setting ELB Classic Backend Server Policy (%s): %s", lbName, err) } } @@ -189,164 +199,128 @@ func resourcePolicyDelete(ctx context.Context, d *schema.ResourceData, meta inte var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - lbName, policyName, err := PolicyParseResourceID(d.Id()) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "parsing resource ID: %s", err) - } - - assigned, err := resourcePolicyAssigned(ctx, policyName, lbName, conn) + lbName, policyName, err := policyParseResourceID(d.Id()) if err != nil { - return sdkdiag.AppendErrorf(diags, "determining assignment status of Load Balancer Policy %s: %s", policyName, err) - } - - if assigned { - _, err := resourcePolicyUnassign(ctx, policyName, lbName, conn) - if err != nil { - return sdkdiag.AppendErrorf(diags, "unassigning Load Balancer Policy %s: %s", policyName, err) + return sdkdiag.AppendFromErr(diags, err) + } + + err = findPolicyAttachmentByTwoPartKey(ctx, conn, lbName, policyName) + switch { + case tfresource.NotFound(err): + // Policy not attached. + case err != nil: + return sdkdiag.AppendErrorf(diags, "reading ELB Classic Load Balancer Policy Attachment (%s/%s): %s", lbName, policyName, err) + default: + if _, err := unassignPolicy(ctx, conn, lbName, policyName); err != nil { + return sdkdiag.AppendFromErr(diags, err) } } - request := &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ + log.Printf("[DEBUG] Deleting ELB Classic Load Balancer Policy: %s", d.Id()) + _, err = conn.DeleteLoadBalancerPolicy(ctx, &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), - } + }) - if _, err := conn.DeleteLoadBalancerPolicy(ctx, request); err != nil { + if err != nil { return sdkdiag.AppendErrorf(diags, "deleting ELB Classic Load Balancer Policy (%s): %s", d.Id(), err) } return diags } -func resourcePolicyAssigned(ctx context.Context, policyName, loadBalancerName string, conn *elasticloadbalancing.Client) (bool, error) { - describeElbOpts := &elasticloadbalancing.DescribeLoadBalancersInput{ - LoadBalancerNames: []string{loadBalancerName}, - } - - describeResp, err := conn.DescribeLoadBalancers(ctx, describeElbOpts) - - if errs.IsA[*awstypes.AccessPointNotFoundException](err) { - return false, nil - } +func findPolicyAttachmentByTwoPartKey(ctx context.Context, conn *elasticloadbalancing.Client, lbName, policyName string) error { + lb, err := findLoadBalancerByName(ctx, conn, lbName) if err != nil { - return false, fmt.Errorf("retrieving ELB description: %s", err) + return err } - if len(describeResp.LoadBalancerDescriptions) != 1 { - return false, fmt.Errorf("Unable to find ELB: %#v", describeResp.LoadBalancerDescriptions) - } + attached := slices.ContainsFunc(lb.BackendServerDescriptions, func(v awstypes.BackendServerDescription) bool { + return slices.Contains(v.PolicyNames, policyName) + }) - lb := describeResp.LoadBalancerDescriptions[0] - assigned := false - for _, backendServer := range lb.BackendServerDescriptions { - for _, name := range backendServer.PolicyNames { - if policyName == name { - assigned = true - break - } - } + if attached { + return nil } - for _, listener := range lb.ListenerDescriptions { - for _, name := range listener.PolicyNames { - if policyName == name { - assigned = true - break - } - } + attached = slices.ContainsFunc(lb.ListenerDescriptions, func(v awstypes.ListenerDescription) bool { + return slices.Contains(v.PolicyNames, policyName) + }) + + if attached { + return nil } - return assigned, nil + return &retry.NotFoundError{} } -type Reassignment struct { +type policyReassignments struct { backendServerPolicies []*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput listenerPolicies []*elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput } -func resourcePolicyUnassign(ctx context.Context, policyName, loadBalancerName string, conn *elasticloadbalancing.Client) (Reassignment, error) { - reassignments := Reassignment{} - - describeElbOpts := &elasticloadbalancing.DescribeLoadBalancersInput{ - LoadBalancerNames: []string{loadBalancerName}, - } +func unassignPolicy(ctx context.Context, conn *elasticloadbalancing.Client, lbName, policyName string) (*policyReassignments, error) { + reassignments := &policyReassignments{} - describeResp, err := conn.DescribeLoadBalancers(ctx, describeElbOpts) + lb, err := findLoadBalancerByName(ctx, conn, lbName) - if errs.IsA[*awstypes.AccessPointNotFoundException](err) { + if tfresource.NotFound(err) { return reassignments, nil } if err != nil { - return reassignments, fmt.Errorf("retrieving ELB description: %s", err) + return nil, err } - if len(describeResp.LoadBalancerDescriptions) != 1 { - return reassignments, fmt.Errorf("Unable to find ELB: %#v", describeResp.LoadBalancerDescriptions) - } - - lb := describeResp.LoadBalancerDescriptions[0] - - for _, backendServer := range lb.BackendServerDescriptions { - policies := []string{} + for _, v := range lb.BackendServerDescriptions { + policies := tfslices.Filter(v.PolicyNames, func(v string) bool { + return v != policyName + }) - for _, name := range backendServer.PolicyNames { - if policyName != name { - policies = append(policies, name) - } - } + if len(v.PolicyNames) != len(policies) { + reassignments.backendServerPolicies = append(reassignments.backendServerPolicies, &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ + InstancePort: v.InstancePort, + LoadBalancerName: aws.String(lbName), + PolicyNames: v.PolicyNames, + }) - if len(backendServer.PolicyNames) != len(policies) { - setOpts := &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ - LoadBalancerName: aws.String(loadBalancerName), - InstancePort: backendServer.InstancePort, + input := &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ + InstancePort: v.InstancePort, + LoadBalancerName: aws.String(lbName), PolicyNames: policies, } - reassignOpts := &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ - LoadBalancerName: aws.String(loadBalancerName), - InstancePort: backendServer.InstancePort, - PolicyNames: backendServer.PolicyNames, - } + _, err = conn.SetLoadBalancerPoliciesForBackendServer(ctx, input) - reassignments.backendServerPolicies = append(reassignments.backendServerPolicies, reassignOpts) - - _, err = conn.SetLoadBalancerPoliciesForBackendServer(ctx, setOpts) if err != nil { - return reassignments, fmt.Errorf("Setting Load Balancer Policies for Backend Server: %s", err) + return nil, fmt.Errorf("setting ELB Classic Backend Server Policy (%s): %w", lbName, err) } } } - for _, listener := range lb.ListenerDescriptions { - policies := []string{} + for _, v := range lb.ListenerDescriptions { + policies := tfslices.Filter(v.PolicyNames, func(v string) bool { + return v != policyName + }) - for _, name := range listener.PolicyNames { - if policyName != name { - policies = append(policies, name) - } - } + if len(v.PolicyNames) != len(policies) { + reassignments.listenerPolicies = append(reassignments.listenerPolicies, &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ + LoadBalancerName: aws.String(lbName), + LoadBalancerPort: v.Listener.LoadBalancerPort, + PolicyNames: v.PolicyNames, + }) - if len(listener.PolicyNames) != len(policies) { - setOpts := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ - LoadBalancerName: aws.String(loadBalancerName), - LoadBalancerPort: listener.Listener.LoadBalancerPort, + input := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ + LoadBalancerName: aws.String(lbName), + LoadBalancerPort: v.Listener.LoadBalancerPort, PolicyNames: policies, } - reassignOpts := &elasticloadbalancing.SetLoadBalancerPoliciesOfListenerInput{ - LoadBalancerName: aws.String(loadBalancerName), - LoadBalancerPort: listener.Listener.LoadBalancerPort, - PolicyNames: listener.PolicyNames, - } - - reassignments.listenerPolicies = append(reassignments.listenerPolicies, reassignOpts) + _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, input) - _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, setOpts) if err != nil { - return reassignments, fmt.Errorf("Setting Load Balancer Policies of Listener: %s", err) + return reassignments, fmt.Errorf("setting ELB Classic Listener Policy (%s): %w", lbName, err) } } } @@ -375,14 +349,14 @@ func suppressPolicyAttributeDiffs(k, old, new string, d *schema.ResourceData) bo const policyResourceIDSeparator = ":" -func PolicyCreateResourceID(lbName, policyName string) string { +func policyCreateResourceID(lbName, policyName string) string { parts := []string{lbName, policyName} id := strings.Join(parts, policyResourceIDSeparator) return id } -func PolicyParseResourceID(id string) (string, string, error) { +func policyParseResourceID(id string) (string, string, error) { parts := strings.Split(id, backendServerPolicyResourceIDSeparator) if len(parts) == 2 && parts[0] != "" && parts[1] != "" { diff --git a/internal/service/elb/policy_test.go b/internal/service/elb/policy_test.go index 361225035e1..e5a384beb44 100644 --- a/internal/service/elb/policy_test.go +++ b/internal/service/elb/policy_test.go @@ -242,12 +242,7 @@ func testAccCheckPolicyExists(ctx context.Context, n string, v *awstypes.PolicyD return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No ELB Classic Load Balancer Policy is set") - } - lbName, policyName, err := tfelb.PolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -276,7 +271,6 @@ func testAccCheckPolicyDestroy(ctx context.Context) resource.TestCheckFunc { } lbName, policyName, err := tfelb.PolicyParseResourceID(rs.Primary.ID) - if err != nil { return err } diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index f2fa62b2a13..8d1de8ab2df 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -81,8 +81,9 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka Name: "Listener Policy", }, { - Factory: ResourcePolicy, + Factory: resourcePolicy, TypeName: "aws_load_balancer_policy", + Name: "Load Balancer Policy", }, { Factory: ResourceProxyProtocolPolicy, From d20b149bee2c866b7acd522bb875d12eddf22876 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 15:40:54 -0400 Subject: [PATCH 25/37] d/aws_elb_service_account: Reduce visibility. --- internal/service/elb/exports_test.go | 1 + .../service/elb/hosted_zone_id_data_source.go | 7 +++--- .../elb/service_account_data_source.go | 23 ++++++++++--------- .../elb/service_account_data_source_test.go | 6 ++--- internal/service/elb/service_package_gen.go | 3 ++- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index 282231c0608..4db1c337951 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -13,6 +13,7 @@ var ( ResourcePolicy = resourcePolicy ResourceSSLNegotiationPolicy = resourceSSLNegotiationPolicy + AccountIDPerRegionMap = accountIDPerRegionMap AppCookieStickinessPolicyParseResourceID = appCookieStickinessPolicyParseResourceID BackendServerPolicyParseResourceID = backendServerPolicyParseResourceID FindLoadBalancerAttachmentByTwoPartKey = findLoadBalancerAttachmentByTwoPartKey diff --git a/internal/service/elb/hosted_zone_id_data_source.go b/internal/service/elb/hosted_zone_id_data_source.go index 5dafb0e4c3a..c81e1b38427 100644 --- a/internal/service/elb/hosted_zone_id_data_source.go +++ b/internal/service/elb/hosted_zone_id_data_source.go @@ -67,15 +67,16 @@ func dataSourceHostedZoneID() *schema.Resource { func dataSourceHostedZoneIDRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics + region := meta.(*conns.AWSClient).Region if v, ok := d.GetOk(names.AttrRegion); ok { region = v.(string) } - if zoneId, ok := hostedZoneIDPerRegionMap[region]; ok { - d.SetId(zoneId) + if v, ok := hostedZoneIDPerRegionMap[region]; ok { + d.SetId(v) return diags } - return sdkdiag.AppendErrorf(diags, "Unknown region (%s)", region) + return sdkdiag.AppendErrorf(diags, "Unknown Region (%s)", region) } diff --git a/internal/service/elb/service_account_data_source.go b/internal/service/elb/service_account_data_source.go index 85af1838277..13e7f195ef2 100644 --- a/internal/service/elb/service_account_data_source.go +++ b/internal/service/elb/service_account_data_source.go @@ -18,7 +18,7 @@ import ( // See http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html#attach-bucket-policy // See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-logging-bucket-permissions -var AccountIdPerRegionMap = map[string]string{ +var accountIDPerRegionMap = map[string]string{ endpoints.AfSouth1RegionID: "098369216593", endpoints.ApEast1RegionID: "754344448648", endpoints.ApNortheast1RegionID: "582318560864", @@ -48,37 +48,38 @@ var AccountIdPerRegionMap = map[string]string{ endpoints.UsWest2RegionID: "797873946194", } -// @SDKDataSource("aws_elb_service_account") -func DataSourceServiceAccount() *schema.Resource { +// @SDKDataSource("aws_elb_service_account", name="Service Account") +func dataSourceServiceAccount() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceServiceAccountRead, Schema: map[string]*schema.Schema{ - names.AttrRegion: { - Type: schema.TypeString, - Optional: true, - }, names.AttrARN: { Type: schema.TypeString, Computed: true, }, + names.AttrRegion: { + Type: schema.TypeString, + Optional: true, + }, }, } } func dataSourceServiceAccountRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics + region := meta.(*conns.AWSClient).Region if v, ok := d.GetOk(names.AttrRegion); ok { region = v.(string) } - if accid, ok := AccountIdPerRegionMap[region]; ok { - d.SetId(accid) + if v, ok := accountIDPerRegionMap[region]; ok { + d.SetId(v) arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, Service: "iam", - AccountID: accid, + AccountID: v, Resource: "root", }.String() d.Set(names.AttrARN, arn) @@ -86,5 +87,5 @@ func dataSourceServiceAccountRead(ctx context.Context, d *schema.ResourceData, m return diags } - return sdkdiag.AppendErrorf(diags, "Unknown region (%q)", region) + return sdkdiag.AppendErrorf(diags, "Unknown Region (%s)", region) } diff --git a/internal/service/elb/service_account_data_source_test.go b/internal/service/elb/service_account_data_source_test.go index ebc5f1065e0..a08dfffacaa 100644 --- a/internal/service/elb/service_account_data_source_test.go +++ b/internal/service/elb/service_account_data_source_test.go @@ -14,8 +14,7 @@ import ( func TestAccELBServiceAccountDataSource_basic(t *testing.T) { ctx := acctest.Context(t) - expectedAccountID := tfelb.AccountIdPerRegionMap[acctest.Region()] - + expectedAccountID := tfelb.AccountIDPerRegionMap[acctest.Region()] dataSourceName := "data.aws_elb_service_account.main" resource.ParallelTest(t, resource.TestCase{ @@ -36,8 +35,7 @@ func TestAccELBServiceAccountDataSource_basic(t *testing.T) { func TestAccELBServiceAccountDataSource_region(t *testing.T) { ctx := acctest.Context(t) - expectedAccountID := tfelb.AccountIdPerRegionMap[acctest.Region()] - + expectedAccountID := tfelb.AccountIDPerRegionMap[acctest.Region()] dataSourceName := "data.aws_elb_service_account.regional" resource.ParallelTest(t, resource.TestCase{ diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index 8d1de8ab2df..bcc6149c17d 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -34,8 +34,9 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Name: "Hosted Zone ID", }, { - Factory: DataSourceServiceAccount, + Factory: dataSourceServiceAccount, TypeName: "aws_elb_service_account", + Name: "Service Account", }, } } From 542881fe831e2215da0aa2c027d0f8eca6f5e9b8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 16:44:14 -0400 Subject: [PATCH 26/37] r/aws_proxy_protocol_policy: Reduce visibility. --- internal/flex/flex.go | 23 +- internal/service/elb/exports_test.go | 2 + internal/service/elb/flex.go | 2 +- internal/service/elb/proxy_protocol_policy.go | 246 +++++++++--------- .../service/elb/proxy_protocol_policy_test.go | 70 ++--- internal/service/elb/service_package_gen.go | 3 +- internal/verify/validate.go | 12 + 7 files changed, 176 insertions(+), 182 deletions(-) diff --git a/internal/flex/flex.go b/internal/flex/flex.go index 510eea82422..cabd68647d7 100644 --- a/internal/flex/flex.go +++ b/internal/flex/flex.go @@ -425,11 +425,16 @@ func IntValueToString(v int) *string { return aws.String(strconv.Itoa(v)) } -// Int64ToStringValue converts an int64 pointer to a Go string value. +// Int32ToStringValue converts an int32 pointer to a Go string value. func Int32ToStringValue(v *int32) string { return strconv.FormatInt(int64(aws.Int32Value(v)), 10) } +// Int32ValueToStringValue converts an int32 value to a Go string value. +func Int32ValueToStringValue(v int32) string { + return strconv.FormatInt(int64(v), 10) +} + // Int64ToStringValue converts an int64 pointer to a Go string value. func Int64ToStringValue(v *int64) string { return strconv.FormatInt(aws.Int64Value(v), 10) @@ -450,8 +455,7 @@ func StringToIntValue(v *string) int { // StringToInt32Value converts a string pointer to a Go int32 value. // Invalid integer strings are converted to 0. func StringToInt32Value(v *string) int32 { - i, _ := strconv.ParseInt(aws.StringValue(v), 0, 32) - return int32(i) + return StringValueToInt32Value(aws.StringValue(v)) } // StringValueToBase64String converts a string to a Go base64 string pointer. @@ -459,6 +463,19 @@ func StringValueToBase64String(v string) *string { return aws.String(itypes.Base64EncodeOnce([]byte(v))) } +// StringValueToInt64 converts a string to a Go int32 pointer. +// Invalid integer strings are converted to 0. +func StringValueToInt32(v string) *int32 { + return aws.Int32(StringValueToInt32Value(v)) +} + +// StringValueToInt32Value converts a string to a Go int32 value. +// Invalid integer strings are converted to 0. +func StringValueToInt32Value(v string) int32 { + i, _ := strconv.ParseInt(v, 0, 32) + return int32(i) +} + // StringValueToInt64 converts a string to a Go int64 pointer. // Invalid integer strings are converted to 0. func StringValueToInt64(v string) *int64 { diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index 4db1c337951..ba59877a467 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -11,6 +11,7 @@ var ( ResourceCookieStickinessPolicy = resourceCookieStickinessPolicy ResourceListenerPolicy = resourceListenerPolicy ResourcePolicy = resourcePolicy + ResourceProxyProtocolPolicy = resourceProxyProtocolPolicy ResourceSSLNegotiationPolicy = resourceSSLNegotiationPolicy AccountIDPerRegionMap = accountIDPerRegionMap @@ -26,5 +27,6 @@ var ( LBCookieStickinessPolicyParseResourceID = lbCookieStickinessPolicyParseResourceID ListenerPolicyParseResourceID = listenerPolicyParseResourceID PolicyParseResourceID = policyParseResourceID + ProxyProtocolPolicyParseResourceID = proxyProtocolPolicyParseResourceID SSLNegotiationPolicyParseResourceID = sslNegotiationPolicyParseResourceID ) diff --git a/internal/service/elb/flex.go b/internal/service/elb/flex.go index 8ebcbd5facb..b980d87ba91 100644 --- a/internal/service/elb/flex.go +++ b/internal/service/elb/flex.go @@ -41,7 +41,7 @@ func flattenAccessLog(apiObject *awstypes.AccessLog) []interface{} { return tfList } -func flattenBackendPolicies(apiObjects []awstypes.BackendServerDescription) map[int32][]string { +func flattenBackendServerDescriptionPolicies(apiObjects []awstypes.BackendServerDescription) map[int32][]string { tfMap := make(map[int32][]string) for _, apiObject := range apiObjects { diff --git a/internal/service/elb/proxy_protocol_policy.go b/internal/service/elb/proxy_protocol_policy.go index 84b07e6d236..7de74b0f3db 100644 --- a/internal/service/elb/proxy_protocol_policy.go +++ b/internal/service/elb/proxy_protocol_policy.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "log" - "strconv" "strings" "github.com/aws/aws-sdk-go-v2/aws" @@ -16,12 +15,16 @@ import ( "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" - "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + "github.com/hashicorp/terraform-provider-aws/internal/flex" + tfmaps "github.com/hashicorp/terraform-provider-aws/internal/maps" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -// @SDKResource("aws_proxy_protocol_policy") -func ResourceProxyProtocolPolicy() *schema.Resource { +// @SDKResource("aws_proxy_protocol_policy", name="Proxy Protocol Policy") +func resourceProxyProtocolPolicy() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceProxyProtocolPolicyCreate, ReadWithoutTimeout: resourceProxyProtocolPolicyRead, @@ -29,16 +32,17 @@ func ResourceProxyProtocolPolicy() *schema.Resource { DeleteWithoutTimeout: resourceProxyProtocolPolicyDelete, Schema: map[string]*schema.Schema{ - "load_balancer": { - Type: schema.TypeString, - Required: true, - }, - "instance_ports": { Type: schema.TypeSet, - Elem: &schema.Schema{Type: schema.TypeString}, Required: true, - Set: schema.HashString, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: verify.StringIsInt32, + }, + }, + "load_balancer": { + Type: schema.TypeString, + Required: true, }, }, } @@ -47,10 +51,10 @@ func ResourceProxyProtocolPolicy() *schema.Resource { func resourceProxyProtocolPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - elbname := aws.String(d.Get("load_balancer").(string)) + lbName := d.Get("load_balancer").(string) input := &elasticloadbalancing.CreateLoadBalancerPolicyInput{ - LoadBalancerName: elbname, + LoadBalancerName: aws.String(lbName), PolicyAttributes: []awstypes.PolicyAttribute{ { AttributeName: aws.String("ProxyProtocol"), @@ -61,15 +65,13 @@ func resourceProxyProtocolPolicyCreate(ctx context.Context, d *schema.ResourceDa PolicyTypeName: aws.String("ProxyProtocolPolicyType"), } - // Create a policy - log.Printf("[DEBUG] ELB create a policy %s from policy type %s", - *input.PolicyName, *input.PolicyTypeName) + _, err := conn.CreateLoadBalancerPolicy(ctx, input) - if _, err := conn.CreateLoadBalancerPolicy(ctx, input); err != nil { - return sdkdiag.AppendErrorf(diags, "creating a policy %s: %s", aws.ToString(input.PolicyName), err) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating ELB Classic Proxy Protocol Policy (%s): %s", lbName, err) } - d.SetId(fmt.Sprintf("%s:%s", *elbname, *input.PolicyName)) + d.SetId(proxyProtocolPolicyCreateResourceID(lbName, aws.ToString(input.PolicyName))) return append(diags, resourceProxyProtocolPolicyUpdate(ctx, d, meta)...) } @@ -77,76 +79,64 @@ func resourceProxyProtocolPolicyCreate(ctx context.Context, d *schema.ResourceDa func resourceProxyProtocolPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - elbname := d.Get("load_balancer").(string) - // Retrieve the current ELB policies for updating the state - req := &elasticloadbalancing.DescribeLoadBalancersInput{ - LoadBalancerNames: []string{elbname}, - } - resp, err := conn.DescribeLoadBalancers(ctx, req) + lbName, _, err := proxyProtocolPolicyParseResourceID(d.Id()) if err != nil { - if !d.IsNewResource() && errs.IsA[*awstypes.AccessPointNotFoundException](err) { - log.Printf("[WARN] ELB Classic Proxy Protocol Policy (%s) not found, removing from state", d.Id()) - d.SetId("") - return diags - } - return sdkdiag.AppendErrorf(diags, "retrieving ELB attributes: %s", err) + return sdkdiag.AppendFromErr(diags, err) } - backends := flattenBackendPolicies(resp.LoadBalancerDescriptions[0].BackendServerDescriptions) + lb, err := findLoadBalancerByName(ctx, conn, lbName) + + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] ELB Classic Proxy Protocol Policy (%s) not found, removing from state", d.Id()) + d.SetId("") + return diags + } - ports := []*string{} - for ip := range backends { - ipstr := strconv.Itoa(int(ip)) - ports = append(ports, &ipstr) + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading ELB Classic Load Balancer (%s): %s", lbName, err) } + + ports := tfslices.ApplyToAll(tfmaps.Keys(flattenBackendServerDescriptionPolicies(lb.BackendServerDescriptions)), flex.Int32ValueToStringValue) d.Set("instance_ports", ports) - d.Set("load_balancer", elbname) + d.Set("load_balancer", lbName) + return diags } func resourceProxyProtocolPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - elbname := aws.String(d.Get("load_balancer").(string)) - // Retrieve the current ELB policies for updating the state - req := &elasticloadbalancing.DescribeLoadBalancersInput{ - LoadBalancerNames: []string{*elbname}, + lbName, policyName, err := proxyProtocolPolicyParseResourceID(d.Id()) + if err != nil { + return sdkdiag.AppendFromErr(diags, err) } - resp, err := conn.DescribeLoadBalancers(ctx, req) + + lb, err := findLoadBalancerByName(ctx, conn, lbName) + if err != nil { - return sdkdiag.AppendErrorf(diags, "retrieving ELB attributes: %s", err) + return sdkdiag.AppendErrorf(diags, "reading ELB Classic Load Balancer (%s): %s", lbName, err) } - backends := flattenBackendPolicies(resp.LoadBalancerDescriptions[0].BackendServerDescriptions) - policyName := resourceProxyProtocolPolicyParseID(d.Id()) + backendPolicies := flattenBackendServerDescriptionPolicies(lb.BackendServerDescriptions) if d.HasChange("instance_ports") { o, n := d.GetChange("instance_ports") - os := o.(*schema.Set) - ns := n.(*schema.Set) - remove := os.Difference(ns).List() - add := ns.Difference(os).List() + os, ns := o.(*schema.Set), n.(*schema.Set) + add, del := ns.Difference(os), os.Difference(ns) - inputs := []*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{} + var inputs []*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput + inputs = append(inputs, expandRemoveProxyProtocolPolicyInputs(policyName, flex.ExpandStringValueSet(del), backendPolicies)...) + inputs = append(inputs, expandAddProxyProtocolPolicyInputs(policyName, flex.ExpandStringValueSet(add), backendPolicies)...) - i, err := resourceProxyProtocolPolicyRemove(policyName, remove, backends) - if err != nil { - return sdkdiag.AppendErrorf(diags, "updating ELB Classic Proxy Protocol Policy (%s): %s", d.Id(), err) - } - inputs = append(inputs, i...) + for _, input := range inputs { + input.LoadBalancerName = aws.String(lbName) - i, err = resourceProxyProtocolPolicyAdd(policyName, add, backends) - if err != nil { - return sdkdiag.AppendErrorf(diags, "updating ELB Classic Proxy Protocol Policy (%s): %s", d.Id(), err) - } - inputs = append(inputs, i...) + _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, input) - for _, input := range inputs { - input.LoadBalancerName = elbname - if _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, input); err != nil { - return sdkdiag.AppendErrorf(diags, "setting policy for backend: %s", err) + if err != nil { + return sdkdiag.AppendErrorf(diags, "setting ELB Classic Backend Server Policy (%s): %s", lbName, err) } } } @@ -157,112 +147,118 @@ func resourceProxyProtocolPolicyUpdate(ctx context.Context, d *schema.ResourceDa func resourceProxyProtocolPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ELBClient(ctx) - elbname := aws.String(d.Get("load_balancer").(string)) - // Retrieve the current ELB policies for updating the state - req := &elasticloadbalancing.DescribeLoadBalancersInput{ - LoadBalancerNames: []string{*elbname}, - } - resp, err := conn.DescribeLoadBalancers(ctx, req) + lbName, policyName, err := proxyProtocolPolicyParseResourceID(d.Id()) if err != nil { - if errs.IsA[*awstypes.AccessPointNotFoundException](err) { - return diags - } - return sdkdiag.AppendErrorf(diags, "retrieving ELB attributes: %s", err) + return sdkdiag.AppendFromErr(diags, err) } - backends := flattenBackendPolicies(resp.LoadBalancerDescriptions[0].BackendServerDescriptions) - ports := d.Get("instance_ports").(*schema.Set).List() - policyName := resourceProxyProtocolPolicyParseID(d.Id()) + lb, err := findLoadBalancerByName(ctx, conn, lbName) + + if tfresource.NotFound(err) { + return diags + } - inputs, err := resourceProxyProtocolPolicyRemove(policyName, ports, backends) if err != nil { - return sdkdiag.AppendErrorf(diags, "deleting ELB Classic Proxy Protocol Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading ELB Classic Load Balancer (%s): %s", lbName, err) } - for _, input := range inputs { - input.LoadBalancerName = elbname - if _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, input); err != nil { - return sdkdiag.AppendErrorf(diags, "setting policy for backend: %s", err) + + backendPolicies := flattenBackendServerDescriptionPolicies(lb.BackendServerDescriptions) + ports := flex.ExpandStringValueSet(d.Get("instance_ports").(*schema.Set)) + + for _, input := range expandRemoveProxyProtocolPolicyInputs(policyName, ports, backendPolicies) { + input.LoadBalancerName = aws.String(lbName) + + _, err := conn.SetLoadBalancerPoliciesForBackendServer(ctx, input) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "setting ELB Classic Backend Server Policy (%s): %s", lbName, err) } } - pOpt := &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ - LoadBalancerName: elbname, + _, err = conn.DeleteLoadBalancerPolicy(ctx, &elasticloadbalancing.DeleteLoadBalancerPolicyInput{ + LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), - } - if _, err := conn.DeleteLoadBalancerPolicy(ctx, pOpt); err != nil { - return sdkdiag.AppendErrorf(diags, "removing a policy from load balancer: %s", err) + }) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "deleting ELB Classic Proxy Protocol Policy (%s): %s", lbName, err) } return diags } -func resourceProxyProtocolPolicyRemove(policyName string, ports []interface{}, backends map[int32][]string) ([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, error) { - inputs := make([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, 0, len(ports)) +func expandAddProxyProtocolPolicyInputs(policyName string, ports []string, backendPolicies map[int32][]string) []*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput { + apiObjects := make([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, 0, len(ports)) + for _, p := range ports { - ip, err := strconv.ParseInt(p.(string), 10, 32) - ip32 := int32(ip) - if err != nil { - return nil, fmt.Errorf("detaching the policy: %s", err) - } + port := flex.StringValueToInt32Value(p) newPolicies := []string{} - curPolicies, found := backends[ip32] - if !found { - // No policy for this instance port found, just skip it. - continue - } - + curPolicies := backendPolicies[port] for _, p := range curPolicies { if p == policyName { - // remove the policy + // Just remove it for now. It will be back later. continue } + newPolicies = append(newPolicies, p) } + newPolicies = append(newPolicies, policyName) - inputs = append(inputs, &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ - InstancePort: &ip32, + apiObjects = append(apiObjects, &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ + InstancePort: aws.Int32(port), PolicyNames: newPolicies, }) } - return inputs, nil + return apiObjects } -func resourceProxyProtocolPolicyAdd(policyName string, ports []interface{}, backends map[int32][]string) ([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, error) { - inputs := make([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, 0, len(ports)) +func expandRemoveProxyProtocolPolicyInputs(policyName string, ports []string, backendPolicies map[int32][]string) []*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput { + apiObjects := make([]*elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput, 0, len(ports)) + for _, p := range ports { - ip, err := strconv.ParseInt(p.(string), 10, 64) - ip32 := int32(ip) + port := flex.StringValueToInt32Value(p) - if err != nil { - return nil, fmt.Errorf("attaching the policy: %s", err) + newPolicies := []string{} + curPolicies, found := backendPolicies[port] + if !found { + // No policy for this instance port found, just skip it. + continue } - newPolicies := []string{} - curPolicies := backends[ip32] for _, p := range curPolicies { if p == policyName { - // Just remove it for now. It will be back later. + // remove the policy continue } newPolicies = append(newPolicies, p) } - newPolicies = append(newPolicies, policyName) - inputs = append(inputs, &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ - InstancePort: &ip32, + apiObjects = append(apiObjects, &elasticloadbalancing.SetLoadBalancerPoliciesForBackendServerInput{ + InstancePort: aws.Int32(port), PolicyNames: newPolicies, }) } - return inputs, nil + + return apiObjects +} + +const proxyProtocolPolicyResourceIDSeparator = ":" + +func proxyProtocolPolicyCreateResourceID(lbName, policyName string) string { + parts := []string{lbName, policyName} + id := strings.Join(parts, proxyProtocolPolicyResourceIDSeparator) + + return id } -// resourceProxyProtocolPolicyParseID takes an ID and parses it into -// it's constituent parts. You need two axes (LB name, policy name) -// to create or identify a proxy protocol policy in AWS's API. -func resourceProxyProtocolPolicyParseID(id string) string { - parts := strings.SplitN(id, ":", 2) - // We currently omit the ELB name as it is not currently used anywhere - return parts[1] +func proxyProtocolPolicyParseResourceID(id string) (string, string, error) { + parts := strings.SplitN(id, proxyProtocolPolicyResourceIDSeparator, 2) + + if len(parts) == 2 && parts[0] != "" && parts[1] != "" { + return parts[0], parts[1], nil + } + + return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected LBNAME%[2]sPOLICYNAME", id, proxyProtocolPolicyResourceIDSeparator) } diff --git a/internal/service/elb/proxy_protocol_policy_test.go b/internal/service/elb/proxy_protocol_policy_test.go index 74af1f33d41..4ad7fd71e24 100644 --- a/internal/service/elb/proxy_protocol_policy_test.go +++ b/internal/service/elb/proxy_protocol_policy_test.go @@ -4,85 +4,51 @@ package elb_test import ( - "context" "fmt" "testing" - "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" - awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccELBProxyProtocolPolicy_basic(t *testing.T) { ctx := acctest.Context(t) lbName := fmt.Sprintf("tf-test-lb-%s", sdkacctest.RandString(5)) + resourceName := "aws_proxy_protocol_policy.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.ELBServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckProxyProtocolPolicyDestroy(ctx), + CheckDestroy: acctest.CheckDestroyNoop, Steps: []resource.TestStep{ { Config: testAccProxyProtocolPolicyConfig_basic(lbName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "aws_proxy_protocol_policy.smtp", "load_balancer", lbName), - resource.TestCheckResourceAttr( - "aws_proxy_protocol_policy.smtp", "instance_ports.#", acctest.Ct1), - resource.TestCheckTypeSetElemAttr("aws_proxy_protocol_policy.smtp", "instance_ports.*", "25"), + resource.TestCheckResourceAttr(resourceName, "load_balancer", lbName), + resource.TestCheckResourceAttr(resourceName, "instance_ports.#", acctest.Ct1), + resource.TestCheckTypeSetElemAttr(resourceName, "instance_ports.*", "25"), ), }, { Config: testAccProxyProtocolPolicyConfig_update(lbName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("aws_proxy_protocol_policy.smtp", "load_balancer", lbName), - resource.TestCheckResourceAttr("aws_proxy_protocol_policy.smtp", "instance_ports.#", acctest.Ct2), - resource.TestCheckTypeSetElemAttr("aws_proxy_protocol_policy.smtp", "instance_ports.*", "25"), - resource.TestCheckTypeSetElemAttr("aws_proxy_protocol_policy.smtp", "instance_ports.*", "587"), + resource.TestCheckResourceAttr(resourceName, "load_balancer", lbName), + resource.TestCheckResourceAttr(resourceName, "instance_ports.#", acctest.Ct2), + resource.TestCheckTypeSetElemAttr(resourceName, "instance_ports.*", "25"), + resource.TestCheckTypeSetElemAttr(resourceName, "instance_ports.*", "587"), ), }, }, }) } -func testAccCheckProxyProtocolPolicyDestroy(ctx context.Context) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ELBClient(ctx) - - for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_placement_group" { - continue - } - - req := &elasticloadbalancing.DescribeLoadBalancersInput{ - LoadBalancerNames: []string{ - rs.Primary.Attributes["load_balancer"]}, - } - _, err := conn.DescribeLoadBalancers(ctx, req) - if err != nil { - // Verify the error is what we want - if errs.IsA[*awstypes.AccessPointNotFoundException](err) { - continue - } - return err - } - - return fmt.Errorf("still exists") - } - return nil - } -} - func testAccProxyProtocolPolicyConfig_basic(rName string) string { return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_elb" "lb" { - name = "%s" +resource "aws_elb" "test" { + name = %[1]q availability_zones = [data.aws_availability_zones.available.names[0]] listener { @@ -100,8 +66,8 @@ resource "aws_elb" "lb" { } } -resource "aws_proxy_protocol_policy" "smtp" { - load_balancer = aws_elb.lb.name +resource "aws_proxy_protocol_policy" "test" { + load_balancer = aws_elb.test.name instance_ports = ["25"] } `, rName)) @@ -109,8 +75,8 @@ resource "aws_proxy_protocol_policy" "smtp" { func testAccProxyProtocolPolicyConfig_update(rName string) string { return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_elb" "lb" { - name = "%s" +resource "aws_elb" "test" { + name = %[1]q availability_zones = [data.aws_availability_zones.available.names[0]] listener { @@ -128,8 +94,8 @@ resource "aws_elb" "lb" { } } -resource "aws_proxy_protocol_policy" "smtp" { - load_balancer = aws_elb.lb.name +resource "aws_proxy_protocol_policy" "test" { + load_balancer = aws_elb.test.name instance_ports = ["25", "587"] } `, rName)) diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index bcc6149c17d..e8a9a7ca166 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -87,8 +87,9 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka Name: "Load Balancer Policy", }, { - Factory: ResourceProxyProtocolPolicy, + Factory: resourceProxyProtocolPolicy, TypeName: "aws_proxy_protocol_policy", + Name: "Proxy Protocol Policy", }, } } diff --git a/internal/verify/validate.go b/internal/verify/validate.go index 1655cd758bc..ec356d4bc46 100644 --- a/internal/verify/validate.go +++ b/internal/verify/validate.go @@ -34,6 +34,18 @@ var regionRegexp = regexache.MustCompile(`^[a-z]{2}(-[a-z]+)+-\d$`) // validates all listed in https://gist.github.com/shortjared/4c1e3fe52bdfa47522cfe5b41e5d6f22 var servicePrincipalRegexp = regexache.MustCompile(`^([0-9a-z-]+\.){1,4}(amazonaws|amazon)\.com$`) +func StringIsInt32(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + + _, err := strconv.ParseInt(value, 10, 32) + if err != nil { + errors = append(errors, fmt.Errorf("%q (%q) must be a 32-bit integer", k, v)) + return + } + + return +} + func Valid4ByteASN(v interface{}, k string) (ws []string, errors []error) { value := v.(string) From 0700f9e60031793e2e0f7e5e162a2d1adc802d4e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 17:00:13 -0400 Subject: [PATCH 27/37] d/aws_elb: Reduce visibility. --- internal/service/elb/exports_test.go | 2 + internal/service/elb/load_balancer.go | 121 +++++------ .../service/elb/load_balancer_data_source.go | 9 +- internal/service/elb/load_balancer_test.go | 184 ----------------- internal/service/elb/service_package_gen.go | 5 +- internal/service/elb/validate.go | 2 +- internal/service/elb/validate_test.go | 190 +++++++++++++++++- 7 files changed, 251 insertions(+), 262 deletions(-) diff --git a/internal/service/elb/exports_test.go b/internal/service/elb/exports_test.go index ba59877a467..eab233c66de 100644 --- a/internal/service/elb/exports_test.go +++ b/internal/service/elb/exports_test.go @@ -10,6 +10,7 @@ var ( ResourceBackendServerPolicy = resourceBackendServerPolicy ResourceCookieStickinessPolicy = resourceCookieStickinessPolicy ResourceListenerPolicy = resourceListenerPolicy + ResourceLoadBalancer = resourceLoadBalancer ResourcePolicy = resourcePolicy ResourceProxyProtocolPolicy = resourceProxyProtocolPolicy ResourceSSLNegotiationPolicy = resourceSSLNegotiationPolicy @@ -25,6 +26,7 @@ var ( FindLoadBalancerPolicyByTwoPartKey = findLoadBalancerPolicyByTwoPartKey HostedZoneIDPerRegionMap = hostedZoneIDPerRegionMap LBCookieStickinessPolicyParseResourceID = lbCookieStickinessPolicyParseResourceID + ListenerHash = listenerHash ListenerPolicyParseResourceID = listenerPolicyParseResourceID PolicyParseResourceID = policyParseResourceID ProxyProtocolPolicyParseResourceID = proxyProtocolPolicyParseResourceID diff --git a/internal/service/elb/load_balancer.go b/internal/service/elb/load_balancer.go index ce29931e2cc..94b871988b6 100644 --- a/internal/service/elb/load_balancer.go +++ b/internal/service/elb/load_balancer.go @@ -38,7 +38,7 @@ import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports // @SDKResource("aws_elb", name="Classic Load Balancer") // @Tags(identifierAttribute="id") -func ResourceLoadBalancer() *schema.Resource { +func resourceLoadBalancer() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceLoadBalancerCreate, ReadWithoutTimeout: resourceLoadBalancerRead, @@ -91,7 +91,7 @@ func ResourceLoadBalancer() *schema.Resource { Type: schema.TypeInt, Optional: true, Default: 60, - ValidateFunc: ValidAccessLogsInterval, + ValidateFunc: validAccessLogsInterval, }, }, }, @@ -155,7 +155,7 @@ func ResourceLoadBalancer() *schema.Resource { names.AttrTarget: { Type: schema.TypeString, Required: true, - ValidateFunc: ValidHeathCheckTarget, + ValidateFunc: validHeathCheckTarget, }, names.AttrTimeout: { Type: schema.TypeInt, @@ -220,7 +220,7 @@ func ResourceLoadBalancer() *schema.Resource { }, }, }, - Set: ListenerHash, + Set: listenerHash, }, names.AttrName: { Type: schema.TypeString, @@ -228,7 +228,7 @@ func ResourceLoadBalancer() *schema.Resource { Computed: true, ForceNew: true, ConflictsWith: []string{names.AttrNamePrefix}, - ValidateFunc: ValidName, + ValidateFunc: validName, }, names.AttrNamePrefix: { Type: schema.TypeString, @@ -278,14 +278,14 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendFromErr(diags, err) } - elbName := create.NewNameGenerator( + lbName := create.NewNameGenerator( create.WithConfiguredName(d.Get(names.AttrName).(string)), create.WithConfiguredPrefix(d.Get(names.AttrNamePrefix).(string)), create.WithDefaultPrefix("tf-lb-"), ).Generate() input := &elasticloadbalancing.CreateLoadBalancerInput{ Listeners: listeners, - LoadBalancerName: aws.String(elbName), + LoadBalancerName: aws.String(lbName), Tags: getTagsIn(ctx), } @@ -310,10 +310,10 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, met }) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating ELB Classic Load Balancer (%s): %s", elbName, err) + return sdkdiag.AppendErrorf(diags, "creating ELB Classic Load Balancer (%s): %s", lbName, err) } - d.SetId(elbName) + d.SetId(lbName) return append(diags, resourceLoadBalancerUpdate(ctx, d, meta)...) } @@ -345,10 +345,10 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta Region: meta.(*conns.AWSClient).Region, Service: "elasticloadbalancing", AccountID: meta.(*conns.AWSClient).AccountID, - Resource: fmt.Sprintf("loadbalancer/%s", d.Id()), + Resource: "loadbalancer/" + d.Id(), } d.Set(names.AttrARN, arn.String()) - d.Set(names.AttrAvailabilityZones, flex.FlattenStringValueList(lb.AvailabilityZones)) + d.Set(names.AttrAvailabilityZones, lb.AvailabilityZones) d.Set("connection_draining", lbAttrs.ConnectionDraining.Enabled) d.Set("connection_draining_timeout", lbAttrs.ConnectionDraining.Timeout) d.Set("cross_zone_load_balancing", lbAttrs.CrossZoneLoadBalancing.Enabled) @@ -365,8 +365,8 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta d.Set("listener", flattenListenerDescriptions(lb.ListenerDescriptions)) d.Set(names.AttrName, lb.LoadBalancerName) d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(lb.LoadBalancerName))) - d.Set(names.AttrSecurityGroups, flex.FlattenStringValueList(lb.SecurityGroups)) - d.Set(names.AttrSubnets, flex.FlattenStringValueList(lb.Subnets)) + d.Set(names.AttrSecurityGroups, lb.SecurityGroups) + d.Set(names.AttrSubnets, lb.Subnets) d.Set("zone_id", lb.CanonicalHostedZoneNameID) if lb.SourceSecurityGroup != nil { @@ -402,12 +402,11 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta // API/state // See https://github.com/hashicorp/terraform/issues/10138 _, n := d.GetChange("access_logs") - elbal := lbAttrs.AccessLog - nl := n.([]interface{}) - if len(nl) == 0 && !elbal.Enabled { - elbal = nil + accessLog := lbAttrs.AccessLog + if len(n.([]interface{})) == 0 && !accessLog.Enabled { + accessLog = nil } - if err := d.Set("access_logs", flattenAccessLog(elbal)); err != nil { + if err := d.Set("access_logs", flattenAccessLog(accessLog)); err != nil { return sdkdiag.AppendErrorf(diags, "setting access_logs: %s", err) } } @@ -436,19 +435,17 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met if d.HasChange("listener") { o, n := d.GetChange("listener") - os := o.(*schema.Set) - ns := n.(*schema.Set) - - remove, _ := expandListeners(os.Difference(ns).List()) + os, ns := o.(*schema.Set), n.(*schema.Set) + del, _ := expandListeners(os.Difference(ns).List()) add, err := expandListeners(ns.Difference(os).List()) if err != nil { return sdkdiag.AppendFromErr(diags, err) } - if len(remove) > 0 { - ports := make([]int32, 0, len(remove)) - for _, listener := range remove { + if len(del) > 0 { + ports := make([]int32, 0, len(del)) + for _, listener := range del { ports = append(ports, listener.LoadBalancerPort) } @@ -498,10 +495,8 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met // balancer if d.HasChange("instances") { o, n := d.GetChange("instances") - os := o.(*schema.Set) - ns := n.(*schema.Set) - remove := expandInstances(os.Difference(ns).List()) - add := expandInstances(ns.Difference(os).List()) + os, ns := o.(*schema.Set), n.(*schema.Set) + add, del := expandInstances(ns.Difference(os).List()), expandInstances(os.Difference(ns).List()) if len(add) > 0 { input := &elasticloadbalancing.RegisterInstancesWithLoadBalancerInput{ @@ -516,9 +511,9 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } } - if len(remove) > 0 { + if len(del) > 0 { input := &elasticloadbalancing.DeregisterInstancesFromLoadBalancerInput{ - Instances: remove, + Instances: del, LoadBalancerName: aws.String(d.Id()), } @@ -549,15 +544,15 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met LoadBalancerName: aws.String(d.Id()), } - if logs := d.Get("access_logs").([]interface{}); len(logs) == 1 { - l := logs[0].(map[string]interface{}) + if v := d.Get("access_logs").([]interface{}); len(v) == 1 { + tfMap := v[0].(map[string]interface{}) input.LoadBalancerAttributes.AccessLog = &awstypes.AccessLog{ - Enabled: l[names.AttrEnabled].(bool), - EmitInterval: aws.Int32(int32(l[names.AttrInterval].(int))), - S3BucketName: aws.String(l[names.AttrBucket].(string)), - S3BucketPrefix: aws.String(l[names.AttrBucketPrefix].(string)), + Enabled: tfMap[names.AttrEnabled].(bool), + EmitInterval: aws.Int32(int32(tfMap[names.AttrInterval].(int))), + S3BucketName: aws.String(tfMap[names.AttrBucket].(string)), + S3BucketPrefix: aws.String(tfMap[names.AttrBucketPrefix].(string)), } - } else if len(logs) == 0 { + } else if len(v) == 0 { // disable access logs input.LoadBalancerAttributes.AccessLog = &awstypes.AccessLog{ Enabled: false, @@ -616,15 +611,15 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } if d.HasChange(names.AttrHealthCheck) { - if hc := d.Get(names.AttrHealthCheck).([]interface{}); len(hc) > 0 { - check := hc[0].(map[string]interface{}) + if v := d.Get(names.AttrHealthCheck).([]interface{}); len(v) > 0 { + tfMap := v[0].(map[string]interface{}) input := &elasticloadbalancing.ConfigureHealthCheckInput{ HealthCheck: &awstypes.HealthCheck{ - HealthyThreshold: aws.Int32(int32(check["healthy_threshold"].(int))), - Interval: aws.Int32(int32(check[names.AttrInterval].(int))), - Target: aws.String(check[names.AttrTarget].(string)), - Timeout: aws.Int32(int32(check[names.AttrTimeout].(int))), - UnhealthyThreshold: aws.Int32(int32(check["unhealthy_threshold"].(int))), + HealthyThreshold: aws.Int32(int32(tfMap["healthy_threshold"].(int))), + Interval: aws.Int32(int32(tfMap[names.AttrInterval].(int))), + Target: aws.String(tfMap[names.AttrTarget].(string)), + Timeout: aws.Int32(int32(tfMap[names.AttrTimeout].(int))), + UnhealthyThreshold: aws.Int32(int32(tfMap["unhealthy_threshold"].(int))), }, LoadBalancerName: aws.String(d.Id()), } @@ -651,15 +646,12 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met if d.HasChange(names.AttrAvailabilityZones) { o, n := d.GetChange(names.AttrAvailabilityZones) - os := o.(*schema.Set) - ns := n.(*schema.Set) - - removed := flex.ExpandStringValueSet(os.Difference(ns)) - added := flex.ExpandStringValueSet(ns.Difference(os)) + os, ns := o.(*schema.Set), n.(*schema.Set) + add, del := flex.ExpandStringValueSet(ns.Difference(os)), flex.ExpandStringValueSet(os.Difference(ns)) - if len(added) > 0 { + if len(add) > 0 { input := &elasticloadbalancing.EnableAvailabilityZonesForLoadBalancerInput{ - AvailabilityZones: added, + AvailabilityZones: add, LoadBalancerName: aws.String(d.Id()), } @@ -670,9 +662,9 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } } - if len(removed) > 0 { + if len(del) > 0 { input := &elasticloadbalancing.DisableAvailabilityZonesForLoadBalancerInput{ - AvailabilityZones: removed, + AvailabilityZones: del, LoadBalancerName: aws.String(d.Id()), } @@ -686,16 +678,13 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met if d.HasChange(names.AttrSubnets) { o, n := d.GetChange(names.AttrSubnets) - os := o.(*schema.Set) - ns := n.(*schema.Set) + os, ns := o.(*schema.Set), n.(*schema.Set) + add, del := flex.ExpandStringValueSet(ns.Difference(os)), flex.ExpandStringValueSet(os.Difference(ns)) - removed := flex.ExpandStringValueSet(os.Difference(ns)) - added := flex.ExpandStringValueSet(ns.Difference(os)) - - if len(removed) > 0 { + if len(del) > 0 { input := &elasticloadbalancing.DetachLoadBalancerFromSubnetsInput{ LoadBalancerName: aws.String(d.Id()), - Subnets: removed, + Subnets: del, } _, err := conn.DetachLoadBalancerFromSubnets(ctx, input) @@ -705,10 +694,10 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met } } - if len(added) > 0 { + if len(add) > 0 { input := &elasticloadbalancing.AttachLoadBalancerToSubnetsInput{ LoadBalancerName: aws.String(d.Id()), - Subnets: added, + Subnets: add, } _, err := tfresource.RetryWhenIsAErrorMessageContains[*awstypes.InvalidConfigurationRequestException](ctx, d.Timeout(schema.TimeoutUpdate), func() (interface{}, error) { @@ -792,7 +781,7 @@ func findLoadBalancerAttributesByName(ctx context.Context, conn *elasticloadbala return output.LoadBalancerAttributes, nil } -func ListenerHash(v interface{}) int { +func listenerHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) buf.WriteString(fmt.Sprintf("%d-", m["instance_port"].(int))) @@ -807,7 +796,7 @@ func ListenerHash(v interface{}) int { return create.StringHashcode(buf.String()) } -func ValidAccessLogsInterval(v interface{}, k string) (ws []string, errors []error) { +func validAccessLogsInterval(v interface{}, k string) (ws []string, errors []error) { value := v.(int) // Check if the value is either 5 or 60 (minutes). @@ -820,7 +809,7 @@ func ValidAccessLogsInterval(v interface{}, k string) (ws []string, errors []err return } -func ValidHeathCheckTarget(v interface{}, k string) (ws []string, errors []error) { +func validHeathCheckTarget(v interface{}, k string) (ws []string, errors []error) { value := v.(string) // Parse the Health Check target value. diff --git a/internal/service/elb/load_balancer_data_source.go b/internal/service/elb/load_balancer_data_source.go index 37a7cb0cb62..4c42845ca25 100644 --- a/internal/service/elb/load_balancer_data_source.go +++ b/internal/service/elb/load_balancer_data_source.go @@ -20,8 +20,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKDataSource("aws_elb") -func DataSourceLoadBalancer() *schema.Resource { +// @SDKDataSource("aws_elb", name="Classic Load Balancer") +func dataSourceLoadBalancer() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceLoadBalancerRead, Schema: map[string]*schema.Schema{ @@ -144,29 +144,24 @@ func DataSourceLoadBalancer() *schema.Resource { Type: schema.TypeInt, Computed: true, }, - "instance_protocol": { Type: schema.TypeString, Computed: true, }, - "lb_port": { Type: schema.TypeInt, Computed: true, }, - "lb_protocol": { Type: schema.TypeString, Computed: true, }, - "ssl_certificate_id": { Type: schema.TypeString, Computed: true, }, }, }, - Set: ListenerHash, }, names.AttrSecurityGroups: { diff --git a/internal/service/elb/load_balancer_test.go b/internal/service/elb/load_balancer_test.go index fceb7f22253..4a980567868 100644 --- a/internal/service/elb/load_balancer_test.go +++ b/internal/service/elb/load_balancer_test.go @@ -6,7 +6,6 @@ package elb_test import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports "context" "fmt" - "math/rand" "reflect" "testing" @@ -58,189 +57,6 @@ func TestLoadBalancerListenerHash(t *testing.T) { } } -func TestValidLoadBalancerNameCannotBeginWithHyphen(t *testing.T) { - t.Parallel() - - var n = "-Testing123" - _, errors := tfelb.ValidName(n, "SampleKey") - - if len(errors) != 1 { - t.Fatalf("Expected the ELB Name to trigger a validation error") - } -} - -func TestValidLoadBalancerNameCanBeAnEmptyString(t *testing.T) { - t.Parallel() - - var n = "" - _, errors := tfelb.ValidName(n, "SampleKey") - - if len(errors) != 0 { - t.Fatalf("Expected the ELB Name to pass validation") - } -} - -func TestValidLoadBalancerNameCannotBeLongerThan32Characters(t *testing.T) { - t.Parallel() - - var n = "Testing123dddddddddddddddddddvvvv" - _, errors := tfelb.ValidName(n, "SampleKey") - - if len(errors) != 1 { - t.Fatalf("Expected the ELB Name to trigger a validation error") - } -} - -func TestValidLoadBalancerNameCannotHaveSpecialCharacters(t *testing.T) { - t.Parallel() - - var n = "Testing123%%" - _, errors := tfelb.ValidName(n, "SampleKey") - - if len(errors) != 1 { - t.Fatalf("Expected the ELB Name to trigger a validation error") - } -} - -func TestValidLoadBalancerNameCannotEndWithHyphen(t *testing.T) { - t.Parallel() - - var n = "Testing123-" - _, errors := tfelb.ValidName(n, "SampleKey") - - if len(errors) != 1 { - t.Fatalf("Expected the ELB Name to trigger a validation error") - } -} - -func TestValidLoadBalancerAccessLogsInterval(t *testing.T) { - t.Parallel() - - type testCases struct { - Value int - ErrCount int - } - - invalidCases := []testCases{ - { - Value: 0, - ErrCount: 1, - }, - { - Value: 10, - ErrCount: 1, - }, - { - Value: -1, - ErrCount: 1, - }, - } - - for _, tc := range invalidCases { - _, errors := tfelb.ValidAccessLogsInterval(tc.Value, names.AttrInterval) - if len(errors) != tc.ErrCount { - t.Fatalf("Expected %q to trigger a validation error.", tc.Value) - } - } -} - -func TestValidLoadBalancerHealthCheckTarget(t *testing.T) { - t.Parallel() - - type testCase struct { - Value string - ErrCount int - } - - randomRunes := func(n int) string { - // A complete set of modern Katakana characters. - runes := []rune("アイウエオ" + - "カキクケコガギグゲゴサシスセソザジズゼゾ" + - "タチツテトダヂヅデドナニヌネノハヒフヘホ" + - "バビブベボパピプペポマミムメモヤユヨラリ" + - "ルレロワヰヱヲン") - - s := make([]rune, n) - for i := range s { - s[i] = runes[rand.Intn(len(runes))] - } - return string(s) - } - - validCases := []testCase{ - { - Value: "TCP:1234", - ErrCount: 0, - }, - { - Value: "http:80/test", - ErrCount: 0, - }, - { - Value: fmt.Sprintf("HTTP:8080/%s", randomRunes(5)), - ErrCount: 0, - }, - { - Value: "SSL:8080", - ErrCount: 0, - }, - } - - for _, tc := range validCases { - _, errors := tfelb.ValidHeathCheckTarget(tc.Value, names.AttrTarget) - if len(errors) != tc.ErrCount { - t.Fatalf("Expected %q not to trigger a validation error.", tc.Value) - } - } - - invalidCases := []testCase{ - { - Value: "", - ErrCount: 1, - }, - { - Value: "TCP:", - ErrCount: 1, - }, - { - Value: "TCP:1234/", - ErrCount: 1, - }, - { - Value: "SSL:8080/", - ErrCount: 1, - }, - { - Value: "HTTP:8080", - ErrCount: 1, - }, - { - Value: "incorrect-value", - ErrCount: 1, - }, - { - Value: "TCP:123456", - ErrCount: 1, - }, - { - Value: "incorrect:80/", - ErrCount: 1, - }, - { - Value: fmt.Sprintf("HTTP:8080/%s%s", - sdkacctest.RandStringFromCharSet(512, sdkacctest.CharSetAlpha), randomRunes(512)), - ErrCount: 1, - }, - } - - for _, tc := range invalidCases { - _, errors := tfelb.ValidHeathCheckTarget(tc.Value, names.AttrTarget) - if len(errors) != tc.ErrCount { - t.Fatalf("Expected %q to trigger a validation error.", tc.Value) - } - } -} - func TestAccELBLoadBalancer_basic(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription diff --git a/internal/service/elb/service_package_gen.go b/internal/service/elb/service_package_gen.go index e8a9a7ca166..b4a6313e238 100644 --- a/internal/service/elb/service_package_gen.go +++ b/internal/service/elb/service_package_gen.go @@ -25,8 +25,9 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { return []*types.ServicePackageSDKDataSource{ { - Factory: DataSourceLoadBalancer, + Factory: dataSourceLoadBalancer, TypeName: "aws_elb", + Name: "Classic Load Balancer", }, { Factory: dataSourceHostedZoneID, @@ -49,7 +50,7 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka Name: "App Cookie Stickiness Policy", }, { - Factory: ResourceLoadBalancer, + Factory: resourceLoadBalancer, TypeName: "aws_elb", Name: "Classic Load Balancer", Tags: &types.ServicePackageResourceTags{ diff --git a/internal/service/elb/validate.go b/internal/service/elb/validate.go index 6210dd5c40d..c185199c44f 100644 --- a/internal/service/elb/validate.go +++ b/internal/service/elb/validate.go @@ -9,7 +9,7 @@ import ( "github.com/YakDriver/regexache" ) -func ValidName(v interface{}, k string) (ws []string, errors []error) { +func validName(v interface{}, k string) (ws []string, errors []error) { value := v.(string) if len(value) == 0 { return // short-circuit diff --git a/internal/service/elb/validate_test.go b/internal/service/elb/validate_test.go index 588063915ae..9bc9607d87b 100644 --- a/internal/service/elb/validate_test.go +++ b/internal/service/elb/validate_test.go @@ -4,8 +4,11 @@ package elb import ( + "fmt" + "math/rand" "testing" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -17,7 +20,7 @@ func TestValidName(t *testing.T) { } for _, s := range validNames { - _, errors := ValidName(s, names.AttrName) + _, errors := validName(s, names.AttrName) if len(errors) > 0 { t.Fatalf("%q should be a valid ELB name: %v", s, errors) } @@ -31,13 +34,68 @@ func TestValidName(t *testing.T) { } for _, s := range invalidNames { - _, errors := ValidName(s, names.AttrName) + _, errors := validName(s, names.AttrName) if len(errors) == 0 { t.Fatalf("%q should not be a valid ELB name: %v", s, errors) } } } +func TestValidLoadBalancerNameCannotBeginWithHyphen(t *testing.T) { + t.Parallel() + + var n = "-Testing123" + _, errors := validName(n, "SampleKey") + + if len(errors) != 1 { + t.Fatalf("Expected the ELB Name to trigger a validation error") + } +} + +func TestValidLoadBalancerNameCanBeAnEmptyString(t *testing.T) { + t.Parallel() + + var n = "" + _, errors := validName(n, "SampleKey") + + if len(errors) != 0 { + t.Fatalf("Expected the ELB Name to pass validation") + } +} + +func TestValidLoadBalancerNameCannotBeLongerThan32Characters(t *testing.T) { + t.Parallel() + + var n = "Testing123dddddddddddddddddddvvvv" + _, errors := validName(n, "SampleKey") + + if len(errors) != 1 { + t.Fatalf("Expected the ELB Name to trigger a validation error") + } +} + +func TestValidLoadBalancerNameCannotHaveSpecialCharacters(t *testing.T) { + t.Parallel() + + var n = "Testing123%%" + _, errors := validName(n, "SampleKey") + + if len(errors) != 1 { + t.Fatalf("Expected the ELB Name to trigger a validation error") + } +} + +func TestValidLoadBalancerNameCannotEndWithHyphen(t *testing.T) { + t.Parallel() + + var n = "Testing123-" + _, errors := validName(n, "SampleKey") + + if len(errors) != 1 { + t.Fatalf("Expected the ELB Name to trigger a validation error") + } +} + func TestValidNamePrefix(t *testing.T) { t.Parallel() @@ -65,3 +123,131 @@ func TestValidNamePrefix(t *testing.T) { } } } + +func TestValidLoadBalancerAccessLogsInterval(t *testing.T) { + t.Parallel() + + type testCases struct { + Value int + ErrCount int + } + + invalidCases := []testCases{ + { + Value: 0, + ErrCount: 1, + }, + { + Value: 10, + ErrCount: 1, + }, + { + Value: -1, + ErrCount: 1, + }, + } + + for _, tc := range invalidCases { + _, errors := validAccessLogsInterval(tc.Value, names.AttrInterval) + if len(errors) != tc.ErrCount { + t.Fatalf("Expected %q to trigger a validation error.", tc.Value) + } + } +} + +func TestValidLoadBalancerHealthCheckTarget(t *testing.T) { + t.Parallel() + + type testCase struct { + Value string + ErrCount int + } + + randomRunes := func(n int) string { + // A complete set of modern Katakana characters. + runes := []rune("アイウエオ" + + "カキクケコガギグゲゴサシスセソザジズゼゾ" + + "タチツテトダヂヅデドナニヌネノハヒフヘホ" + + "バビブベボパピプペポマミムメモヤユヨラリ" + + "ルレロワヰヱヲン") + + s := make([]rune, n) + for i := range s { + s[i] = runes[rand.Intn(len(runes))] + } + return string(s) + } + + validCases := []testCase{ + { + Value: "TCP:1234", + ErrCount: 0, + }, + { + Value: "http:80/test", + ErrCount: 0, + }, + { + Value: fmt.Sprintf("HTTP:8080/%s", randomRunes(5)), + ErrCount: 0, + }, + { + Value: "SSL:8080", + ErrCount: 0, + }, + } + + for _, tc := range validCases { + _, errors := validHeathCheckTarget(tc.Value, names.AttrTarget) + if len(errors) != tc.ErrCount { + t.Fatalf("Expected %q not to trigger a validation error.", tc.Value) + } + } + + invalidCases := []testCase{ + { + Value: "", + ErrCount: 1, + }, + { + Value: "TCP:", + ErrCount: 1, + }, + { + Value: "TCP:1234/", + ErrCount: 1, + }, + { + Value: "SSL:8080/", + ErrCount: 1, + }, + { + Value: "HTTP:8080", + ErrCount: 1, + }, + { + Value: "incorrect-value", + ErrCount: 1, + }, + { + Value: "TCP:123456", + ErrCount: 1, + }, + { + Value: "incorrect:80/", + ErrCount: 1, + }, + { + Value: fmt.Sprintf("HTTP:8080/%s%s", + sdkacctest.RandStringFromCharSet(512, sdkacctest.CharSetAlpha), randomRunes(512)), + ErrCount: 1, + }, + } + + for _, tc := range invalidCases { + _, errors := validHeathCheckTarget(tc.Value, names.AttrTarget) + if len(errors) != tc.ErrCount { + t.Fatalf("Expected %q to trigger a validation error.", tc.Value) + } + } +} From feeb2b8180e105e5d7e44295dfd7077a38e0213e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 17:02:23 -0400 Subject: [PATCH 28/37] elb: Fix sweeper compilation errors. --- internal/service/elb/sweep.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/service/elb/sweep.go b/internal/service/elb/sweep.go index d5173390947..eb8a3acdb3a 100644 --- a/internal/service/elb/sweep.go +++ b/internal/service/elb/sweep.go @@ -32,7 +32,6 @@ func sweepLoadBalancers(region string) error { sweepResources := make([]sweep.Sweepable, 0) pages := elasticloadbalancing.NewDescribeLoadBalancersPaginator(conn, input) - for pages.HasMorePages() { page, err := pages.NextPage(ctx) @@ -46,7 +45,7 @@ func sweepLoadBalancers(region string) error { } for _, v := range page.LoadBalancerDescriptions { - r := ResourceLoadBalancer() + r := resourceLoadBalancer() d := r.Data(nil) d.SetId(aws.ToString(v.LoadBalancerName)) From a6b0dd2322a7bd9f4a06b49fb888e0887202cde5 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 17:07:15 -0400 Subject: [PATCH 29/37] Fix golangci-lint 'unparam'. --- internal/service/elb/attachment_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/elb/attachment_test.go b/internal/service/elb/attachment_test.go index 1e4679d1966..a547293c962 100644 --- a/internal/service/elb/attachment_test.go +++ b/internal/service/elb/attachment_test.go @@ -141,7 +141,7 @@ resource "aws_elb" "test" { lb_protocol = "http" } } -`)) +`, rName)) } func testAccAttachmentConfig_1(rName string) string { From 6de4be1acdc7eab6828a0c6d1e9fa1f57783516c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 9 Jul 2024 17:08:57 -0400 Subject: [PATCH 30/37] Fix golangci-lint 'gosimple'. --- internal/service/elb/flex.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/service/elb/flex.go b/internal/service/elb/flex.go index b980d87ba91..6b23e7fa98e 100644 --- a/internal/service/elb/flex.go +++ b/internal/service/elb/flex.go @@ -46,11 +46,7 @@ func flattenBackendServerDescriptionPolicies(apiObjects []awstypes.BackendServer for _, apiObject := range apiObjects { k := aws.ToInt32(apiObject.InstancePort) - - for _, v := range apiObject.PolicyNames { - tfMap[k] = append(tfMap[k], v) - } - + tfMap[k] = append(tfMap[k], apiObject.PolicyNames...) sort.Strings(tfMap[k]) } From 1d4b2ccb2b3d4e7b0d91f8ad7c3bedce13833264 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 10 Jul 2024 08:47:45 -0400 Subject: [PATCH 31/37] 'aws_elasticloadbalancing' -> 'aws_elb' in acceptance tests. --- internal/service/elb/load_balancer_test.go | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/internal/service/elb/load_balancer_test.go b/internal/service/elb/load_balancer_test.go index 4a980567868..c2807643494 100644 --- a/internal/service/elb/load_balancer_test.go +++ b/internal/service/elb/load_balancer_test.go @@ -61,7 +61,7 @@ func TestAccELBLoadBalancer_basic(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -115,7 +115,7 @@ func TestAccELBLoadBalancer_disappears(t *testing.T) { ctx := acctest.Context(t) var loadBalancer awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -138,7 +138,7 @@ func TestAccELBLoadBalancer_disappears(t *testing.T) { func TestAccELBLoadBalancer_nameGenerated(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -166,7 +166,7 @@ func TestAccELBLoadBalancer_nameGenerated(t *testing.T) { func TestAccELBLoadBalancer_namePrefix(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -195,7 +195,7 @@ func TestAccELBLoadBalancer_tags(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -243,7 +243,7 @@ func TestAccELBLoadBalancer_tags(t *testing.T) { func TestAccELBLoadBalancer_fullCharacterRange(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -266,7 +266,7 @@ func TestAccELBLoadBalancer_fullCharacterRange(t *testing.T) { func TestAccELBLoadBalancer_AccessLogs_enabled(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -307,7 +307,7 @@ func TestAccELBLoadBalancer_AccessLogs_enabled(t *testing.T) { func TestAccELBLoadBalancer_AccessLogs_disabled(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -347,7 +347,7 @@ func TestAccELBLoadBalancer_generatesNameForZeroValue(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription generatedNameRegexp := regexache.MustCompile("^tf-lb-") - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -370,7 +370,7 @@ func TestAccELBLoadBalancer_availabilityZones(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -403,7 +403,7 @@ func TestAccELBLoadBalancer_ListenerSSLCertificateID_iamServerCertificate(t *tes key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com") rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" testCheck := func(*terraform.State) error { if len(conf.ListenerDescriptions) != 1 { @@ -443,7 +443,7 @@ func TestAccELBLoadBalancer_Swap_subnets(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -461,15 +461,15 @@ func TestAccELBLoadBalancer_Swap_subnets(t *testing.T) { { Config: testAccLoadBalancerConfig_subnetSwap(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, "aws_elasticloadbalancing.test", &conf), - resource.TestCheckResourceAttr("aws_elasticloadbalancing.test", "subnets.#", acctest.Ct2), + testAccCheckLoadBalancerExists(ctx, resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "subnets.#", acctest.Ct2), ), }, { Config: testAccLoadBalancerConfig_subnetCompleteSwap(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckLoadBalancerExists(ctx, "aws_elasticloadbalancing.test", &conf), - resource.TestCheckResourceAttr("aws_elasticloadbalancing.test", "subnets.#", acctest.Ct2), + testAccCheckLoadBalancerExists(ctx, resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "subnets.#", acctest.Ct2), ), }, }, @@ -480,7 +480,7 @@ func TestAccELBLoadBalancer_instanceAttaching(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" testCheckInstanceAttached := func(count int) resource.TestCheckFunc { return func(*terraform.State) error { @@ -520,7 +520,7 @@ func TestAccELBLoadBalancer_listener(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -649,7 +649,7 @@ func TestAccELBLoadBalancer_healthCheck(t *testing.T) { ctx := acctest.Context(t) var conf awstypes.LoadBalancerDescription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -678,7 +678,7 @@ func TestAccELBLoadBalancer_healthCheck(t *testing.T) { func TestAccELBLoadBalancer_timeout(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -705,7 +705,7 @@ func TestAccELBLoadBalancer_timeout(t *testing.T) { func TestAccELBLoadBalancer_connectionDraining(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -740,7 +740,7 @@ func TestAccELBLoadBalancer_connectionDraining(t *testing.T) { func TestAccELBLoadBalancer_securityGroups(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -769,7 +769,7 @@ func TestAccELBLoadBalancer_securityGroups(t *testing.T) { func TestAccELBLoadBalancer_desyncMitigationMode(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -795,7 +795,7 @@ func TestAccELBLoadBalancer_desyncMitigationMode(t *testing.T) { func TestAccELBLoadBalancer_desyncMitigationMode_update(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_elasticloadbalancing.test" + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -1123,7 +1123,7 @@ resource "aws_elb" "test" { # See https://github.com/hashicorp/terraform-provider-aws/issues/2498 output "lb_name" { - value = aws_elasticloadbalancing.test.name + value = aws_elb.test.name } `) From 338a4991708c61288285c432d749e73a869c5d0d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 10 Jul 2024 08:58:30 -0400 Subject: [PATCH 32/37] Correct load balancer attribute name. --- internal/service/elb/consts.go | 9 +++++++++ internal/service/elb/load_balancer.go | 4 ++-- internal/service/elb/load_balancer_data_source.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 internal/service/elb/consts.go diff --git a/internal/service/elb/consts.go b/internal/service/elb/consts.go new file mode 100644 index 00000000000..a2172ae372f --- /dev/null +++ b/internal/service/elb/consts.go @@ -0,0 +1,9 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package elb + +// See https://docs.aws.amazon.com/elasticloadbalancing/2012-06-01/APIReference/API_AdditionalAttribute.html#API_AdditionalAttribute_Contents. +const ( + loadBalancerAttributeDesyncMitigationMode = "elb.http.desyncmitigationmode" +) diff --git a/internal/service/elb/load_balancer.go b/internal/service/elb/load_balancer.go index 94b871988b6..3b7f02d9263 100644 --- a/internal/service/elb/load_balancer.go +++ b/internal/service/elb/load_balancer.go @@ -413,7 +413,7 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta for _, attr := range lbAttrs.AdditionalAttributes { switch aws.ToString(attr.Key) { - case "elasticloadbalancing.http.desyncmitigationmode": + case loadBalancerAttributeDesyncMitigationMode: d.Set("desync_mitigation_mode", attr.Value) } } @@ -530,7 +530,7 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met LoadBalancerAttributes: &awstypes.LoadBalancerAttributes{ AdditionalAttributes: []awstypes.AdditionalAttribute{ { - Key: aws.String("elasticloadbalancing.http.desyncmitigationmode"), + Key: aws.String(loadBalancerAttributeDesyncMitigationMode), Value: aws.String(d.Get("desync_mitigation_mode").(string)), }, }, diff --git a/internal/service/elb/load_balancer_data_source.go b/internal/service/elb/load_balancer_data_source.go index 4c42845ca25..7b716e00ff7 100644 --- a/internal/service/elb/load_balancer_data_source.go +++ b/internal/service/elb/load_balancer_data_source.go @@ -302,7 +302,7 @@ func dataSourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, met for _, attr := range lbAttrs.AdditionalAttributes { switch aws.ToString(attr.Key) { - case "elasticloadbalancing.http.desyncmitigationmode": + case loadBalancerAttributeDesyncMitigationMode: d.Set("desync_mitigation_mode", attr.Value) } } From 2a58c26a79b63122556a72148a7151b73334ecf5 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 10 Jul 2024 10:02:41 -0400 Subject: [PATCH 33/37] 'aws_awstypes' -> 'aws_elb' in acceptance tests. --- internal/service/elb/policy_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/service/elb/policy_test.go b/internal/service/elb/policy_test.go index e5a384beb44..87053c4007e 100644 --- a/internal/service/elb/policy_test.go +++ b/internal/service/elb/policy_test.go @@ -311,7 +311,7 @@ resource "aws_elb" "test-lb" { } resource "aws_load_balancer_policy" "test-policy" { - load_balancer_name = aws_awstypes.test-lb.name + load_balancer_name = aws_elb.test-lb.name policy_name = "test-policy-%[1]d" policy_type_name = "AppCookieStickinessPolicyType" @@ -344,7 +344,7 @@ resource "aws_elb" "test" { } resource "aws_load_balancer_policy" "test" { - load_balancer_name = aws_awstypes.test.name + load_balancer_name = aws_elb.test.name policy_name = %[1]q policy_type_name = %[2]q } @@ -370,7 +370,7 @@ resource "aws_elb" "test" { } resource "aws_load_balancer_policy" "test" { - load_balancer_name = aws_awstypes.test.name + load_balancer_name = aws_elb.test.name policy_name = %[1]q policy_type_name = "SSLNegotiationPolicyType" @@ -406,7 +406,7 @@ resource "aws_elb" "test" { } resource "aws_load_balancer_policy" "test" { - load_balancer_name = aws_awstypes.test.name + load_balancer_name = aws_elb.test.name policy_name = %[1]q policy_type_name = "SSLNegotiationPolicyType" @@ -437,7 +437,7 @@ resource "aws_elb" "test-lb" { } resource "aws_load_balancer_policy" "test-policy" { - load_balancer_name = aws_awstypes.test-lb.name + load_balancer_name = aws_elb.test-lb.name policy_name = "test-policy-%[1]d" policy_type_name = "AppCookieStickinessPolicyType" @@ -448,7 +448,7 @@ resource "aws_load_balancer_policy" "test-policy" { } resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" { - load_balancer_name = aws_awstypes.test-lb.name + load_balancer_name = aws_elb.test-lb.name load_balancer_port = 80 policy_names = [ @@ -477,7 +477,7 @@ resource "aws_elb" "test-lb" { } resource "aws_load_balancer_policy" "test-policy" { - load_balancer_name = aws_awstypes.test-lb.name + load_balancer_name = aws_elb.test-lb.name policy_name = "test-policy-%[1]d" policy_type_name = "AppCookieStickinessPolicyType" @@ -488,7 +488,7 @@ resource "aws_load_balancer_policy" "test-policy" { } resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" { - load_balancer_name = aws_awstypes.test-lb.name + load_balancer_name = aws_elb.test-lb.name load_balancer_port = 80 policy_names = [ From 9510d93f231555d7ee7a23f3e8cee6c5853f9d64 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 10 Jul 2024 10:18:15 -0400 Subject: [PATCH 34/37] elb: Handle 'LoadBalancerNotFound: There is no ACTIVE Load Balancer named ...' on Delete. --- internal/service/elb/app_cookie_stickiness_policy.go | 9 +++++++++ internal/service/elb/errors.go | 3 ++- internal/service/elb/lb_cookie_stickiness_policy.go | 9 +++++++++ internal/service/elb/lb_ssl_negotiation_policy.go | 9 +++++++++ internal/service/elb/listener_policy.go | 5 +++++ internal/service/elb/policy.go | 5 +++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/internal/service/elb/app_cookie_stickiness_policy.go b/internal/service/elb/app_cookie_stickiness_policy.go index d9eed102fd0..d0ab012693e 100644 --- a/internal/service/elb/app_cookie_stickiness_policy.go +++ b/internal/service/elb/app_cookie_stickiness_policy.go @@ -14,6 +14,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -163,6 +164,10 @@ func resourceAppCookieStickinessPolicyDelete(ctx context.Context, d *schema.Reso _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, input) + if tfawserr.ErrCodeEquals(err, errCodeLoadBalancerNotFound) { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic App Cookie Stickiness Policy (%s): %s", d.Id(), err) } @@ -173,6 +178,10 @@ func resourceAppCookieStickinessPolicyDelete(ctx context.Context, d *schema.Reso PolicyName: aws.String(policyName), }) + if tfawserr.ErrCodeEquals(err, errCodeLoadBalancerNotFound) { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "deleting ELB Classic App Cookie Stickiness Policy (%s): %s", d.Id(), err) } diff --git a/internal/service/elb/errors.go b/internal/service/elb/errors.go index 0b4c394f4b9..8ee5fe1aa8d 100644 --- a/internal/service/elb/errors.go +++ b/internal/service/elb/errors.go @@ -4,5 +4,6 @@ package elb const ( - errCodeInvalidTarget = "InvalidTarget" + errCodeInvalidTarget = "InvalidTarget" + errCodeLoadBalancerNotFound = "LoadBalancerNotFound" ) diff --git a/internal/service/elb/lb_cookie_stickiness_policy.go b/internal/service/elb/lb_cookie_stickiness_policy.go index 322a1f0d8db..aa64a9b0095 100644 --- a/internal/service/elb/lb_cookie_stickiness_policy.go +++ b/internal/service/elb/lb_cookie_stickiness_policy.go @@ -12,6 +12,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -152,6 +153,10 @@ func resourceCookieStickinessPolicyDelete(ctx context.Context, d *schema.Resourc _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, input) + if tfawserr.ErrCodeEquals(err, errCodeLoadBalancerNotFound) { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic LB Cookie Stickiness Policy (%s): %s", d.Id(), err) } @@ -162,6 +167,10 @@ func resourceCookieStickinessPolicyDelete(ctx context.Context, d *schema.Resourc PolicyName: aws.String(policyName), }) + if tfawserr.ErrCodeEquals(err, errCodeLoadBalancerNotFound) { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "deleting ELB Classic LB Cookie Stickiness Policy (%s): %s", d.Id(), err) } diff --git a/internal/service/elb/lb_ssl_negotiation_policy.go b/internal/service/elb/lb_ssl_negotiation_policy.go index 755399df03a..c4511264e74 100644 --- a/internal/service/elb/lb_ssl_negotiation_policy.go +++ b/internal/service/elb/lb_ssl_negotiation_policy.go @@ -12,6 +12,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + "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" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -179,6 +180,10 @@ func resourceSSLNegotiationPolicyDelete(ctx context.Context, d *schema.ResourceD _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, input) + if tfawserr.ErrCodeEquals(err, errCodeLoadBalancerNotFound) { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic SSL Negotiation Policy (%s): %s", d.Id(), err) } @@ -188,6 +193,10 @@ func resourceSSLNegotiationPolicyDelete(ctx context.Context, d *schema.ResourceD PolicyName: aws.String(policyName), }) + if tfawserr.ErrCodeEquals(err, errCodeLoadBalancerNotFound) { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "deleting ELB Classic SSL Negotiation Policy (%s): %s", d.Id(), err) } diff --git a/internal/service/elb/listener_policy.go b/internal/service/elb/listener_policy.go index e1d2235ba21..bde97f4c07f 100644 --- a/internal/service/elb/listener_policy.go +++ b/internal/service/elb/listener_policy.go @@ -12,6 +12,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" + "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" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -127,6 +128,10 @@ func resourceListenerPolicyDelete(ctx context.Context, d *schema.ResourceData, m log.Printf("[DEBUG] Deleting ELB Classic Listener Policy: %s", d.Id()) _, err = conn.SetLoadBalancerPoliciesOfListener(ctx, input) + if tfawserr.ErrCodeEquals(err, errCodeLoadBalancerNotFound) { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "setting ELB Classic Listener Policy (%s): %s", d.Id(), err) } diff --git a/internal/service/elb/policy.go b/internal/service/elb/policy.go index 64319c7f8ed..fb54ae5117c 100644 --- a/internal/service/elb/policy.go +++ b/internal/service/elb/policy.go @@ -13,6 +13,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -222,6 +223,10 @@ func resourcePolicyDelete(ctx context.Context, d *schema.ResourceData, meta inte PolicyName: aws.String(policyName), }) + if tfawserr.ErrCodeEquals(err, errCodeLoadBalancerNotFound) { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "deleting ELB Classic Load Balancer Policy (%s): %s", d.Id(), err) } From ffb9cb0447b6ca4a65dfe0c6cd369d9920c426c8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 10 Jul 2024 11:30:29 -0400 Subject: [PATCH 35/37] r/aws_iam_server_certificate: Add configurable delete timeout. --- .changelog/38212.txt | 3 +++ internal/service/iam/server_certificate.go | 9 +++++---- website/docs/r/iam_server_certificate.html.markdown | 6 ++++++ 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .changelog/38212.txt diff --git a/.changelog/38212.txt b/.changelog/38212.txt new file mode 100644 index 00000000000..a653decd871 --- /dev/null +++ b/.changelog/38212.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_iam_server_certificate: Add configurable `delete` timeout +``` \ No newline at end of file diff --git a/internal/service/iam/server_certificate.go b/internal/service/iam/server_certificate.go index afaceb0aaf4..a9859e406e6 100644 --- a/internal/service/iam/server_certificate.go +++ b/internal/service/iam/server_certificate.go @@ -43,6 +43,10 @@ func resourceServerCertificate() *schema.Resource { StateContext: resourceServerCertificateImport, }, + Timeouts: &schema.ResourceTimeout{ + Delete: schema.DefaultTimeout(15 * time.Minute), + }, + Schema: map[string]*schema.Schema{ names.AttrARN: { Type: schema.TypeString, @@ -210,15 +214,12 @@ func resourceServerCertificateUpdate(ctx context.Context, d *schema.ResourceData return append(diags, resourceServerCertificateRead(ctx, d, meta)...) } -const deleteTimeout = 15 * time.Minute - func resourceServerCertificateDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).IAMClient(ctx) log.Printf("[DEBUG] Deleting IAM Server Certificate: %s", d.Id()) - - _, err := tfresource.RetryWhenIsAErrorMessageContains[*awstypes.DeleteConflictException](ctx, deleteTimeout, func() (interface{}, error) { + _, err := tfresource.RetryWhenIsAErrorMessageContains[*awstypes.DeleteConflictException](ctx, d.Timeout(schema.TimeoutDelete), func() (interface{}, error) { return conn.DeleteServerCertificate(ctx, &iam.DeleteServerCertificateInput{ ServerCertificateName: aws.String(d.Get(names.AttrName).(string)), }) diff --git a/website/docs/r/iam_server_certificate.html.markdown b/website/docs/r/iam_server_certificate.html.markdown index 6903a92dafb..0e8994fa094 100644 --- a/website/docs/r/iam_server_certificate.html.markdown +++ b/website/docs/r/iam_server_certificate.html.markdown @@ -122,6 +122,12 @@ This resource exports the following attributes in addition to the arguments abov * `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). * `upload_date` - Date and time in [RFC3339 format](https://tools.ietf.org/html/rfc3339#section-5.8) when the server certificate was uploaded. +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +- `delete` - (Default `15m`) + ## Import In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import IAM Server Certificates using the `name`. For example: From 62870ba17c8f3b7288f81dfcc2f8311ca1dcefc2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 10 Jul 2024 11:33:59 -0400 Subject: [PATCH 36/37] elb: Increase aws_iam_server_certificate delete timeout in acceptance tests. --- .../service/elb/backend_server_policy_test.go | 4 ++++ .../elb/lb_ssl_negotiation_policy_test.go | 8 ++++++++ internal/service/elb/listener_policy_test.go | 4 ++++ internal/service/elb/load_balancer_test.go | 18 +++++++++++++----- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/internal/service/elb/backend_server_policy_test.go b/internal/service/elb/backend_server_policy_test.go index f7a4c2dc7b1..03039f100a1 100644 --- a/internal/service/elb/backend_server_policy_test.go +++ b/internal/service/elb/backend_server_policy_test.go @@ -183,6 +183,10 @@ resource "aws_iam_server_certificate" "test" { name = %[1]q certificate_body = "%[2]s" private_key = "%[3]s" + + timeouts { + delete = "30m" + } } resource "aws_load_balancer_policy" "test0" { diff --git a/internal/service/elb/lb_ssl_negotiation_policy_test.go b/internal/service/elb/lb_ssl_negotiation_policy_test.go index 90f808d3523..ac47ccabbdc 100644 --- a/internal/service/elb/lb_ssl_negotiation_policy_test.go +++ b/internal/service/elb/lb_ssl_negotiation_policy_test.go @@ -159,6 +159,10 @@ resource "aws_iam_server_certificate" "test" { name = %[1]q certificate_body = "%[2]s" private_key = "%[3]s" + + timeouts { + delete = "30m" + } } resource "aws_elb" "test" { @@ -224,6 +228,10 @@ resource "aws_iam_server_certificate" "test" { name_prefix = %[1]q certificate_body = "%[2]s" private_key = "%[3]s" + + timeouts { + delete = "30m" + } } resource "aws_elb" "test" { diff --git a/internal/service/elb/listener_policy_test.go b/internal/service/elb/listener_policy_test.go index 28c5fa54a27..ba8090766a4 100644 --- a/internal/service/elb/listener_policy_test.go +++ b/internal/service/elb/listener_policy_test.go @@ -204,6 +204,10 @@ resource "aws_iam_server_certificate" "test" { name_prefix = %[1]q certificate_body = "%[2]s" private_key = "%[3]s" + + timeouts { + delete = "30m" + } } resource "aws_elb" "test" { diff --git a/internal/service/elb/load_balancer_test.go b/internal/service/elb/load_balancer_test.go index c2807643494..7328e5a9823 100644 --- a/internal/service/elb/load_balancer_test.go +++ b/internal/service/elb/load_balancer_test.go @@ -1396,10 +1396,14 @@ resource "aws_security_group" "test" { func testAccLoadBalancerConfig_listenerIAMServerCertificate(rName, certificate, key, lbProtocol string) string { return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_iam_server_certificate" "test_cert" { +resource "aws_iam_server_certificate" "test" { name = %[1]q certificate_body = "%[2]s" private_key = "%[3]s" + + timeouts { + delete = "30m" + } } resource "aws_elb" "test" { @@ -1412,7 +1416,7 @@ resource "aws_elb" "test" { instance_protocol = %[4]q lb_port = 443 lb_protocol = %[4]q - ssl_certificate_id = aws_iam_server_certificate.test_cert.arn + ssl_certificate_id = aws_iam_server_certificate.test.arn } } `, rName, acctest.TLSPEMEscapeNewlines(certificate), acctest.TLSPEMEscapeNewlines(key), lbProtocol)) @@ -1420,10 +1424,14 @@ resource "aws_elb" "test" { func testAccLoadBalancerConfig_listenerIAMServerCertificateAddInvalidListener(rName, certificate, key string) string { return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_iam_server_certificate" "test_cert" { +resource "aws_iam_server_certificate" "test" { name = %[1]q certificate_body = "%[2]s" private_key = "%[3]s" + + timeouts { + delete = "30m" + } } resource "aws_elb" "test" { @@ -1436,7 +1444,7 @@ resource "aws_elb" "test" { instance_protocol = "https" lb_port = 443 lb_protocol = "https" - ssl_certificate_id = aws_iam_server_certificate.test_cert.arn + ssl_certificate_id = aws_iam_server_certificate.test.arn } # lb_protocol tcp and ssl_certificate_id is not valid @@ -1445,7 +1453,7 @@ resource "aws_elb" "test" { instance_protocol = "tcp" lb_port = 8443 lb_protocol = "tcp" - ssl_certificate_id = aws_iam_server_certificate.test_cert.arn + ssl_certificate_id = aws_iam_server_certificate.test.arn } } `, rName, acctest.TLSPEMEscapeNewlines(certificate), acctest.TLSPEMEscapeNewlines(key))) From 52b6e6f8e1050a0a20addfbb435ac53f27ef933f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 10 Jul 2024 11:41:47 -0400 Subject: [PATCH 37/37] Run 'make clean-tidy'. --- skaff/go.mod | 2 +- skaff/go.sum | 8 +-- tools/awssdkpatch/go.mod | 2 +- tools/awssdkpatch/go.sum | 8 +-- tools/tfsdk2fw/go.mod | 58 +++++++++--------- tools/tfsdk2fw/go.sum | 124 +++++++++++++++++++++------------------ 6 files changed, 107 insertions(+), 95 deletions(-) diff --git a/skaff/go.mod b/skaff/go.mod index cbb09d98a9a..cff172e7f25 100644 --- a/skaff/go.mod +++ b/skaff/go.mod @@ -13,7 +13,7 @@ require ( github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/hashicorp/hcl/v2 v2.20.1 // indirect + github.com/hashicorp/hcl/v2 v2.21.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/spf13/pflag v1.0.5 // indirect diff --git a/skaff/go.sum b/skaff/go.sum index eb05b8021ae..89806808e7d 100644 --- a/skaff/go.sum +++ b/skaff/go.sum @@ -13,8 +13,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc= -github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4= +github.com/hashicorp/hcl/v2 v2.21.0 h1:lve4q/o/2rqwYOgUg3y3V2YPyD1/zkCLGjIV74Jit14= +github.com/hashicorp/hcl/v2 v2.21.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= @@ -26,8 +26,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= diff --git a/tools/awssdkpatch/go.mod b/tools/awssdkpatch/go.mod index 397ef81d2a1..d85f3571170 100644 --- a/tools/awssdkpatch/go.mod +++ b/tools/awssdkpatch/go.mod @@ -11,7 +11,7 @@ require ( github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/hashicorp/hcl/v2 v2.20.1 // indirect + github.com/hashicorp/hcl/v2 v2.21.0 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/zclconf/go-cty v1.14.4 // indirect golang.org/x/mod v0.19.0 // indirect diff --git a/tools/awssdkpatch/go.sum b/tools/awssdkpatch/go.sum index bb41bcb059b..19aacce5ee9 100644 --- a/tools/awssdkpatch/go.sum +++ b/tools/awssdkpatch/go.sum @@ -8,14 +8,14 @@ github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc= -github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4= +github.com/hashicorp/hcl/v2 v2.21.0 h1:lve4q/o/2rqwYOgUg3y3V2YPyD1/zkCLGjIV74Jit14= +github.com/hashicorp/hcl/v2 v2.21.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= diff --git a/tools/tfsdk2fw/go.mod b/tools/tfsdk2fw/go.mod index 033db5b9070..669448fe4ce 100644 --- a/tools/tfsdk2fw/go.mod +++ b/tools/tfsdk2fw/go.mod @@ -18,20 +18,20 @@ require ( github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect - github.com/aws/aws-sdk-go v1.54.12 // indirect + github.com/aws/aws-sdk-go v1.54.17 // indirect github.com/aws/aws-sdk-go-v2 v1.30.1 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3 // indirect - github.com/aws/aws-sdk-go-v2/config v1.27.23 // indirect - github.com/aws/aws-sdk-go-v2/credentials v1.17.23 // indirect + github.com/aws/aws-sdk-go-v2/config v1.27.24 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.17.24 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9 // indirect - github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.3 // indirect + github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.5 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.13 // indirect github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.32.1 // indirect github.com/aws/aws-sdk-go-v2/service/account v1.19.1 // indirect - github.com/aws/aws-sdk-go-v2/service/acm v1.28.1 // indirect + github.com/aws/aws-sdk-go-v2/service/acm v1.28.2 // indirect github.com/aws/aws-sdk-go-v2/service/acmpca v1.33.1 // indirect github.com/aws/aws-sdk-go-v2/service/amp v1.27.1 // indirect github.com/aws/aws-sdk-go-v2/service/amplify v1.23.1 // indirect @@ -41,7 +41,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/appfabric v1.9.1 // indirect github.com/aws/aws-sdk-go-v2/service/appflow v1.43.1 // indirect github.com/aws/aws-sdk-go-v2/service/appintegrations v1.27.1 // indirect - github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.30.1 // indirect + github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.30.2 // indirect github.com/aws/aws-sdk-go-v2/service/applicationinsights v1.26.1 // indirect github.com/aws/aws-sdk-go-v2/service/applicationsignals v1.2.1 // indirect github.com/aws/aws-sdk-go-v2/service/apprunner v1.30.1 // indirect @@ -81,8 +81,8 @@ require ( github.com/aws/aws-sdk-go-v2/service/codepipeline v1.30.1 // indirect github.com/aws/aws-sdk-go-v2/service/codestarconnections v1.27.1 // indirect github.com/aws/aws-sdk-go-v2/service/codestarnotifications v1.24.1 // indirect - github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.25.1 // indirect - github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.41.1 // indirect + github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.25.3 // indirect + github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.41.2 // indirect github.com/aws/aws-sdk-go-v2/service/comprehend v1.33.1 // indirect github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.37.1 // indirect github.com/aws/aws-sdk-go-v2/service/configservice v1.48.1 // indirect @@ -94,9 +94,9 @@ require ( github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.39.1 // indirect github.com/aws/aws-sdk-go-v2/service/databrew v1.31.1 // indirect github.com/aws/aws-sdk-go-v2/service/datasync v1.40.1 // indirect - github.com/aws/aws-sdk-go-v2/service/datazone v1.12.1 // indirect + github.com/aws/aws-sdk-go-v2/service/datazone v1.13.0 // indirect github.com/aws/aws-sdk-go-v2/service/dax v1.21.1 // indirect - github.com/aws/aws-sdk-go-v2/service/devicefarm v1.24.1 // indirect + github.com/aws/aws-sdk-go-v2/service/devicefarm v1.25.0 // indirect github.com/aws/aws-sdk-go-v2/service/devopsguru v1.32.1 // indirect github.com/aws/aws-sdk-go-v2/service/directoryservice v1.27.1 // indirect github.com/aws/aws-sdk-go-v2/service/dlm v1.26.1 // indirect @@ -104,13 +104,15 @@ require ( github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.11.1 // indirect github.com/aws/aws-sdk-go-v2/service/drs v1.28.1 // indirect github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.1 // indirect - github.com/aws/aws-sdk-go-v2/service/ec2 v1.167.1 // indirect + github.com/aws/aws-sdk-go-v2/service/ec2 v1.168.0 // indirect github.com/aws/aws-sdk-go-v2/service/ecr v1.30.1 // indirect github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.25.1 // indirect github.com/aws/aws-sdk-go-v2/service/ecs v1.44.1 // indirect + github.com/aws/aws-sdk-go-v2/service/efs v1.31.1 // indirect github.com/aws/aws-sdk-go-v2/service/eks v1.46.0 // indirect github.com/aws/aws-sdk-go-v2/service/elasticache v1.40.1 // indirect - github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.25.1 // indirect + github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.26.0 // indirect + github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.1 // indirect github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.1 // indirect github.com/aws/aws-sdk-go-v2/service/emr v1.42.0 // indirect github.com/aws/aws-sdk-go-v2/service/emrserverless v1.23.1 // indirect @@ -121,7 +123,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/fis v1.26.1 // indirect github.com/aws/aws-sdk-go-v2/service/fms v1.35.1 // indirect github.com/aws/aws-sdk-go-v2/service/glacier v1.24.1 // indirect - github.com/aws/aws-sdk-go-v2/service/globalaccelerator v1.26.1 // indirect + github.com/aws/aws-sdk-go-v2/service/globalaccelerator v1.26.2 // indirect github.com/aws/aws-sdk-go-v2/service/grafana v1.24.1 // indirect github.com/aws/aws-sdk-go-v2/service/greengrass v1.25.1 // indirect github.com/aws/aws-sdk-go-v2/service/groundstation v1.29.1 // indirect @@ -141,6 +143,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/iotevents v1.25.1 // indirect github.com/aws/aws-sdk-go-v2/service/ivschat v1.14.1 // indirect github.com/aws/aws-sdk-go-v2/service/kafka v1.35.1 // indirect + github.com/aws/aws-sdk-go-v2/service/kafkaconnect v1.19.1 // indirect github.com/aws/aws-sdk-go-v2/service/kendra v1.52.1 // indirect github.com/aws/aws-sdk-go-v2/service/keyspaces v1.12.1 // indirect github.com/aws/aws-sdk-go-v2/service/kinesis v1.29.1 // indirect @@ -165,22 +168,22 @@ require ( github.com/aws/aws-sdk-go-v2/service/networkmonitor v1.5.1 // indirect github.com/aws/aws-sdk-go-v2/service/oam v1.13.1 // indirect github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.13.1 // indirect - github.com/aws/aws-sdk-go-v2/service/organizations v1.29.1 // indirect + github.com/aws/aws-sdk-go-v2/service/organizations v1.30.0 // indirect github.com/aws/aws-sdk-go-v2/service/osis v1.12.1 // indirect github.com/aws/aws-sdk-go-v2/service/paymentcryptography v1.12.1 // indirect github.com/aws/aws-sdk-go-v2/service/pcaconnectorad v1.7.1 // indirect github.com/aws/aws-sdk-go-v2/service/pipes v1.14.1 // indirect github.com/aws/aws-sdk-go-v2/service/polly v1.42.1 // indirect github.com/aws/aws-sdk-go-v2/service/pricing v1.30.1 // indirect - github.com/aws/aws-sdk-go-v2/service/qbusiness v1.9.1 // indirect + github.com/aws/aws-sdk-go-v2/service/qbusiness v1.10.0 // indirect github.com/aws/aws-sdk-go-v2/service/qldb v1.23.1 // indirect github.com/aws/aws-sdk-go-v2/service/ram v1.27.1 // indirect github.com/aws/aws-sdk-go-v2/service/rbin v1.18.1 // indirect github.com/aws/aws-sdk-go-v2/service/rds v1.81.2 // indirect - github.com/aws/aws-sdk-go-v2/service/redshift v1.46.1 // indirect + github.com/aws/aws-sdk-go-v2/service/redshift v1.46.2 // indirect github.com/aws/aws-sdk-go-v2/service/redshiftdata v1.27.1 // indirect github.com/aws/aws-sdk-go-v2/service/redshiftserverless v1.20.1 // indirect - github.com/aws/aws-sdk-go-v2/service/rekognition v1.42.1 // indirect + github.com/aws/aws-sdk-go-v2/service/rekognition v1.43.0 // indirect github.com/aws/aws-sdk-go-v2/service/resourceexplorer2 v1.12.1 // indirect github.com/aws/aws-sdk-go-v2/service/resourcegroups v1.24.1 // indirect github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.23.1 // indirect @@ -189,7 +192,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.1 // indirect github.com/aws/aws-sdk-go-v2/service/route53profiles v1.2.1 // indirect github.com/aws/aws-sdk-go-v2/service/rum v1.19.1 // indirect - github.com/aws/aws-sdk-go-v2/service/s3 v1.57.1 // indirect + github.com/aws/aws-sdk-go-v2/service/s3 v1.58.0 // indirect github.com/aws/aws-sdk-go-v2/service/s3control v1.46.1 // indirect github.com/aws/aws-sdk-go-v2/service/scheduler v1.10.1 // indirect github.com/aws/aws-sdk-go-v2/service/schemas v1.26.1 // indirect @@ -200,6 +203,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/servicediscovery v1.31.1 // indirect github.com/aws/aws-sdk-go-v2/service/servicequotas v1.23.1 // indirect github.com/aws/aws-sdk-go-v2/service/sesv2 v1.32.1 // indirect + github.com/aws/aws-sdk-go-v2/service/sfn v1.29.1 // indirect github.com/aws/aws-sdk-go-v2/service/shield v1.27.1 // indirect github.com/aws/aws-sdk-go-v2/service/signer v1.24.1 // indirect github.com/aws/aws-sdk-go-v2/service/sns v1.31.1 // indirect @@ -210,7 +214,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/ssmsap v1.15.1 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.22.1 // indirect github.com/aws/aws-sdk-go-v2/service/ssoadmin v1.27.1 // indirect - github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.1 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.2 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.30.1 // indirect github.com/aws/aws-sdk-go-v2/service/swf v1.25.1 // indirect github.com/aws/aws-sdk-go-v2/service/synthetics v1.26.1 // indirect @@ -224,7 +228,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/wafregional v1.23.1 // indirect github.com/aws/aws-sdk-go-v2/service/wafv2 v1.51.2 // indirect github.com/aws/aws-sdk-go-v2/service/wellarchitected v1.32.1 // indirect - github.com/aws/aws-sdk-go-v2/service/workspaces v1.43.0 // indirect + github.com/aws/aws-sdk-go-v2/service/workspaces v1.44.0 // indirect github.com/aws/aws-sdk-go-v2/service/workspacesweb v1.21.1 // indirect github.com/aws/aws-sdk-go-v2/service/xray v1.27.1 // indirect github.com/aws/smithy-go v1.20.3 // indirect @@ -254,20 +258,20 @@ require ( github.com/hashicorp/go-plugin v1.6.0 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.7.0 // indirect - github.com/hashicorp/hc-install v0.6.4 // indirect - github.com/hashicorp/hcl/v2 v2.20.1 // indirect + github.com/hashicorp/hc-install v0.7.0 // indirect + github.com/hashicorp/hcl/v2 v2.21.0 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.21.0 // indirect github.com/hashicorp/terraform-json v0.22.1 // indirect - github.com/hashicorp/terraform-plugin-framework v1.9.0 // indirect + github.com/hashicorp/terraform-plugin-framework v1.10.0 // indirect github.com/hashicorp/terraform-plugin-framework-jsontypes v0.1.0 // indirect github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 // indirect github.com/hashicorp/terraform-plugin-framework-timetypes v0.4.0 // indirect - github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 // indirect + github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 // indirect github.com/hashicorp/terraform-plugin-go v0.23.0 // indirect github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect github.com/hashicorp/terraform-plugin-mux v0.16.0 // indirect - github.com/hashicorp/terraform-plugin-testing v1.8.0 // indirect + github.com/hashicorp/terraform-plugin-testing v1.9.0 // indirect github.com/hashicorp/terraform-registry-address v0.2.3 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.1.1 // indirect @@ -299,11 +303,11 @@ require ( go.opentelemetry.io/otel v1.27.0 // indirect go.opentelemetry.io/otel/metric v1.27.0 // indirect go.opentelemetry.io/otel/trace v1.27.0 // indirect - golang.org/x/crypto v0.24.0 // indirect + golang.org/x/crypto v0.25.0 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/appengine v1.6.8 // indirect diff --git a/tools/tfsdk2fw/go.sum b/tools/tfsdk2fw/go.sum index 9fa094611f0..9acb1e6512b 100644 --- a/tools/tfsdk2fw/go.sum +++ b/tools/tfsdk2fw/go.sum @@ -22,20 +22,20 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go v1.54.12 h1:xPDB+GSBZq0rJbmDZF+EyfMbnWRyfEPcn7PZ7bJjXSw= -github.com/aws/aws-sdk-go v1.54.12/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= +github.com/aws/aws-sdk-go v1.54.17 h1:ZV/qwcCIhMHgsJ6iXXPVYI0s1MdLT+5LW28ClzCUPeI= +github.com/aws/aws-sdk-go v1.54.17/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/aws/aws-sdk-go-v2 v1.30.1 h1:4y/5Dvfrhd1MxRDD77SrfsDaj8kUkkljU7XE83NPV+o= github.com/aws/aws-sdk-go-v2 v1.30.1/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3 h1:tW1/Rkad38LA15X4UQtjXZXNKsCgkshC3EbmcUmghTg= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3/go.mod h1:UbnqO+zjqk3uIt9yCACHJ9IVNhyhOCnYk8yA19SAWrM= -github.com/aws/aws-sdk-go-v2/config v1.27.23 h1:Cr/gJEa9NAS7CDAjbnB7tHYb3aLZI2gVggfmSAasDac= -github.com/aws/aws-sdk-go-v2/config v1.27.23/go.mod h1:WMMYHqLCFu5LH05mFOF5tsq1PGEMfKbu083VKqLCd0o= -github.com/aws/aws-sdk-go-v2/credentials v1.17.23 h1:G1CfmLVoO2TdQ8z9dW+JBc/r8+MqyPQhXCafNZcXVZo= -github.com/aws/aws-sdk-go-v2/credentials v1.17.23/go.mod h1:V/DvSURn6kKgcuKEk4qwSwb/fZ2d++FFARtWSbXnLqY= +github.com/aws/aws-sdk-go-v2/config v1.27.24 h1:NM9XicZ5o1CBU/MZaHwFtimRpWx9ohAUAqkG6AqSqPo= +github.com/aws/aws-sdk-go-v2/config v1.27.24/go.mod h1:aXzi6QJTuQRVVusAO8/NxpdTeTyr/wRcybdDtfUwJSs= +github.com/aws/aws-sdk-go-v2/credentials v1.17.24 h1:YclAsrnb1/GTQNt2nzv+756Iw4mF8AOzcDfweWwwm/M= +github.com/aws/aws-sdk-go-v2/credentials v1.17.24/go.mod h1:Hld7tmnAkoBQdTMNYZGzztzKRdA4fCdn9L83LOoigac= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9 h1:Aznqksmd6Rfv2HQN9cpqIV/lQRMaIpJkLLaJ1ZI76no= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9/go.mod h1:WQr3MY7AxGNxaqAtsDWn+fBxmd4XvLkzeqQ8P1VM0/w= -github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.3 h1:J2mHCzCeDQNfBOas73ARi4/CsLm0wYpQ3Itll8dPDBQ= -github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.3/go.mod h1:6rYGWnaLHD+WRF4E709VW+HEEJPKZbNdjHgq9osFXuE= +github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.5 h1:qkipTyOc+ElVS+TgGJCf/6gqu0CL5+ii19W/eMQfY94= +github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.5/go.mod h1:UjB35RXl+ESpnVtyaKqdw11NhMxm90lF9o2zqJNbi14= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13 h1:5SAoZ4jYpGH4721ZNoS1znQrhOfZinOhc4XuTXx/nVc= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13/go.mod h1:+rdA6ZLpaSeM7tSg/B0IEDinCIBJGmW8rKDFkYpP04g= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13 h1:WIijqeaAO7TYFLbhsZmi2rgLEAtWOC1LhxCAVTJlSKw= @@ -48,8 +48,8 @@ github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.32.1 h1:UlnzbXKREuUBbfiaz github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.32.1/go.mod h1:rzwfckqHB3D6OX8s9NNnQ+3Ue9g093uLus91qvw2waQ= github.com/aws/aws-sdk-go-v2/service/account v1.19.1 h1:zrQ4xJWzZvtpk82yTNUa1epainAQKY+vd/VBT9bjUQw= github.com/aws/aws-sdk-go-v2/service/account v1.19.1/go.mod h1:MM1yOaj4b9dKTV559gAznF1cxwH25q9coIs72FOyok8= -github.com/aws/aws-sdk-go-v2/service/acm v1.28.1 h1:fwsAC87QCkj4eQ3/q6qqBux9s0sdBb8HRsUEK9Lpf1Q= -github.com/aws/aws-sdk-go-v2/service/acm v1.28.1/go.mod h1:PlzT5RdIk5yPjDQu9q+SB3UhMY2XIvGhol8vBhZFc0M= +github.com/aws/aws-sdk-go-v2/service/acm v1.28.2 h1:PLrhpvPPOCDViTLv8yihBGudiV+Hub6K6G0WsaYeR+Y= +github.com/aws/aws-sdk-go-v2/service/acm v1.28.2/go.mod h1:PlzT5RdIk5yPjDQu9q+SB3UhMY2XIvGhol8vBhZFc0M= github.com/aws/aws-sdk-go-v2/service/acmpca v1.33.1 h1:kyHfl1VRBejUolTBJ0YIp6rPxAKYyjIms6bQRILrXC8= github.com/aws/aws-sdk-go-v2/service/acmpca v1.33.1/go.mod h1:2a/l5Gz15HVSg1nyQauzh+WmZ5bIWjpigz5k/Z8GqNo= github.com/aws/aws-sdk-go-v2/service/amp v1.27.1 h1:va9j7MGA8jBlQs9KujMlkSdnC26TuEJXv7ywnFjmTZ8= @@ -68,8 +68,8 @@ github.com/aws/aws-sdk-go-v2/service/appflow v1.43.1 h1:yYMQIh6w+YebWeT9A8OdS13x github.com/aws/aws-sdk-go-v2/service/appflow v1.43.1/go.mod h1:eMsImLFMYLuLpKJQRaNmhAarCbu7X29wqo3nu+MQff8= github.com/aws/aws-sdk-go-v2/service/appintegrations v1.27.1 h1:Rav5TKX64RvL5ubk/ESAfubEcAjwDiU6Je1HbZOJECc= github.com/aws/aws-sdk-go-v2/service/appintegrations v1.27.1/go.mod h1:rUtcZvFc4xUm9k5y/ocguib8bblzUxUxeYEFQnDoCHc= -github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.30.1 h1:WahcgbRER7BEmOmEWL4V7BKsj3SIGe8FE19wC/Rkyrk= -github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.30.1/go.mod h1:wRhh/2KOPVIgeazBRqNd033ALrP0DRgalAAFVbyBFMo= +github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.30.2 h1:mRLltTs9uxi18kWQxEawhFNIsaEP6wc1U4H5kw4XVCs= +github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.30.2/go.mod h1:wRhh/2KOPVIgeazBRqNd033ALrP0DRgalAAFVbyBFMo= github.com/aws/aws-sdk-go-v2/service/applicationinsights v1.26.1 h1:w9E9xNNS0/QzEqMY1s2CfYnOB7cqVrmvz24aWoenH9w= github.com/aws/aws-sdk-go-v2/service/applicationinsights v1.26.1/go.mod h1:C7nA/g6h4rQY7ME9BuFuY3IW/3Hp84dzxYOFJUlCVVE= github.com/aws/aws-sdk-go-v2/service/applicationsignals v1.2.1 h1:2bNulxCt2cPl/FfQPj7cUCUA6wGHlwcnWItsmDpfbaw= @@ -148,10 +148,10 @@ github.com/aws/aws-sdk-go-v2/service/codestarconnections v1.27.1 h1:U8XnTJY8BRWB github.com/aws/aws-sdk-go-v2/service/codestarconnections v1.27.1/go.mod h1:HwL5LK+96aciqaQGy9R952m6A1wJVv+28WVAICwUcoU= github.com/aws/aws-sdk-go-v2/service/codestarnotifications v1.24.1 h1:Hlq6tNUpVg2QL8jpmyHqd9JQxclxi8LhHijpnKy+2j0= github.com/aws/aws-sdk-go-v2/service/codestarnotifications v1.24.1/go.mod h1:NFFY3krqG9XpxFUJX4cK7H7JQUd6ZJZtOxhwr3IvTbw= -github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.25.1 h1:w7k+lTipHwSzdikhf+8YkRFnq+Fx3RNb8sZKC519lQM= -github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.25.1/go.mod h1:9B6D4KgCOGxUy70whXp0TMIwc5v0J1doUwqL7d5hbQc= -github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.41.1 h1:8cdo17dADrMJER+tT3y6SbGw0/Hrv9m3BeZQSbbGYFY= -github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.41.1/go.mod h1:wqqFjEnVtltlQXbpYgqfGcDkuml+2it3ikxbWmQ5ypA= +github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.25.3 h1:UHf0sE/ssy2FBmT0W20+OR5PH/w/jhPEaViacHDJwik= +github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.25.3/go.mod h1:9B6D4KgCOGxUy70whXp0TMIwc5v0J1doUwqL7d5hbQc= +github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.41.2 h1:xwPwJ//Dt+AxuHsabV52hBPgw3+4356w1o6wMAzXtes= +github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.41.2/go.mod h1:wqqFjEnVtltlQXbpYgqfGcDkuml+2it3ikxbWmQ5ypA= github.com/aws/aws-sdk-go-v2/service/comprehend v1.33.1 h1:K/sfA9c5qjXi6LedevzfQABo11oqCPI1ScVrhTbR+q4= github.com/aws/aws-sdk-go-v2/service/comprehend v1.33.1/go.mod h1:vOz/b8JUWaHtt9utuOQcazrXDfHb41f+zKd+b3pBRcg= github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.37.1 h1:bCeXSnZn4FKtyoE+B6cuXul8EQOsiCwr6tMTMKdIqu8= @@ -174,12 +174,12 @@ github.com/aws/aws-sdk-go-v2/service/databrew v1.31.1 h1:A4pF8zI5mPHFbCHRCaY0PE6 github.com/aws/aws-sdk-go-v2/service/databrew v1.31.1/go.mod h1:zfR3fjCNYab5wbj84lDOT/BCfvYxgxzqpL/KUHgHht4= github.com/aws/aws-sdk-go-v2/service/datasync v1.40.1 h1:X4p3u+6ddLBGUeMBrY17SDEqKscJptDVutwb6nxU3Io= github.com/aws/aws-sdk-go-v2/service/datasync v1.40.1/go.mod h1:8oB4hGBkkFOl/IFS6KYld4XgtIga3nOkAW9SuNbxdv0= -github.com/aws/aws-sdk-go-v2/service/datazone v1.12.1 h1:wro8aemBaIJtyqM8jYMN72ZNJ9ScQg/AvhkmWL6/Bg8= -github.com/aws/aws-sdk-go-v2/service/datazone v1.12.1/go.mod h1:Lh7Pn/2GA5nwXg/pT5YufMDCH47B4m4/J9aXsOzYUlM= +github.com/aws/aws-sdk-go-v2/service/datazone v1.13.0 h1:D/9gFpZedj1ox4L+DekJqfrZvwD6eTZrpBv8RUeiwr4= +github.com/aws/aws-sdk-go-v2/service/datazone v1.13.0/go.mod h1:Lh7Pn/2GA5nwXg/pT5YufMDCH47B4m4/J9aXsOzYUlM= github.com/aws/aws-sdk-go-v2/service/dax v1.21.1 h1:lGIBbKVTTUveeE0ZtR7qiNf+WB/w+yS7mv2wrIxFrnc= github.com/aws/aws-sdk-go-v2/service/dax v1.21.1/go.mod h1:q1IQsaE9JEPkoF5pB54KJQj2nNNs5Epn/7IzbdGMMNI= -github.com/aws/aws-sdk-go-v2/service/devicefarm v1.24.1 h1:P+hW3WvvZ22MNMpCeMCgdx+7Kg8MynYKYvfKWgH3K68= -github.com/aws/aws-sdk-go-v2/service/devicefarm v1.24.1/go.mod h1:hYmcErsprdwy0wN6BFw7a6cnoWBH3TvVOhTvk4oq90k= +github.com/aws/aws-sdk-go-v2/service/devicefarm v1.25.0 h1:24Zt55ZaUGMrN4XaFSFfT8xNPUFvUtjrWNpAhLnQmG8= +github.com/aws/aws-sdk-go-v2/service/devicefarm v1.25.0/go.mod h1:hYmcErsprdwy0wN6BFw7a6cnoWBH3TvVOhTvk4oq90k= github.com/aws/aws-sdk-go-v2/service/devopsguru v1.32.1 h1:JN2w0v4Bt/sBcidrprwmymXZyfg3D/dwJ4azSgMnUfQ= github.com/aws/aws-sdk-go-v2/service/devopsguru v1.32.1/go.mod h1:twfqPLl38iWhkUTYnsKupGxzn1sSQEWtffrx6TrdVX4= github.com/aws/aws-sdk-go-v2/service/directoryservice v1.27.1 h1:1bJ0BnWfZTcd2fcLlff4z+OcS2b0v4xDkRbigduFNFo= @@ -194,20 +194,24 @@ github.com/aws/aws-sdk-go-v2/service/drs v1.28.1 h1:zYBtPmFwcITzWu78wbagPApJiceb github.com/aws/aws-sdk-go-v2/service/drs v1.28.1/go.mod h1:ntVCpBCBFFQe5C3nL5i+Bcq7ltSeKk01zJKINvuiTkE= github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.1 h1:Szwz1vpZkvfhFMJ0X5uUECgHeUmPAxk1UGqAVs/pARw= github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.1/go.mod h1:b4wouGyJlzkr2HAvPrDGgYNp1EtmlXOkzhEOvl0c0FQ= -github.com/aws/aws-sdk-go-v2/service/ec2 v1.167.1 h1:194kHl9h0FnIZ9PTWeBiAYVX8lKYJ9OT3rZXFM79X2M= -github.com/aws/aws-sdk-go-v2/service/ec2 v1.167.1/go.mod h1:CtLD6CPq9z9dyMxV+H6/M5d9+/ea3dO80um029GXqV0= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.168.0 h1:xOPq0agGC1WMZvFpSZCKEjDVAQnLPZJZGvjuPVF2t9M= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.168.0/go.mod h1:CtLD6CPq9z9dyMxV+H6/M5d9+/ea3dO80um029GXqV0= github.com/aws/aws-sdk-go-v2/service/ecr v1.30.1 h1:zV3FlyuyPzfyFOXKu6mJW9JBGzdtOgpdlj3va+naOD8= github.com/aws/aws-sdk-go-v2/service/ecr v1.30.1/go.mod h1:l0zC7cSb2vAH1fr8+BRlolWT9cwlKpbRC8PjW6tyyIU= github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.25.1 h1:54/7zy+oA2ep9UzWjAtccawCj3ZAXhMXxwBg0yNRxTA= github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.25.1/go.mod h1:2UjSvHCwdRoPF17osaRvfBXuo32KPSvTlGMii5YbjyU= github.com/aws/aws-sdk-go-v2/service/ecs v1.44.1 h1:Kc0ubjRMW0nq5Tu2LDhQBOLzP2/oUceZNP0NUfU+MQo= github.com/aws/aws-sdk-go-v2/service/ecs v1.44.1/go.mod h1:+l39x/ffnRnFeIAe3OzWX6LTv/fkLyo5zNehFgMEwzQ= +github.com/aws/aws-sdk-go-v2/service/efs v1.31.1 h1:cvGFfU0+Wa04EvZ7tjOU5Lfd2RpN5wc9aLIgTTnA1EA= +github.com/aws/aws-sdk-go-v2/service/efs v1.31.1/go.mod h1:KoCfH5bEaBQ2WLZim2slIgtCL1agZ2f9iN/zQBJmxr8= github.com/aws/aws-sdk-go-v2/service/eks v1.46.0 h1:ZPhHHZtAjVohIGIVjXECPfljcPOQ+hjZ1IpgvjPTJ50= github.com/aws/aws-sdk-go-v2/service/eks v1.46.0/go.mod h1:p4Yk0zfWEoLvvQ4V6XZrTmAAPzcevNnEsbUR82NAY0w= github.com/aws/aws-sdk-go-v2/service/elasticache v1.40.1 h1:yJMmaQ3jTpCrsXl0lxQUsvlMZA4/B8ia+99eSbIBjAA= github.com/aws/aws-sdk-go-v2/service/elasticache v1.40.1/go.mod h1:HfavnpYheVa3TXRxHNZYIM/BMI8hmSbtiSbYxqdri/4= -github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.25.1 h1:T1lEDcxMSuHOIeY6CrmTCpRa1lOy9GMi03OZCa9H31g= -github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.25.1/go.mod h1:H8YbT18eu4O03RiBqdDderRdpnHe2Pv439zdO5mmbfU= +github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.26.0 h1:HKN6OvyM2N4mCME+1MgkBemV1Mle3VSuag4Q5+jaPM0= +github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.26.0/go.mod h1:H8YbT18eu4O03RiBqdDderRdpnHe2Pv439zdO5mmbfU= +github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.1 h1:/x4d5NeeoKJAhyZ5zHnBOaxOSotobVb9mXeprdl363I= +github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.1/go.mod h1:Dm9KFhagyV3Ecne6tpYIXWh51N/Q288vpm+0u3P/gbo= github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.1 h1:XuwjSEGfLxo6UJtpJVy/E80GpE1gNclDBv5k1nTQcCs= github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.1/go.mod h1:74D8OQ00uEvvpuG5e4VX+/2v3MC2pltRtzNyXJnEjrI= github.com/aws/aws-sdk-go-v2/service/emr v1.42.0 h1:n3e3/X7ixZrQja0ot3l6M19nw8EarUo1yR0rH4e8aec= @@ -228,8 +232,8 @@ github.com/aws/aws-sdk-go-v2/service/fms v1.35.1 h1:8Juf7iK533V3uRNHHSZZM9Yqhe5t github.com/aws/aws-sdk-go-v2/service/fms v1.35.1/go.mod h1:gVOUVE18pUkhdN7sqOSQ7nF8ZrCRSUDOc1E+tOt42yg= github.com/aws/aws-sdk-go-v2/service/glacier v1.24.1 h1:KlpakUk4p2S9mRz0i15M5ONzY6Ib50vLCGkXh3pX/7Q= github.com/aws/aws-sdk-go-v2/service/glacier v1.24.1/go.mod h1:o6UHomtBF7tyY30psg6hs0ZIlxkBK8SnhgtIrkKFoSA= -github.com/aws/aws-sdk-go-v2/service/globalaccelerator v1.26.1 h1:ZF//0v9qJttmSjTyT3EK8UAvDNs0xQ6xZUtJpEDPgNI= -github.com/aws/aws-sdk-go-v2/service/globalaccelerator v1.26.1/go.mod h1:bWwtuxoMnUPJAn7EjLscm0ddKzf++mnjCUF8J/gjxsA= +github.com/aws/aws-sdk-go-v2/service/globalaccelerator v1.26.2 h1:vd+hQTyOzYuB/SiHLPTFijqRFeWsm1HLQt0lXRCeudE= +github.com/aws/aws-sdk-go-v2/service/globalaccelerator v1.26.2/go.mod h1:bWwtuxoMnUPJAn7EjLscm0ddKzf++mnjCUF8J/gjxsA= github.com/aws/aws-sdk-go-v2/service/grafana v1.24.1 h1:9arpyvo+AHuSlfwd0B4+99mSauANa+ca4UR04TXpMC8= github.com/aws/aws-sdk-go-v2/service/grafana v1.24.1/go.mod h1:w3Do1roFlHxKtjWkjSwevSX4Vbia2CpZ32rfBa38xJs= github.com/aws/aws-sdk-go-v2/service/greengrass v1.25.1 h1:Fw4hUGV/H7uJUf+h/ZkwXHDUrCeRzy6T8JvzsM5J1yE= @@ -268,6 +272,8 @@ github.com/aws/aws-sdk-go-v2/service/ivschat v1.14.1 h1:rmVLJaE6iqVSSeipZnhul8BM github.com/aws/aws-sdk-go-v2/service/ivschat v1.14.1/go.mod h1:IUQ9qdszWBPacNZ36JLkmOxGx/2LCzz/DOZjpg/8tz4= github.com/aws/aws-sdk-go-v2/service/kafka v1.35.1 h1:Q4Jr/gf+7LHjBFTdecQJn4ugVoVszCHzyq1EztrHHkc= github.com/aws/aws-sdk-go-v2/service/kafka v1.35.1/go.mod h1:7/xNH8gqz3k4p4OyW5+s8ecOp1Xg+vBTPMKpMNjeeik= +github.com/aws/aws-sdk-go-v2/service/kafkaconnect v1.19.1 h1:mtbyDAlKv06I6KWTcbhKEUPe51Vinm5RbcmzYI8UWPw= +github.com/aws/aws-sdk-go-v2/service/kafkaconnect v1.19.1/go.mod h1:8XzP4poz+dq07pMe/w+9707EuHp/5lP0OACGvQnVnlo= github.com/aws/aws-sdk-go-v2/service/kendra v1.52.1 h1:mVfjPIVnnSYLWnGYPrTrPlXohOMmYvQpjmYiBLnTh4M= github.com/aws/aws-sdk-go-v2/service/kendra v1.52.1/go.mod h1:mjdRASBq4jLAUxSSBk4jvXdyciq6hZl162yoJ1+BTdc= github.com/aws/aws-sdk-go-v2/service/keyspaces v1.12.1 h1:OmIPCAjROLz+AJyzvNpJRD4cenApFQJAeAIWrkRXOo8= @@ -316,8 +322,8 @@ github.com/aws/aws-sdk-go-v2/service/oam v1.13.1 h1:vLjIsA+s8nlstJpFUs8tPSz0NqB0 github.com/aws/aws-sdk-go-v2/service/oam v1.13.1/go.mod h1:1Ulv69BFp/E+4O+QJF5FgeIbhsOST8lBLyA82ryMG2c= github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.13.1 h1:DUhW/a+R+5o4Y81TJbLJQNCmBpzshEe6jaxJYmIrYOA= github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.13.1/go.mod h1:vpRvxI6cT7QfY/iq1QmhCiD+DF19HsmFLOzWm+jaYkA= -github.com/aws/aws-sdk-go-v2/service/organizations v1.29.1 h1:JlOzx930ntqLP0bgADvyIqtk9owMro3x5azyJie4E64= -github.com/aws/aws-sdk-go-v2/service/organizations v1.29.1/go.mod h1:ZEeCMh1nNfDZyRfCCoeAvqPNSQSF2bcWK5sOgmclQTM= +github.com/aws/aws-sdk-go-v2/service/organizations v1.30.0 h1:UBZxMASlLL9NmxzeqvMFYgavnXR8dqY8PQPnBURc//0= +github.com/aws/aws-sdk-go-v2/service/organizations v1.30.0/go.mod h1:ZEeCMh1nNfDZyRfCCoeAvqPNSQSF2bcWK5sOgmclQTM= github.com/aws/aws-sdk-go-v2/service/osis v1.12.1 h1:dPJf72n6FvEDeLYsTIbkgH0InvRnGMLJGPoX+0yLD/k= github.com/aws/aws-sdk-go-v2/service/osis v1.12.1/go.mod h1:h9yBRbuwOnZwgbOxQ3JidyZa1D4oP58HJ00aUCPuimw= github.com/aws/aws-sdk-go-v2/service/paymentcryptography v1.12.1 h1:yFC5b8Ngj5D0Up8ger9MYTcimD6qV5RfCSoW+RbFYX4= @@ -330,8 +336,8 @@ github.com/aws/aws-sdk-go-v2/service/polly v1.42.1 h1:D/hvXnzmOZmEU+neCUVf07An80 github.com/aws/aws-sdk-go-v2/service/polly v1.42.1/go.mod h1:jVJ3U2lGiKfs4Clt8wsbaf4JfO4BQz962iDPiHtlyqo= github.com/aws/aws-sdk-go-v2/service/pricing v1.30.1 h1:NxMNBOH4xO/MKFxdT2Taw4vIP0biQfnQIzaqnwpOIgw= github.com/aws/aws-sdk-go-v2/service/pricing v1.30.1/go.mod h1:NKVImK3sKfX5U6FcHw5q89j4JlNBtP8E4lI5q4JmAaA= -github.com/aws/aws-sdk-go-v2/service/qbusiness v1.9.1 h1:sbJEqJyK3QQRBo/9+0dB1p4VRgvGFRFGkp/iFag5KQg= -github.com/aws/aws-sdk-go-v2/service/qbusiness v1.9.1/go.mod h1:ryZvrvKgKwER3XGY+2uYvJhj79wCSbqRDagmPpAdN5s= +github.com/aws/aws-sdk-go-v2/service/qbusiness v1.10.0 h1:VE4+A36g5S1wvzTPSNxW4rgtdKlVKqfIGgf5NAM+h6s= +github.com/aws/aws-sdk-go-v2/service/qbusiness v1.10.0/go.mod h1:ryZvrvKgKwER3XGY+2uYvJhj79wCSbqRDagmPpAdN5s= github.com/aws/aws-sdk-go-v2/service/qldb v1.23.1 h1:+Cn7bN/yDM+FV+VZCObhvVryGNTP5Yj1cg2vzxcJdqA= github.com/aws/aws-sdk-go-v2/service/qldb v1.23.1/go.mod h1:vFNiqeuQiwtsbnKCKCIutgYnZQRlXV7wIIgN3xOSKkk= github.com/aws/aws-sdk-go-v2/service/ram v1.27.1 h1:L9OVMWPmtzOaKsIDX+c3Cg8aQ1PGMDVGGo8PX604Edo= @@ -340,14 +346,14 @@ github.com/aws/aws-sdk-go-v2/service/rbin v1.18.1 h1:ExvgjfyVWE6c0yG7m8JJ4SdCGWs github.com/aws/aws-sdk-go-v2/service/rbin v1.18.1/go.mod h1:Lr+d3m2rouz3e+yWjMlz41ZJEPw/FudRP2Bw/s2n8IQ= github.com/aws/aws-sdk-go-v2/service/rds v1.81.2 h1:8hS1TW26euZk4OZtZEYFDLGJ+8MDFRjtKLUBdLFbB64= github.com/aws/aws-sdk-go-v2/service/rds v1.81.2/go.mod h1:EuF7sZqyUlv+NPw1x2hz0XZDrKfqnSh0qHA84xJ3Unw= -github.com/aws/aws-sdk-go-v2/service/redshift v1.46.1 h1:2zQRYtwbdOO+0eWc6Dm24Re4yjEVz6HGU7+6nETV79w= -github.com/aws/aws-sdk-go-v2/service/redshift v1.46.1/go.mod h1:LfV8AL9nxkRM0UixGsY0OxvHj5+VBB89RMNWX6pQOSE= +github.com/aws/aws-sdk-go-v2/service/redshift v1.46.2 h1:NUX1UtoZBmqs1oxoqS+8CS6YAb4Xo0RbOPsBI0ZIs2c= +github.com/aws/aws-sdk-go-v2/service/redshift v1.46.2/go.mod h1:LfV8AL9nxkRM0UixGsY0OxvHj5+VBB89RMNWX6pQOSE= github.com/aws/aws-sdk-go-v2/service/redshiftdata v1.27.1 h1:PE6MxnWY00HuqjqNhUAyNgnU3ysANUxPVWtAzOwsnW0= github.com/aws/aws-sdk-go-v2/service/redshiftdata v1.27.1/go.mod h1:hBO1X3Wx31sH0UTYDPXi4B1cUWQht+j5XQ9rHZjk8eo= github.com/aws/aws-sdk-go-v2/service/redshiftserverless v1.20.1 h1:14jIz6jAewmRc/CtzROzWMarL6/QbIuVO/8hAmSMCv0= github.com/aws/aws-sdk-go-v2/service/redshiftserverless v1.20.1/go.mod h1:NrrLoBm5Xu71gdSDNBnDx7xmkFQluzDhxHPuBkubRd0= -github.com/aws/aws-sdk-go-v2/service/rekognition v1.42.1 h1:7ZrhirY0yIdyT5ZdSKSuHHJsOl1+cl9TSNz/KdJCK8Y= -github.com/aws/aws-sdk-go-v2/service/rekognition v1.42.1/go.mod h1:gRnUZkRF9AGGBo2Vm/Fei0PsgGG3pwY2lJQ7m37Rn+U= +github.com/aws/aws-sdk-go-v2/service/rekognition v1.43.0 h1:fsHQAnrRxbW1CLR94+FeqT+9esYRYiuvGhj4vHbsrE0= +github.com/aws/aws-sdk-go-v2/service/rekognition v1.43.0/go.mod h1:gRnUZkRF9AGGBo2Vm/Fei0PsgGG3pwY2lJQ7m37Rn+U= github.com/aws/aws-sdk-go-v2/service/resourceexplorer2 v1.12.1 h1:T2hY+2V0VYmZM6+z0yN79Sc+ErmlORcSehDFjSaD41c= github.com/aws/aws-sdk-go-v2/service/resourceexplorer2 v1.12.1/go.mod h1:3F3HH/OKef7NKtA4SRhdyU+htOIeQLKI4sAy+8xr+ns= github.com/aws/aws-sdk-go-v2/service/resourcegroups v1.24.1 h1:oLJlhVebfrnc+5EQfZhoK8dYhti4O52W3QmlOWf/0+4= @@ -364,8 +370,8 @@ github.com/aws/aws-sdk-go-v2/service/route53profiles v1.2.1 h1:R50SGyDN2TkTfaHiQ github.com/aws/aws-sdk-go-v2/service/route53profiles v1.2.1/go.mod h1:atspKEGYiBulfNgTrzrDAuurdRVkMqy28UKDbCegMDk= github.com/aws/aws-sdk-go-v2/service/rum v1.19.1 h1:2LfqWtIyncZxc0hK9vScqTkXXY1sj5+jn2tMIpSNAVI= github.com/aws/aws-sdk-go-v2/service/rum v1.19.1/go.mod h1:HGOf93YUR9Na69vxfqcPK1op1LRlqXgd7/gIKdNkjmo= -github.com/aws/aws-sdk-go-v2/service/s3 v1.57.1 h1:aHPtNY87GZ214N4rShgIo+5JQz7ICrJ50i17JbueUTw= -github.com/aws/aws-sdk-go-v2/service/s3 v1.57.1/go.mod h1:hdV0NTYd0RwV4FvNKhKUNbPLZoq9CTr/lke+3I7aCAI= +github.com/aws/aws-sdk-go-v2/service/s3 v1.58.0 h1:4rhV0Hn+bf8IAIUphRX1moBcEvKJipCPmswMCl6Q5mw= +github.com/aws/aws-sdk-go-v2/service/s3 v1.58.0/go.mod h1:hdV0NTYd0RwV4FvNKhKUNbPLZoq9CTr/lke+3I7aCAI= github.com/aws/aws-sdk-go-v2/service/s3control v1.46.1 h1:PGCbHXY4ykRTP072d2IZvJiFt6mW0RJ8vfFTdk2hLbA= github.com/aws/aws-sdk-go-v2/service/s3control v1.46.1/go.mod h1:6rKG97PjdiPjxN2IR3yINOjfchz9OMYtkWchgcn6DWY= github.com/aws/aws-sdk-go-v2/service/scheduler v1.10.1 h1:0PRs0NagmL38++LZ0AtIBJpJotPkGljE+x8VuInM3SI= @@ -386,6 +392,8 @@ github.com/aws/aws-sdk-go-v2/service/servicequotas v1.23.1 h1:XgITaR1uJ05Eb6DdRM github.com/aws/aws-sdk-go-v2/service/servicequotas v1.23.1/go.mod h1:MqIqbHQqx/eHfKoHN4kbCxF8EBP1l16hP97I6KVyORA= github.com/aws/aws-sdk-go-v2/service/sesv2 v1.32.1 h1:we9OxmWVvnWQy5U+Dpo5lSrJSp6k5QDirULkuCTzjC4= github.com/aws/aws-sdk-go-v2/service/sesv2 v1.32.1/go.mod h1:c8d2aYvCLMavTMAe2qYORY5OtoTEIvdDfWIwxVtrtrE= +github.com/aws/aws-sdk-go-v2/service/sfn v1.29.1 h1:c3S0evZRUeenO+v1dnVcwjM+y7UltX130/xKdsT64bA= +github.com/aws/aws-sdk-go-v2/service/sfn v1.29.1/go.mod h1:wjWJ7jSg3hMUUrSEzjb7aDj7AyK7tyU375GuT5HlW2I= github.com/aws/aws-sdk-go-v2/service/shield v1.27.1 h1:8eDBIhkbbCWP/fmdxc1JjmlNSJIDVG0aCTjcS7O0Nr8= github.com/aws/aws-sdk-go-v2/service/shield v1.27.1/go.mod h1:VIQLspYYeFbt8Cg9EtfMkAkAuPvJj2zYz4hX1bhPrKU= github.com/aws/aws-sdk-go-v2/service/signer v1.24.1 h1:nF3MbF/9wh7nVNLfFbUYR8lo28gtoh5ORCei420SGtc= @@ -406,8 +414,8 @@ github.com/aws/aws-sdk-go-v2/service/sso v1.22.1 h1:p1GahKIjyMDZtiKoIn0/jAj/TkMz github.com/aws/aws-sdk-go-v2/service/sso v1.22.1/go.mod h1:/vWdhoIoYA5hYoPZ6fm7Sv4d8701PiG5VKe8/pPJL60= github.com/aws/aws-sdk-go-v2/service/ssoadmin v1.27.1 h1:hULJtFCOI3cDdd/LAt6wO8KhcC/OS7OfXqomXgqaTkQ= github.com/aws/aws-sdk-go-v2/service/ssoadmin v1.27.1/go.mod h1:bu/89Z5+FahsHft6bDNGS3QiFXbcr+4Lq4HkSYBBJFU= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.1 h1:lCEv9f8f+zJ8kcFeAjRZsekLd/x5SAm96Cva+VbUdo8= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.1/go.mod h1:xyFHA4zGxgYkdD73VeezHt3vSKEG9EmFnGwoKlP00u4= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.2 h1:ORnrOK0C4WmYV/uYt3koHEWBLYsRDwk2Np+eEoyV4Z0= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.2/go.mod h1:xyFHA4zGxgYkdD73VeezHt3vSKEG9EmFnGwoKlP00u4= github.com/aws/aws-sdk-go-v2/service/sts v1.30.1 h1:+woJ607dllHJQtsnJLi52ycuqHMwlW+Wqm2Ppsfp4nQ= github.com/aws/aws-sdk-go-v2/service/sts v1.30.1/go.mod h1:jiNR3JqT15Dm+QWq2SRgh0x0bCNSRP2L25+CqPNpJlQ= github.com/aws/aws-sdk-go-v2/service/swf v1.25.1 h1:TvwT8sC8QbE+F9H3AFUE9mirnUzhd8pPYu0J4ZWgOjE= @@ -434,8 +442,8 @@ github.com/aws/aws-sdk-go-v2/service/wafv2 v1.51.2 h1:ohNyyHWxZe2dp1l3YMzrN9OUS0 github.com/aws/aws-sdk-go-v2/service/wafv2 v1.51.2/go.mod h1:kfHast+LcTA5amM8pQFIvTzzAlfKTa2/Vilbb9qLoEY= github.com/aws/aws-sdk-go-v2/service/wellarchitected v1.32.1 h1:FlvBKTXUACdt5eDDB9UAPNwWqs4CCqaU963WSlvWyE8= github.com/aws/aws-sdk-go-v2/service/wellarchitected v1.32.1/go.mod h1:6uG4zrI1dAsqdmv4eEx9VU5NWTIpLSUkh2CQIzDmZfQ= -github.com/aws/aws-sdk-go-v2/service/workspaces v1.43.0 h1:8984C5RyPVPGuTq8xH7id5hkW30OR1tcFCqaLA1rSus= -github.com/aws/aws-sdk-go-v2/service/workspaces v1.43.0/go.mod h1:qphorK9uA0vjz5JyU0djKDxMEIs9Z1C/lb3tYvFeOro= +github.com/aws/aws-sdk-go-v2/service/workspaces v1.44.0 h1:0/1+ji/hqqBMptjTLYUu8s179ZTKfdgvAeIYYJaMSZk= +github.com/aws/aws-sdk-go-v2/service/workspaces v1.44.0/go.mod h1:qphorK9uA0vjz5JyU0djKDxMEIs9Z1C/lb3tYvFeOro= github.com/aws/aws-sdk-go-v2/service/workspacesweb v1.21.1 h1:XcW/rY2et34gZB3oGnfXq0rJqdrQx+4DQqAqx7WM7rU= github.com/aws/aws-sdk-go-v2/service/workspacesweb v1.21.1/go.mod h1:L/DSEMyw+H/K0MGmGx+bd/+6ZjOsE+WYW4V4RHegI0U= github.com/aws/aws-sdk-go-v2/service/xray v1.27.1 h1:asXBSkcpo1VnbeARCHlhWdsdRBbB1P2LwQ/vQUgoRhI= @@ -531,34 +539,34 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hc-install v0.6.4 h1:QLqlM56/+SIIGvGcfFiwMY3z5WGXT066suo/v9Km8e0= -github.com/hashicorp/hc-install v0.6.4/go.mod h1:05LWLy8TD842OtgcfBbOT0WMoInBMUSHjmDx10zuBIA= -github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc= -github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4= +github.com/hashicorp/hc-install v0.7.0 h1:Uu9edVqjKQxxuD28mR5TikkKDd/p55S8vzPC1659aBk= +github.com/hashicorp/hc-install v0.7.0/go.mod h1:ELmmzZlGnEcqoUMKUuykHaPCIR1sYLYX+KSggWSKZuA= +github.com/hashicorp/hcl/v2 v2.21.0 h1:lve4q/o/2rqwYOgUg3y3V2YPyD1/zkCLGjIV74Jit14= +github.com/hashicorp/hcl/v2 v2.21.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ= github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg= github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec= github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A= -github.com/hashicorp/terraform-plugin-framework v1.9.0 h1:caLcDoxiRucNi2hk8+j3kJwkKfvHznubyFsJMWfZqKU= -github.com/hashicorp/terraform-plugin-framework v1.9.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM= +github.com/hashicorp/terraform-plugin-framework v1.10.0 h1:xXhICE2Fns1RYZxEQebwkB2+kXouLC932Li9qelozrc= +github.com/hashicorp/terraform-plugin-framework v1.10.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM= github.com/hashicorp/terraform-plugin-framework-jsontypes v0.1.0 h1:b8vZYB/SkXJT4YPbT3trzE6oJ7dPyMy68+9dEDKsJjE= github.com/hashicorp/terraform-plugin-framework-jsontypes v0.1.0/go.mod h1:tP9BC3icoXBz72evMS5UTFvi98CiKhPdXF6yLs1wS8A= github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 h1:gm5b1kHgFFhaKFhm4h2TgvMUlNzFAtUqlcOWnWPm+9E= github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1/go.mod h1:MsjL1sQ9L7wGwzJ5RjcI6FzEMdyoBnw+XK8ZnOvQOLY= github.com/hashicorp/terraform-plugin-framework-timetypes v0.4.0 h1:XLI93Oqw2/KTzYjgCXrUnm8LBkGAiHC/mDQg5g5Vob4= github.com/hashicorp/terraform-plugin-framework-timetypes v0.4.0/go.mod h1:mGuieb3bqKFYwEYB4lCMt302Z3siyv4PFYk/41wAUps= -github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc= -github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg= +github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 h1:bxZfGo9DIUoLLtHMElsu+zwqI4IsMZQBRRy4iLzZJ8E= +github.com/hashicorp/terraform-plugin-framework-validators v0.13.0/go.mod h1:wGeI02gEhj9nPANU62F2jCaHjXulejm/X+af4PdZaNo= github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co= github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ= github.com/hashicorp/terraform-plugin-mux v0.16.0 h1:RCzXHGDYwUwwqfYYWJKBFaS3fQsWn/ZECEiW7p2023I= github.com/hashicorp/terraform-plugin-mux v0.16.0/go.mod h1:PF79mAsPc8CpusXPfEVa4X8PtkB+ngWoiUClMrNZlYo= github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 h1:kJiWGx2kiQVo97Y5IOGR4EMcZ8DtMswHhUuFibsCQQE= github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0/go.mod h1:sl/UoabMc37HA6ICVMmGO+/0wofkVIRxf+BMb/dnoIg= -github.com/hashicorp/terraform-plugin-testing v1.8.0 h1:wdYIgwDk4iO933gC4S8KbKdnMQShu6BXuZQPScmHvpk= -github.com/hashicorp/terraform-plugin-testing v1.8.0/go.mod h1:o2kOgf18ADUaZGhtOl0YCkfIxg01MAiMATT2EtIHlZk= +github.com/hashicorp/terraform-plugin-testing v1.9.0 h1:xOsQRqqlHKXpFq6etTxih3ubdK3HVDtfE1IY7Rpd37o= +github.com/hashicorp/terraform-plugin-testing v1.9.0/go.mod h1:fhhVx/8+XNJZTD5o3b4stfZ6+q7z9+lIWigIYdT6/44= github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= @@ -664,8 +672,8 @@ github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.52.0 h1:kAytSRJYoIy4eJtDOfSGf9LOCD4QdXFN37YJs0+bYrw= go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.52.0/go.mod h1:l6VnFEqDdeMSMfwULTDDY9ewlnlVLhmvBainVT+h/Zs= go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= @@ -677,8 +685,8 @@ go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39S golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -709,13 +717,13 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=