From c945dd0ce74145798d142487d4930c3952182c84 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sun, 7 Apr 2024 19:30:13 +0100 Subject: [PATCH 1/2] chime: Upgrade to AWS SDK v2 --- go.mod | 1 + go.sum | 2 + internal/conns/awsclient_gen.go | 6 +-- .../chime/service_endpoints_gen_test.go | 40 ++++++++++++------- internal/service/chime/service_package.go | 28 ------------- internal/service/chime/service_package_gen.go | 17 ++++---- names/data/names_data.csv | 2 +- names/names.go | 1 + 8 files changed, 43 insertions(+), 54 deletions(-) delete mode 100644 internal/service/chime/service_package.go diff --git a/go.mod b/go.mod index 8c3fc696a28..6b236339445 100644 --- a/go.mod +++ b/go.mod @@ -214,6 +214,7 @@ require ( github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // 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.5 // indirect + github.com/aws/aws-sdk-go-v2/service/chime v1.30.4 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.6 // indirect diff --git a/go.sum b/go.sum index 1bbe0c12522..77f654c867d 100644 --- a/go.sum +++ b/go.sum @@ -82,6 +82,8 @@ github.com/aws/aws-sdk-go-v2/service/bedrockagent v1.5.1 h1:LWEonf7hVyLqY4AK46rj github.com/aws/aws-sdk-go-v2/service/bedrockagent v1.5.1/go.mod h1:6CwV+GE3wrFqkrU2LB8cajHMWJn7jFFhRtxBQiOZ5kw= github.com/aws/aws-sdk-go-v2/service/budgets v1.22.4 h1:sVv+p2Wo+sUXa8dC1pCMJ/+9ncOriq8EiRWvAkOuaLY= github.com/aws/aws-sdk-go-v2/service/budgets v1.22.4/go.mod h1:JFS3MaNoisHXHQm5/xRQjj1tICixIgT8Vv32D0lV5NE= +github.com/aws/aws-sdk-go-v2/service/chime v1.30.4 h1:IOShdLvjngLscUJozVEaPl3P2B2JSGfP7qVOJPdWaj0= +github.com/aws/aws-sdk-go-v2/service/chime v1.30.4/go.mod h1:5Aw544A4C/xQGeP5kRixFnj0078cPoSBmbLVFGWapOc= github.com/aws/aws-sdk-go-v2/service/chimesdkmediapipelines v1.15.5 h1:FgeK3aPbB/ARkhxUXfSn9d2ibb4Q9kUhHl/dWwqIy8Y= github.com/aws/aws-sdk-go-v2/service/chimesdkmediapipelines v1.15.5/go.mod h1:yPGCqtEO6NNwd6kebco4VSvyHkKbjjwd7K6g49Ze/Uw= github.com/aws/aws-sdk-go-v2/service/chimesdkvoice v1.14.4 h1:rea/sazWAyaUXPcbSCBDGKM1Kb6YiU25xvNnN0p7AyM= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 35c6c862819..e7b6b1b4369 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -23,6 +23,7 @@ import ( bedrock_sdkv2 "github.com/aws/aws-sdk-go-v2/service/bedrock" bedrockagent_sdkv2 "github.com/aws/aws-sdk-go-v2/service/bedrockagent" budgets_sdkv2 "github.com/aws/aws-sdk-go-v2/service/budgets" + chime_sdkv2 "github.com/aws/aws-sdk-go-v2/service/chime" chimesdkmediapipelines_sdkv2 "github.com/aws/aws-sdk-go-v2/service/chimesdkmediapipelines" chimesdkvoice_sdkv2 "github.com/aws/aws-sdk-go-v2/service/chimesdkvoice" cleanrooms_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cleanrooms" @@ -162,7 +163,6 @@ import ( autoscaling_sdkv1 "github.com/aws/aws-sdk-go/service/autoscaling" backup_sdkv1 "github.com/aws/aws-sdk-go/service/backup" batch_sdkv1 "github.com/aws/aws-sdk-go/service/batch" - chime_sdkv1 "github.com/aws/aws-sdk-go/service/chime" cloudformation_sdkv1 "github.com/aws/aws-sdk-go/service/cloudformation" cloudfront_sdkv1 "github.com/aws/aws-sdk-go/service/cloudfront" cloudwatchrum_sdkv1 "github.com/aws/aws-sdk-go/service/cloudwatchrum" @@ -377,8 +377,8 @@ func (c *AWSClient) CURClient(ctx context.Context) *costandusagereportservice_sd return errs.Must(client[*costandusagereportservice_sdkv2.Client](ctx, c, names.CUR, make(map[string]any))) } -func (c *AWSClient) ChimeConn(ctx context.Context) *chime_sdkv1.Chime { - return errs.Must(conn[*chime_sdkv1.Chime](ctx, c, names.Chime, make(map[string]any))) +func (c *AWSClient) ChimeClient(ctx context.Context) *chime_sdkv2.Client { + return errs.Must(client[*chime_sdkv2.Client](ctx, c, names.Chime, make(map[string]any))) } func (c *AWSClient) ChimeSDKMediaPipelinesClient(ctx context.Context) *chimesdkmediapipelines_sdkv2.Client { diff --git a/internal/service/chime/service_endpoints_gen_test.go b/internal/service/chime/service_endpoints_gen_test.go index 366dde7099c..3896336c8bc 100644 --- a/internal/service/chime/service_endpoints_gen_test.go +++ b/internal/service/chime/service_endpoints_gen_test.go @@ -4,17 +4,17 @@ package chime_test import ( "context" + "errors" "fmt" "maps" - "net/url" "os" "path/filepath" "reflect" "strings" "testing" - "github.com/aws/aws-sdk-go/aws/endpoints" - chime_sdkv1 "github.com/aws/aws-sdk-go/service/chime" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + chime_sdkv2 "github.com/aws/aws-sdk-go-v2/service/chime" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -212,32 +212,42 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S } func defaultEndpoint(region string) string { - r := endpoints.DefaultResolver() + r := chime_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(chime_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), chime_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) if err != nil { return err.Error() } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return url.String() + return ep.URI.String() } func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { t.Helper() - client := meta.ChimeConn(ctx) - - req, _ := client.ListAccountsRequest(&chime_sdkv1.ListAccountsInput{}) + var endpoint string - req.HTTPRequest.URL.Path = "/" + client := meta.ChimeClient(ctx) - endpoint := req.HTTPRequest.URL.String() + _, err := client.ListAccounts(ctx, &chime_sdkv2.ListAccountsInput{}, + func(opts *chime_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &endpoint), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) + } return endpoint } diff --git a/internal/service/chime/service_package.go b/internal/service/chime/service_package.go deleted file mode 100644 index 2ddfe0505ea..00000000000 --- a/internal/service/chime/service_package.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package chime - -import ( - "context" - - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - request_sdkv1 "github.com/aws/aws-sdk-go/aws/request" - chime_sdkv1 "github.com/aws/aws-sdk-go/service/chime" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" -) - -// CustomizeConn customizes a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) CustomizeConn(ctx context.Context, conn *chime_sdkv1.Chime) (*chime_sdkv1.Chime, error) { - conn.Handlers.Retry.PushBack(func(r *request_sdkv1.Request) { - // When calling CreateVoiceConnector across multiple resources, - // the API can randomly return a BadRequestException without explanation - if r.Operation.Name == "CreateVoiceConnector" { - if tfawserr.ErrMessageContains(r.Error, chime_sdkv1.ErrCodeBadRequestException, "Service received a bad request") { - r.Retryable = aws_sdkv1.Bool(true) - } - } - }) - - return conn, nil -} diff --git a/internal/service/chime/service_package_gen.go b/internal/service/chime/service_package_gen.go index e875959ddac..43a4201e971 100644 --- a/internal/service/chime/service_package_gen.go +++ b/internal/service/chime/service_package_gen.go @@ -5,9 +5,8 @@ package chime import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - chime_sdkv1 "github.com/aws/aws-sdk-go/service/chime" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + chime_sdkv2 "github.com/aws/aws-sdk-go-v2/service/chime" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -68,11 +67,15 @@ func (p *servicePackage) ServicePackageName() string { return names.Chime } -// 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) (*chime_sdkv1.Chime, error) { - sess := config["session"].(*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) (*chime_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return chime_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil + return chime_sdkv2.NewFromConfig(cfg, func(o *chime_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/names/data/names_data.csv b/names/data/names_data.csv index c2dc14cb28a..5f06a776efa 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -42,7 +42,7 @@ billingconductor,billingconductor,billingconductor,,,billingconductor,,,BillingC braket,braket,braket,braket,,braket,,,Braket,Braket,,1,,,aws_braket_,,braket_,Braket,Amazon,,x,,,,,Braket,,, ce,ce,costexplorer,costexplorer,,ce,,costexplorer,CE,CostExplorer,,1,,,aws_ce_,,ce_,CE (Cost Explorer),AWS,,,,,,,Cost Explorer,ListCostCategoryDefinitions,, ,,,,,,,,,,,,,,,,,Chatbot,AWS,x,,,,,,,,,No SDK support -chime,chime,chime,chime,,chime,,,Chime,Chime,,1,,,aws_chime_,,chime_,Chime,Amazon,,,,,,,Chime,ListAccounts,, +chime,chime,chime,chime,,chime,,,Chime,Chime,,,2,,aws_chime_,,chime_,Chime,Amazon,,,,,,,Chime,ListAccounts,, chime-sdk-identity,chimesdkidentity,chimesdkidentity,chimesdkidentity,,chimesdkidentity,,,ChimeSDKIdentity,ChimeSDKIdentity,,1,,,aws_chimesdkidentity_,,chimesdkidentity_,Chime SDK Identity,Amazon,,x,,,,,Chime SDK Identity,,, chime-sdk-mediapipelines,chimesdkmediapipelines,chimesdkmediapipelines,chimesdkmediapipelines,,chimesdkmediapipelines,,,ChimeSDKMediaPipelines,ChimeSDKMediaPipelines,,,2,,aws_chimesdkmediapipelines_,,chimesdkmediapipelines_,Chime SDK Media Pipelines,Amazon,,,,,,,Chime SDK Media Pipelines,ListMediaPipelines,, chime-sdk-meetings,chimesdkmeetings,chimesdkmeetings,chimesdkmeetings,,chimesdkmeetings,,,ChimeSDKMeetings,ChimeSDKMeetings,,1,,,aws_chimesdkmeetings_,,chimesdkmeetings_,Chime SDK Meetings,Amazon,,x,,,,,Chime SDK Meetings,,, diff --git a/names/names.go b/names/names.go index 7b2c5cf4324..dc68471f559 100644 --- a/names/names.go +++ b/names/names.go @@ -37,6 +37,7 @@ const ( BatchEndpointID = "batch" BedrockEndpointID = "bedrock" BudgetsEndpointID = "budgets" + ChimeEndpointID = "chime" ChimeSDKMediaPipelinesEndpointID = "media-pipelines-chime" ChimeSDKVoiceEndpointID = "voice-chime" CloudSearchEndpointID = "cloudsearch" From 426cff39c1601a6e571cd7041b26d3c81b1a3ab3 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Fri, 19 Jul 2024 09:42:40 -0400 Subject: [PATCH 2/2] r/aws_chime_voice_connector_group: handle NotFound error on delete The delete operation calls an update when the `connector` argument is configured, which was not handling cases where the group did not exist (deleted out of band). This change prevents this error from propagating back to the user, and instead just removes the resource from state when the group cannot be found during the delete operation. --- .changelog/36774.txt | 3 +++ internal/service/chime/voice_connector_group.go | 8 +++++++- internal/service/chime/voice_connector_group_test.go | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changelog/36774.txt diff --git a/.changelog/36774.txt b/.changelog/36774.txt new file mode 100644 index 00000000000..44d53925f24 --- /dev/null +++ b/.changelog/36774.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_chime_voice_connector_group: Properly handle voice connector groups deleted out of band +``` diff --git a/internal/service/chime/voice_connector_group.go b/internal/service/chime/voice_connector_group.go index 42d80c6f73f..ef6f3042abd 100644 --- a/internal/service/chime/voice_connector_group.go +++ b/internal/service/chime/voice_connector_group.go @@ -97,7 +97,7 @@ func resourceVoiceConnectorGroupRead(ctx context.Context, d *schema.ResourceData resp, err = findVoiceConnectorGroupByID(ctx, conn, d.Id()) } - if !d.IsNewResource() && tfresource.NotFound(err) { + if !d.IsNewResource() && errs.IsA[*awstypes.NotFoundException](err) { log.Printf("[WARN] Chime Voice conector group %s not found", d.Id()) d.SetId("") return diags @@ -147,6 +147,12 @@ func resourceVoiceConnectorGroupDelete(ctx context.Context, d *schema.ResourceDa conn := meta.(*conns.AWSClient).ChimeSDKVoiceClient(ctx) if v, ok := d.GetOk("connector"); ok && v.(*schema.Set).Len() > 0 { + // Exit before attempting connector updates if the group does not exist + _, err := findVoiceConnectorGroupByID(ctx, conn, d.Id()) + if errs.IsA[*awstypes.NotFoundException](err) { + return diags + } + if err := resourceVoiceConnectorGroupUpdate(ctx, d, meta); err != nil { return err } diff --git a/internal/service/chime/voice_connector_group_test.go b/internal/service/chime/voice_connector_group_test.go index d2409f306a8..f844430b23f 100644 --- a/internal/service/chime/voice_connector_group_test.go +++ b/internal/service/chime/voice_connector_group_test.go @@ -14,8 +14,8 @@ import ( "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" tfchime "github.com/hashicorp/terraform-provider-aws/internal/service/chime" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -196,7 +196,7 @@ func testAccCheckVoiceConnectorGroupDestroy(ctx context.Context) resource.TestCh return tfchime.FindVoiceConnectorGroupByID(ctx, conn, rs.Primary.ID) }) - if tfresource.NotFound(err) { + if errs.IsA[*awstypes.NotFoundException](err) { continue }