From 51b0a0d65e9d71bb3c370b932716330bbcbf59c1 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Nov 2023 13:53:55 -0600 Subject: [PATCH 01/22] aws_chime_voice_connector: retry when new resource not found --- internal/service/chime/voice_connector.go | 53 ++++++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/internal/service/chime/voice_connector.go b/internal/service/chime/voice_connector.go index c70245eeeb1..307b790ca57 100644 --- a/internal/service/chime/voice_connector.go +++ b/internal/service/chime/voice_connector.go @@ -6,16 +6,19 @@ package chime import ( "context" "log" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/chimesdkvoice" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/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" "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" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -98,26 +101,27 @@ func resourceVoiceConnectorRead(ctx context.Context, d *schema.ResourceData, met var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - getInput := &chimesdkvoice.GetVoiceConnectorInput{ - VoiceConnectorId: aws.String(d.Id()), - } + outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, 1*time.Minute, func() (interface{}, error) { + return findVoiceConnectorByID(ctx, conn, d.Id()) + }, d.IsNewResource()) - resp, err := conn.GetVoiceConnectorWithContext(ctx, getInput) - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Chime Voice connector %s not found", d.Id()) d.SetId("") return diags } - if err != nil || resp.VoiceConnector == nil { - return sdkdiag.AppendErrorf(diags, "getting Voice connector (%s): %s", d.Id(), err) + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading Voice Connector (%s): %s", d.Id(), err) } - d.Set("arn", resp.VoiceConnector.VoiceConnectorArn) - d.Set("aws_region", resp.VoiceConnector.AwsRegion) - d.Set("outbound_host_name", resp.VoiceConnector.OutboundHostName) - d.Set("require_encryption", resp.VoiceConnector.RequireEncryption) - d.Set("name", resp.VoiceConnector.Name) + resp := outputRaw.(*chimesdkvoice.VoiceConnector) + + d.Set("arn", resp.VoiceConnectorArn) + d.Set("aws_region", resp.AwsRegion) + d.Set("outbound_host_name", resp.OutboundHostName) + d.Set("require_encryption", resp.RequireEncryption) + d.Set("name", resp.Name) return diags } @@ -159,3 +163,28 @@ func resourceVoiceConnectorDelete(ctx context.Context, d *schema.ResourceData, m return diags } + +func findVoiceConnectorByID(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoice, id string) (*chimesdkvoice.VoiceConnector, error) { + in := &chimesdkvoice.GetVoiceConnectorInput{ + VoiceConnectorId: aws.String(id), + } + + resp, err := conn.GetVoiceConnectorWithContext(ctx, in) + + if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + if resp == nil || resp.VoiceConnector == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + if err != nil { + return nil, err + } + + return resp.VoiceConnector, nil +} From 59c70dae7482c4769935e011665e5dc3b37f4e80 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Nov 2023 16:23:00 -0600 Subject: [PATCH 02/22] aws_chime_voice_connector: use try read in tests --- internal/service/chime/chime_test.go | 50 ++++++------ internal/service/chime/exports_test.go | 9 +++ internal/service/chime/voice_connector.go | 78 ++++++++++++++++--- .../service/chime/voice_connector_test.go | 42 ++++++---- 4 files changed, 128 insertions(+), 51 deletions(-) create mode 100644 internal/service/chime/exports_test.go diff --git a/internal/service/chime/chime_test.go b/internal/service/chime/chime_test.go index 8d762e6d7ae..8ddbe2669e2 100644 --- a/internal/service/chime/chime_test.go +++ b/internal/service/chime/chime_test.go @@ -19,31 +19,31 @@ func TestAccChime_serial(t *testing.T) { "update": testAccVoiceConnector_update, "tags": testAccVoiceConnector_tags, }, - "VoiceConnectorGroup": { - "basic": testAccVoiceConnectorGroup_basic, - "disappears": testAccVoiceConnectorGroup_disappears, - "update": testAccVoiceConnectorGroup_update, - }, - "VoiceConnectorLogging": { - "basic": testAccVoiceConnectorLogging_basic, - "disappears": testAccVoiceConnectorLogging_disappears, - "update": testAccVoiceConnectorLogging_update, - }, - "VoiceConnectorOrigination": { - "basic": testAccVoiceConnectorOrigination_basic, - "disappears": testAccVoiceConnectorOrigination_disappears, - "update": testAccVoiceConnectorOrigination_update, - }, - "VoiceConnectorTermination": { - "basic": testAccVoiceConnectorTermination_basic, - "disappears": testAccVoiceConnectorTermination_disappears, - "update": testAccVoiceConnectorTermination_update, - }, - "VoiceConnectorTerminationCredentials": { - "basic": testAccVoiceConnectorTerminationCredentials_basic, - "disappears": testAccVoiceConnectorTerminationCredentials_disappears, - "update": testAccVoiceConnectorTerminationCredentials_update, - }, + //"VoiceConnectorGroup": { + // "basic": testAccVoiceConnectorGroup_basic, + // "disappears": testAccVoiceConnectorGroup_disappears, + // "update": testAccVoiceConnectorGroup_update, + //}, + //"VoiceConnectorLogging": { + // "basic": testAccVoiceConnectorLogging_basic, + // "disappears": testAccVoiceConnectorLogging_disappears, + // "update": testAccVoiceConnectorLogging_update, + //}, + //"VoiceConnectorOrigination": { + // "basic": testAccVoiceConnectorOrigination_basic, + // "disappears": testAccVoiceConnectorOrigination_disappears, + // "update": testAccVoiceConnectorOrigination_update, + //}, + //"VoiceConnectorTermination": { + // "basic": testAccVoiceConnectorTermination_basic, + // "disappears": testAccVoiceConnectorTermination_disappears, + // "update": testAccVoiceConnectorTermination_update, + //}, + //"VoiceConnectorTerminationCredentials": { + // "basic": testAccVoiceConnectorTerminationCredentials_basic, + // "disappears": testAccVoiceConnectorTerminationCredentials_disappears, + // "update": testAccVoiceConnectorTerminationCredentials_update, + //}, } acctest.RunSerialTests2Levels(t, testCases, 0) diff --git a/internal/service/chime/exports_test.go b/internal/service/chime/exports_test.go new file mode 100644 index 00000000000..fd834fc9a85 --- /dev/null +++ b/internal/service/chime/exports_test.go @@ -0,0 +1,9 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package chime + +// Exports for use in tests only. +var ( + FindVoiceConnectorWithRetry = findVoiceConnectorWithRetry +) diff --git a/internal/service/chime/voice_connector.go b/internal/service/chime/voice_connector.go index 307b790ca57..446f1997688 100644 --- a/internal/service/chime/voice_connector.go +++ b/internal/service/chime/voice_connector.go @@ -12,6 +12,7 @@ import ( "github.com/aws/aws-sdk-go/service/chimesdkvoice" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -45,8 +46,8 @@ func ResourceVoiceConnector() *schema.Resource { Type: schema.TypeString, ForceNew: true, Optional: true, - Default: chimesdkvoice.VoiceConnectorAwsRegionUsEast1, - ValidateFunc: validation.StringInSlice([]string{chimesdkvoice.VoiceConnectorAwsRegionUsEast1, chimesdkvoice.VoiceConnectorAwsRegionUsWest2}, false), + Computed: true, + ValidateFunc: validation.StringInSlice(chimesdkvoice.VoiceConnectorAwsRegion_Values(), false), }, "name": { Type: schema.TypeString, @@ -65,10 +66,23 @@ func ResourceVoiceConnector() *schema.Resource { names.AttrTagsAll: tftags.TagsSchemaComputed(), }, - CustomizeDiff: verify.SetTagsDiff, + CustomizeDiff: customdiff.All( + verify.SetTagsDiff, + resourceVoiceConnectorDefaultRegion, + ), } } +func resourceVoiceConnectorDefaultRegion(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error { + if v, ok := diff.Get("aws_region").(string); !ok || v == "" { + if err := diff.SetNew("aws_region", meta.(*conns.AWSClient).Region); err != nil { + return err + } + } + + return nil +} + func resourceVoiceConnectorCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) @@ -76,10 +90,13 @@ func resourceVoiceConnectorCreate(ctx context.Context, d *schema.ResourceData, m createInput := &chimesdkvoice.CreateVoiceConnectorInput{ Name: aws.String(d.Get("name").(string)), RequireEncryption: aws.Bool(d.Get("require_encryption").(bool)), + Tags: getTagsIn(ctx), } if v, ok := d.GetOk("aws_region"); ok { createInput.AwsRegion = aws.String(v.(string)) + } else { + createInput.AwsRegion = aws.String(meta.(*conns.AWSClient).Region) } resp, err := conn.CreateVoiceConnectorWithContext(ctx, createInput) @@ -89,10 +106,10 @@ func resourceVoiceConnectorCreate(ctx context.Context, d *schema.ResourceData, m d.SetId(aws.StringValue(resp.VoiceConnector.VoiceConnectorId)) - tagsConn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - if err := createTags(ctx, tagsConn, aws.StringValue(resp.VoiceConnector.VoiceConnectorArn), getTagsIn(ctx)); err != nil { - return sdkdiag.AppendErrorf(diags, "setting Chime Voice Connector (%s) tags: %s", d.Id(), err) - } + //tagsConn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) + //if err := createTags(ctx, tagsConn, aws.StringValue(resp.VoiceConnector.VoiceConnectorArn), getTagsIn(ctx)); err != nil { + // return sdkdiag.AppendErrorf(diags, "setting Chime Voice Connector (%s) tags: %s", d.Id(), err) + //} return append(diags, resourceVoiceConnectorRead(ctx, d, meta)...) } @@ -101,9 +118,29 @@ func resourceVoiceConnectorRead(ctx context.Context, d *schema.ResourceData, met var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, 1*time.Minute, func() (interface{}, error) { - return findVoiceConnectorByID(ctx, conn, d.Id()) - }, d.IsNewResource()) + //var resp *chimesdkvoice.VoiceConnector + //err := tfresource.Retry(ctx, 1*time.Minute, func() *retry.RetryError { + // var err error + // resp, err = findVoiceConnectorByID(ctx, conn, d.Id()) + // if d.IsNewResource() && tfresource.NotFound(err) { + // return retry.RetryableError(err) + // } + // + // if err != nil { + // return retry.NonRetryableError(err) + // } + // + // return nil + //}, tfresource.WithDelay(5*time.Second)) + + resp, err := findVoiceConnectorWithRetry(ctx, conn, d.IsNewResource(), d.Id()) + + if tfresource.TimedOut(err) { + resp, err = findVoiceConnectorByID(ctx, conn, d.Id()) + } + //outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, 1*time.Minute, func() (interface{}, error) { + // return findVoiceConnectorByID(ctx, conn, d.Id()) + //}, d.IsNewResource()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Chime Voice connector %s not found", d.Id()) @@ -115,7 +152,7 @@ func resourceVoiceConnectorRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading Voice Connector (%s): %s", d.Id(), err) } - resp := outputRaw.(*chimesdkvoice.VoiceConnector) + // resp := outputRaw.(*chimesdkvoice.VoiceConnector) d.Set("arn", resp.VoiceConnectorArn) d.Set("aws_region", resp.AwsRegion) @@ -188,3 +225,22 @@ func findVoiceConnectorByID(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoi return resp.VoiceConnector, nil } + +func findVoiceConnectorWithRetry(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoice, isNewResource bool, id string) (*chimesdkvoice.VoiceConnector, error) { + var resp *chimesdkvoice.VoiceConnector + err := tfresource.Retry(ctx, 1*time.Minute, func() *retry.RetryError { + var err error + resp, err = findVoiceConnectorByID(ctx, conn, id) + if isNewResource && tfresource.NotFound(err) { + return retry.RetryableError(err) + } + + if err != nil { + return retry.NonRetryableError(err) + } + + return nil + }, tfresource.WithDelay(5*time.Second)) + + return resp, err +} diff --git a/internal/service/chime/voice_connector_test.go b/internal/service/chime/voice_connector_test.go index 15aa116a003..e4559e19134 100644 --- a/internal/service/chime/voice_connector_test.go +++ b/internal/service/chime/voice_connector_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/chimesdkvoice" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -17,6 +16,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfchime "github.com/hashicorp/terraform-provider-aws/internal/service/chime" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func testAccVoiceConnector_basic(t *testing.T) { @@ -29,7 +29,7 @@ func testAccVoiceConnector_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -41,7 +41,7 @@ func testAccVoiceConnector_basic(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckVoiceConnectorExists(ctx, resourceName, voiceConnector), resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("vc-%s", vcName)), - resource.TestCheckResourceAttr(resourceName, "aws_region", chimesdkvoice.VoiceConnectorAwsRegionUsEast1), + resource.TestCheckResourceAttrSet(resourceName, "aws_region"), resource.TestCheckResourceAttr(resourceName, "require_encryption", "true"), ), }, @@ -64,7 +64,7 @@ func testAccVoiceConnector_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -93,7 +93,7 @@ func testAccVoiceConnector_update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -105,7 +105,7 @@ func testAccVoiceConnector_update(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckVoiceConnectorExists(ctx, resourceName, voiceConnector), resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("vc-%s", vcName)), - resource.TestCheckResourceAttr(resourceName, "aws_region", chimesdkvoice.VoiceConnectorAwsRegionUsEast1), + resource.TestCheckResourceAttrSet(resourceName, "aws_region"), resource.TestCheckResourceAttr(resourceName, "require_encryption", "true"), ), }, @@ -136,7 +136,7 @@ func testAccVoiceConnector_tags(t *testing.T) { acctest.PreCheck(ctx, t) // Legacy chime resources are always created in us-east-1, and the ListTags operation // can behave unexpectedly when configured with a different region. - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -258,17 +258,29 @@ func testAccCheckVoiceConnectorDestroy(ctx context.Context) resource.TestCheckFu continue } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorInput{ - VoiceConnectorId: aws.String(rs.Primary.ID), + + _, err := tfchime.FindVoiceConnectorWithRetry(ctx, conn, false, rs.Primary.ID) + + if tfresource.NotFound(err) { + continue } - resp, err := conn.GetVoiceConnectorWithContext(ctx, input) - if err == nil { - if resp.VoiceConnector != nil && aws.StringValue(resp.VoiceConnector.Name) != "" { - return fmt.Errorf("error Chime Voice Connector still exists") - } + + if err != nil { + return err } - return nil + + //input := &chimesdkvoice.GetVoiceConnectorInput{ + // VoiceConnectorId: aws.String(rs.Primary.ID), + //} + //resp, err := conn.GetVoiceConnectorWithContext(ctx, input) + //if err == nil { + // if resp.VoiceConnector != nil && aws.StringValue(resp.VoiceConnector.Name) != "" { + // return fmt.Errorf("error Chime Voice Connector still exists") + // } + //} + return fmt.Errorf("voice connector still exists: (%s)", rs.Primary.ID) } + return nil } } From a3a2f86eac640d2ba558e048b7c52f69cace8959 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Nov 2023 16:25:21 -0600 Subject: [PATCH 03/22] aws_chime_voice_connector: cleanup --- internal/service/chime/voice_connector.go | 25 ------------------- .../service/chime/voice_connector_test.go | 12 --------- 2 files changed, 37 deletions(-) diff --git a/internal/service/chime/voice_connector.go b/internal/service/chime/voice_connector.go index 446f1997688..0f9d9b29f32 100644 --- a/internal/service/chime/voice_connector.go +++ b/internal/service/chime/voice_connector.go @@ -106,11 +106,6 @@ func resourceVoiceConnectorCreate(ctx context.Context, d *schema.ResourceData, m d.SetId(aws.StringValue(resp.VoiceConnector.VoiceConnectorId)) - //tagsConn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - //if err := createTags(ctx, tagsConn, aws.StringValue(resp.VoiceConnector.VoiceConnectorArn), getTagsIn(ctx)); err != nil { - // return sdkdiag.AppendErrorf(diags, "setting Chime Voice Connector (%s) tags: %s", d.Id(), err) - //} - return append(diags, resourceVoiceConnectorRead(ctx, d, meta)...) } @@ -118,29 +113,11 @@ func resourceVoiceConnectorRead(ctx context.Context, d *schema.ResourceData, met var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - //var resp *chimesdkvoice.VoiceConnector - //err := tfresource.Retry(ctx, 1*time.Minute, func() *retry.RetryError { - // var err error - // resp, err = findVoiceConnectorByID(ctx, conn, d.Id()) - // if d.IsNewResource() && tfresource.NotFound(err) { - // return retry.RetryableError(err) - // } - // - // if err != nil { - // return retry.NonRetryableError(err) - // } - // - // return nil - //}, tfresource.WithDelay(5*time.Second)) - resp, err := findVoiceConnectorWithRetry(ctx, conn, d.IsNewResource(), d.Id()) if tfresource.TimedOut(err) { resp, err = findVoiceConnectorByID(ctx, conn, d.Id()) } - //outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, 1*time.Minute, func() (interface{}, error) { - // return findVoiceConnectorByID(ctx, conn, d.Id()) - //}, d.IsNewResource()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Chime Voice connector %s not found", d.Id()) @@ -152,8 +129,6 @@ func resourceVoiceConnectorRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading Voice Connector (%s): %s", d.Id(), err) } - // resp := outputRaw.(*chimesdkvoice.VoiceConnector) - d.Set("arn", resp.VoiceConnectorArn) d.Set("aws_region", resp.AwsRegion) d.Set("outbound_host_name", resp.OutboundHostName) diff --git a/internal/service/chime/voice_connector_test.go b/internal/service/chime/voice_connector_test.go index e4559e19134..967ee3df33e 100644 --- a/internal/service/chime/voice_connector_test.go +++ b/internal/service/chime/voice_connector_test.go @@ -29,7 +29,6 @@ func testAccVoiceConnector_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -64,7 +63,6 @@ func testAccVoiceConnector_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -93,7 +91,6 @@ func testAccVoiceConnector_update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -269,15 +266,6 @@ func testAccCheckVoiceConnectorDestroy(ctx context.Context) resource.TestCheckFu return err } - //input := &chimesdkvoice.GetVoiceConnectorInput{ - // VoiceConnectorId: aws.String(rs.Primary.ID), - //} - //resp, err := conn.GetVoiceConnectorWithContext(ctx, input) - //if err == nil { - // if resp.VoiceConnector != nil && aws.StringValue(resp.VoiceConnector.Name) != "" { - // return fmt.Errorf("error Chime Voice Connector still exists") - // } - //} return fmt.Errorf("voice connector still exists: (%s)", rs.Primary.ID) } From 6b87af72ce18c909ab0173a5645c46f564c1e3a2 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Nov 2023 16:42:31 -0600 Subject: [PATCH 04/22] cleanup unused tagging funcs --- internal/service/chime/chime_test.go | 50 ++++++++++++++-------------- internal/service/chime/generate.go | 2 +- internal/service/chime/tags_gen.go | 9 ----- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/internal/service/chime/chime_test.go b/internal/service/chime/chime_test.go index 8ddbe2669e2..8d762e6d7ae 100644 --- a/internal/service/chime/chime_test.go +++ b/internal/service/chime/chime_test.go @@ -19,31 +19,31 @@ func TestAccChime_serial(t *testing.T) { "update": testAccVoiceConnector_update, "tags": testAccVoiceConnector_tags, }, - //"VoiceConnectorGroup": { - // "basic": testAccVoiceConnectorGroup_basic, - // "disappears": testAccVoiceConnectorGroup_disappears, - // "update": testAccVoiceConnectorGroup_update, - //}, - //"VoiceConnectorLogging": { - // "basic": testAccVoiceConnectorLogging_basic, - // "disappears": testAccVoiceConnectorLogging_disappears, - // "update": testAccVoiceConnectorLogging_update, - //}, - //"VoiceConnectorOrigination": { - // "basic": testAccVoiceConnectorOrigination_basic, - // "disappears": testAccVoiceConnectorOrigination_disappears, - // "update": testAccVoiceConnectorOrigination_update, - //}, - //"VoiceConnectorTermination": { - // "basic": testAccVoiceConnectorTermination_basic, - // "disappears": testAccVoiceConnectorTermination_disappears, - // "update": testAccVoiceConnectorTermination_update, - //}, - //"VoiceConnectorTerminationCredentials": { - // "basic": testAccVoiceConnectorTerminationCredentials_basic, - // "disappears": testAccVoiceConnectorTerminationCredentials_disappears, - // "update": testAccVoiceConnectorTerminationCredentials_update, - //}, + "VoiceConnectorGroup": { + "basic": testAccVoiceConnectorGroup_basic, + "disappears": testAccVoiceConnectorGroup_disappears, + "update": testAccVoiceConnectorGroup_update, + }, + "VoiceConnectorLogging": { + "basic": testAccVoiceConnectorLogging_basic, + "disappears": testAccVoiceConnectorLogging_disappears, + "update": testAccVoiceConnectorLogging_update, + }, + "VoiceConnectorOrigination": { + "basic": testAccVoiceConnectorOrigination_basic, + "disappears": testAccVoiceConnectorOrigination_disappears, + "update": testAccVoiceConnectorOrigination_update, + }, + "VoiceConnectorTermination": { + "basic": testAccVoiceConnectorTermination_basic, + "disappears": testAccVoiceConnectorTermination_disappears, + "update": testAccVoiceConnectorTermination_update, + }, + "VoiceConnectorTerminationCredentials": { + "basic": testAccVoiceConnectorTerminationCredentials_basic, + "disappears": testAccVoiceConnectorTerminationCredentials_disappears, + "update": testAccVoiceConnectorTerminationCredentials_update, + }, } acctest.RunSerialTests2Levels(t, testCases, 0) diff --git a/internal/service/chime/generate.go b/internal/service/chime/generate.go index 7bbc5209df2..d8055064d03 100644 --- a/internal/service/chime/generate.go +++ b/internal/service/chime/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 -ListTagsInIDElem=ResourceARN -ServiceTagsSlice -TagInIDElem=ResourceARN -CreateTags -UpdateTags -AWSSDKServicePackage=chimesdkvoice +//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsInIDElem=ResourceARN -ServiceTagsSlice -TagInIDElem=ResourceARN -UpdateTags -AWSSDKServicePackage=chimesdkvoice //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/chime/tags_gen.go b/internal/service/chime/tags_gen.go index 6e3ad528667..38a3edba190 100644 --- a/internal/service/chime/tags_gen.go +++ b/internal/service/chime/tags_gen.go @@ -97,15 +97,6 @@ func setTagsOut(ctx context.Context, tags []*chimesdkvoice.Tag) { } } -// createTags creates chime service tags for new resources. -func createTags(ctx context.Context, conn chimesdkvoiceiface.ChimeSDKVoiceAPI, identifier string, tags []*chimesdkvoice.Tag) error { - if len(tags) == 0 { - return nil - } - - return updateTags(ctx, conn, identifier, nil, KeyValueTags(ctx, tags)) -} - // updateTags updates chime service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. From e93ff7f78b6718d1cbbe8c913fd0469b2b839392 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Nov 2023 16:51:16 -0600 Subject: [PATCH 05/22] add CHANGELOG entry --- .changelog/34334.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/34334.txt diff --git a/.changelog/34334.txt b/.changelog/34334.txt new file mode 100644 index 00000000000..3997fcaf182 --- /dev/null +++ b/.changelog/34334.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_chime_voice_connector: Fix `read` error when resource is not created in `us-east-1` +``` \ No newline at end of file From 9c803a08cfab3b9f7e8d76eaa894469f8ecea69e Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Nov 2023 17:40:54 -0600 Subject: [PATCH 06/22] aws_chime_voice_connector_termination: add retry --- internal/service/chime/exports_test.go | 3 +- internal/service/chime/find.go | 31 ++++++++++ internal/service/chime/voice_connector.go | 24 +------- .../chime/voice_connector_termination.go | 56 ++++++++++++++----- .../chime/voice_connector_termination_test.go | 23 ++++---- .../service/chime/voice_connector_test.go | 4 +- 6 files changed, 91 insertions(+), 50 deletions(-) create mode 100644 internal/service/chime/find.go diff --git a/internal/service/chime/exports_test.go b/internal/service/chime/exports_test.go index fd834fc9a85..dd68d0de913 100644 --- a/internal/service/chime/exports_test.go +++ b/internal/service/chime/exports_test.go @@ -5,5 +5,6 @@ package chime // Exports for use in tests only. var ( - FindVoiceConnectorWithRetry = findVoiceConnectorWithRetry + FindVoiceConnectorByID = findVoiceConnectorByID + FindVoiceConnectorTerminationByID = findVoiceConnectorTerminationByID ) diff --git a/internal/service/chime/find.go b/internal/service/chime/find.go new file mode 100644 index 00000000000..bfa6299e21b --- /dev/null +++ b/internal/service/chime/find.go @@ -0,0 +1,31 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package chime + +import ( + "context" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" +) + +func FindVoiceConnectorResourceWithRetry[T any](ctx context.Context, isNewResource bool, f func() (T, error)) (T, error) { + var resp T + err := tfresource.Retry(ctx, 1*time.Minute, func() *retry.RetryError { + var err error + resp, err = f() + if isNewResource && tfresource.NotFound(err) { + return retry.RetryableError(err) + } + + if err != nil { + return retry.NonRetryableError(err) + } + + return nil + }, tfresource.WithDelay(5*time.Second)) + + return resp, err +} diff --git a/internal/service/chime/voice_connector.go b/internal/service/chime/voice_connector.go index 0f9d9b29f32..0d9bacbf9af 100644 --- a/internal/service/chime/voice_connector.go +++ b/internal/service/chime/voice_connector.go @@ -6,7 +6,6 @@ package chime import ( "context" "log" - "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/chimesdkvoice" @@ -113,7 +112,9 @@ func resourceVoiceConnectorRead(ctx context.Context, d *schema.ResourceData, met var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - resp, err := findVoiceConnectorWithRetry(ctx, conn, d.IsNewResource(), d.Id()) + resp, err := FindVoiceConnectorResourceWithRetry(ctx, d.IsNewResource(), func() (*chimesdkvoice.VoiceConnector, error) { + return findVoiceConnectorByID(ctx, conn, d.Id()) + }) if tfresource.TimedOut(err) { resp, err = findVoiceConnectorByID(ctx, conn, d.Id()) @@ -200,22 +201,3 @@ func findVoiceConnectorByID(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoi return resp.VoiceConnector, nil } - -func findVoiceConnectorWithRetry(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoice, isNewResource bool, id string) (*chimesdkvoice.VoiceConnector, error) { - var resp *chimesdkvoice.VoiceConnector - err := tfresource.Retry(ctx, 1*time.Minute, func() *retry.RetryError { - var err error - resp, err = findVoiceConnectorByID(ctx, conn, id) - if isNewResource && tfresource.NotFound(err) { - return retry.RetryableError(err) - } - - if err != nil { - return retry.NonRetryableError(err) - } - - return nil - }, tfresource.WithDelay(5*time.Second)) - - return resp, err -} diff --git a/internal/service/chime/voice_connector_termination.go b/internal/service/chime/voice_connector_termination.go index ccc46db20cd..729faa7fbe2 100644 --- a/internal/service/chime/voice_connector_termination.go +++ b/internal/service/chime/voice_connector_termination.go @@ -12,10 +12,12 @@ import ( "github.com/aws/aws-sdk-go/service/chimesdkvoice" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/flex" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) // @SDKResource("aws_chime_voice_connector_termination") @@ -113,13 +115,15 @@ func resourceVoiceConnectorTerminationCreate(ctx context.Context, d *schema.Reso func resourceVoiceConnectorTerminationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorTerminationInput{ - VoiceConnectorId: aws.String(d.Id()), - } + resp, err := FindVoiceConnectorResourceWithRetry(ctx, d.IsNewResource(), func() (*chimesdkvoice.Termination, error) { + return findVoiceConnectorTerminationByID(ctx, conn, d.Id()) + }) - resp, err := conn.GetVoiceConnectorTerminationWithContext(ctx, input) + if tfresource.TimedOut(err) { + resp, err = findVoiceConnectorTerminationByID(ctx, conn, d.Id()) + } - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Chime Voice Connector (%s) termination not found, removing from state", d.Id()) d.SetId("") return nil @@ -129,18 +133,14 @@ func resourceVoiceConnectorTerminationRead(ctx context.Context, d *schema.Resour return diag.Errorf("getting Chime Voice Connector (%s) termination: %s", d.Id(), err) } - if resp == nil || resp.Termination == nil { - return diag.Errorf("getting Chime Voice Connector (%s) termination: empty response", d.Id()) - } + d.Set("cps_limit", resp.CpsLimit) + d.Set("disabled", resp.Disabled) + d.Set("default_phone_number", resp.DefaultPhoneNumber) - d.Set("cps_limit", resp.Termination.CpsLimit) - d.Set("disabled", resp.Termination.Disabled) - d.Set("default_phone_number", resp.Termination.DefaultPhoneNumber) - - if err := d.Set("calling_regions", flex.FlattenStringList(resp.Termination.CallingRegions)); err != nil { + if err := d.Set("calling_regions", flex.FlattenStringList(resp.CallingRegions)); err != nil { return diag.Errorf("setting termination calling regions (%s): %s", d.Id(), err) } - if err := d.Set("cidr_allow_list", flex.FlattenStringList(resp.Termination.CidrAllowedList)); err != nil { + if err := d.Set("cidr_allow_list", flex.FlattenStringList(resp.CidrAllowedList)); err != nil { return diag.Errorf("setting termination cidr allow list (%s): %s", d.Id(), err) } @@ -201,3 +201,31 @@ func resourceVoiceConnectorTerminationDelete(ctx context.Context, d *schema.Reso return nil } + +func findVoiceConnectorTerminationByID(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoice, id string) (*chimesdkvoice.Termination, error) { + in := &chimesdkvoice.GetVoiceConnectorInput{ + VoiceConnectorId: aws.String(id), + } + + input := &chimesdkvoice.GetVoiceConnectorTerminationInput{ + VoiceConnectorId: aws.String(id), + } + + resp, err := conn.GetVoiceConnectorTerminationWithContext(ctx, input) + if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + if resp == nil || resp.Termination == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + if err != nil { + return nil, err + } + + return resp.Termination, nil +} diff --git a/internal/service/chime/voice_connector_termination_test.go b/internal/service/chime/voice_connector_termination_test.go index e9c9c333fe4..4d5b76358b3 100644 --- a/internal/service/chime/voice_connector_termination_test.go +++ b/internal/service/chime/voice_connector_termination_test.go @@ -9,15 +9,14 @@ import ( "testing" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/chimesdkvoice" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" 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" tfchime "github.com/hashicorp/terraform-provider-aws/internal/service/chime" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func testAccVoiceConnectorTermination_basic(t *testing.T) { @@ -28,7 +27,7 @@ func testAccVoiceConnectorTermination_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -62,7 +61,7 @@ func testAccVoiceConnectorTermination_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -89,7 +88,7 @@ func testAccVoiceConnectorTermination_update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -190,12 +189,12 @@ func testAccCheckVoiceConnectorTerminationDestroy(ctx context.Context) resource. continue } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorTerminationInput{ - VoiceConnectorId: aws.String(rs.Primary.ID), - } - resp, err := conn.GetVoiceConnectorTerminationWithContext(ctx, input) - if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.Termination, error) { + return tfchime.FindVoiceConnectorTerminationByID(ctx, conn, rs.Primary.ID) + }) + + if tfresource.NotFound(err) { continue } @@ -203,9 +202,7 @@ func testAccCheckVoiceConnectorTerminationDestroy(ctx context.Context) resource. return err } - if resp != nil && resp.Termination != nil { - return fmt.Errorf("error Chime Voice Connector Termination still exists") - } + return fmt.Errorf("voice connector termination still exists: (%s)", rs.Primary.ID) } return nil diff --git a/internal/service/chime/voice_connector_test.go b/internal/service/chime/voice_connector_test.go index 967ee3df33e..8aac5bf0f2a 100644 --- a/internal/service/chime/voice_connector_test.go +++ b/internal/service/chime/voice_connector_test.go @@ -256,7 +256,9 @@ func testAccCheckVoiceConnectorDestroy(ctx context.Context) resource.TestCheckFu } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - _, err := tfchime.FindVoiceConnectorWithRetry(ctx, conn, false, rs.Primary.ID) + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.VoiceConnector, error) { + return tfchime.FindVoiceConnectorByID(ctx, conn, rs.Primary.ID) + }) if tfresource.NotFound(err) { continue From c42b600668cab2471bd3ed16de8212bc843c6699 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Nov 2023 17:42:10 -0600 Subject: [PATCH 07/22] aws_chime_voice_connector_termination: cleanup --- internal/service/chime/voice_connector_termination_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/service/chime/voice_connector_termination_test.go b/internal/service/chime/voice_connector_termination_test.go index 4d5b76358b3..5d8c7a3d87f 100644 --- a/internal/service/chime/voice_connector_termination_test.go +++ b/internal/service/chime/voice_connector_termination_test.go @@ -27,7 +27,6 @@ func testAccVoiceConnectorTermination_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -61,7 +60,6 @@ func testAccVoiceConnectorTermination_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -88,7 +86,6 @@ func testAccVoiceConnectorTermination_update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), From 456b0675508874355ae78d584f9c9faee5cc6b45 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Nov 2023 17:43:09 -0600 Subject: [PATCH 08/22] CHANGELOG --- .changelog/34334.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changelog/34334.txt b/.changelog/34334.txt index 3997fcaf182..b0e3750e74b 100644 --- a/.changelog/34334.txt +++ b/.changelog/34334.txt @@ -1,3 +1,7 @@ ```release-note:bug resource/aws_chime_voice_connector: Fix `read` error when resource is not created in `us-east-1` +``` + +```release-note:bug +resource/aws_chime_voice_connector_termination: Fix `read` error when resource is not created in `us-east-1` ``` \ No newline at end of file From 001dee50f9b750563d77283a3b3affb528e24271 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Nov 2023 17:56:46 -0600 Subject: [PATCH 09/22] aws_chime_voice_connector: do not set region in handler --- internal/service/chime/voice_connector.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/service/chime/voice_connector.go b/internal/service/chime/voice_connector.go index 0d9bacbf9af..2a64e145cc5 100644 --- a/internal/service/chime/voice_connector.go +++ b/internal/service/chime/voice_connector.go @@ -94,8 +94,6 @@ func resourceVoiceConnectorCreate(ctx context.Context, d *schema.ResourceData, m if v, ok := d.GetOk("aws_region"); ok { createInput.AwsRegion = aws.String(v.(string)) - } else { - createInput.AwsRegion = aws.String(meta.(*conns.AWSClient).Region) } resp, err := conn.CreateVoiceConnectorWithContext(ctx, createInput) From 5987719203aae747acd52bae723640897e23795f Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 12:23:28 -0600 Subject: [PATCH 10/22] aws_chime_voice_connector_group: add retry on read --- internal/service/chime/exports_test.go | 1 + .../service/chime/voice_connector_group.go | 52 +++++++++++++++---- .../chime/voice_connector_group_test.go | 40 +++++++------- .../service/chime/voice_connector_test.go | 12 ++--- 4 files changed, 71 insertions(+), 34 deletions(-) diff --git a/internal/service/chime/exports_test.go b/internal/service/chime/exports_test.go index dd68d0de913..64e2bb7e616 100644 --- a/internal/service/chime/exports_test.go +++ b/internal/service/chime/exports_test.go @@ -6,5 +6,6 @@ package chime // Exports for use in tests only. var ( FindVoiceConnectorByID = findVoiceConnectorByID + FindVoiceConnectorGroupByID = findVoiceConnectorGroupByID FindVoiceConnectorTerminationByID = findVoiceConnectorTerminationByID ) diff --git a/internal/service/chime/voice_connector_group.go b/internal/service/chime/voice_connector_group.go index 18ef1c6a2fa..6000f436cc5 100644 --- a/internal/service/chime/voice_connector_group.go +++ b/internal/service/chime/voice_connector_group.go @@ -11,9 +11,12 @@ import ( "github.com/aws/aws-sdk-go/service/chimesdkvoice" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/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" "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/tfresource" ) // @SDKResource("aws_chime_voice_connector_group") @@ -79,27 +82,33 @@ func resourceVoiceConnectorGroupCreate(ctx context.Context, d *schema.ResourceDa } func resourceVoiceConnectorGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - getInput := &chimesdkvoice.GetVoiceConnectorGroupInput{ - VoiceConnectorGroupId: aws.String(d.Id()), + resp, err := FindVoiceConnectorResourceWithRetry(ctx, d.IsNewResource(), func() (*chimesdkvoice.VoiceConnectorGroup, error) { + return findVoiceConnectorGroupByID(ctx, conn, d.Id()) + }) + + if tfresource.TimedOut(err) { + resp, err = findVoiceConnectorGroupByID(ctx, conn, d.Id()) } - resp, err := conn.GetVoiceConnectorGroupWithContext(ctx, getInput) - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Chime Voice conector group %s not found", d.Id()) d.SetId("") return nil } - if err != nil || resp.VoiceConnectorGroup == nil { - return diag.Errorf("getting Chime Voice Connector group (%s): %s", d.Id(), err) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading Voice Connector Group (%s): %s", d.Id(), err) } - d.Set("name", resp.VoiceConnectorGroup.Name) + d.Set("name", resp.Name) - if err := d.Set("connector", flattenVoiceConnectorItems(resp.VoiceConnectorGroup.VoiceConnectorItems)); err != nil { - return diag.Errorf("setting Chime Voice Connector group items (%s): %s", d.Id(), err) + if err := d.Set("connector", flattenVoiceConnectorItems(resp.VoiceConnectorItems)); err != nil { + return sdkdiag.AppendErrorf(diags, "setting Chime Voice Connector group items (%s): %s", d.Id(), err) } + return nil } @@ -176,3 +185,28 @@ func flattenVoiceConnectorItems(connectors []*chimesdkvoice.VoiceConnectorItem) } return rawConnectors } + +func findVoiceConnectorGroupByID(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoice, id string) (*chimesdkvoice.VoiceConnectorGroup, error) { + in := &chimesdkvoice.GetVoiceConnectorGroupInput{ + VoiceConnectorGroupId: aws.String(id), + } + + resp, err := conn.GetVoiceConnectorGroupWithContext(ctx, in) + + if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + if resp == nil || resp.VoiceConnectorGroup == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + if err != nil { + return nil, err + } + + return resp.VoiceConnectorGroup, nil +} diff --git a/internal/service/chime/voice_connector_group_test.go b/internal/service/chime/voice_connector_group_test.go index efea54d40c2..882d4489a50 100644 --- a/internal/service/chime/voice_connector_group_test.go +++ b/internal/service/chime/voice_connector_group_test.go @@ -8,8 +8,6 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/chimesdkvoice" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -17,6 +15,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfchime "github.com/hashicorp/terraform-provider-aws/internal/service/chime" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func testAccVoiceConnectorGroup_basic(t *testing.T) { @@ -29,7 +28,6 @@ func testAccVoiceConnectorGroup_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -64,7 +62,6 @@ func testAccVoiceConnectorGroup_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -93,7 +90,6 @@ func testAccVoiceConnectorGroup_update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -172,16 +168,17 @@ func testAccCheckVoiceConnectorGroupExists(ctx context.Context, name string, vc } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorGroupInput{ - VoiceConnectorGroupId: aws.String(rs.Primary.ID), - } - resp, err := conn.GetVoiceConnectorGroupWithContext(ctx, input) - if err != nil || resp.VoiceConnectorGroup == nil { + resp, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.VoiceConnectorGroup, error) { + return tfchime.FindVoiceConnectorGroupByID(ctx, conn, rs.Primary.ID) + }) + + if err != nil { return err } - vc = resp.VoiceConnectorGroup + vc = resp + return nil } } @@ -193,17 +190,22 @@ func testAccCheckVoiceConnectorGroupDestroy(ctx context.Context) resource.TestCh continue } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorGroupInput{ - VoiceConnectorGroupId: aws.String(rs.Primary.ID), + + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.VoiceConnectorGroup, error) { + return tfchime.FindVoiceConnectorGroupByID(ctx, conn, rs.Primary.ID) + }) + + if tfresource.NotFound(err) { + continue } - resp, err := conn.GetVoiceConnectorGroupWithContext(ctx, input) - if err == nil { - if resp.VoiceConnectorGroup != nil && aws.StringValue(resp.VoiceConnectorGroup.Name) != "" { - return fmt.Errorf("error Chime Voice Connector still exists") - } + + if err != nil { + return err } - return nil + + return fmt.Errorf("voice connector group still exists: (%s)", rs.Primary.ID) } + return nil } } diff --git a/internal/service/chime/voice_connector_test.go b/internal/service/chime/voice_connector_test.go index 8aac5bf0f2a..b70753d8588 100644 --- a/internal/service/chime/voice_connector_test.go +++ b/internal/service/chime/voice_connector_test.go @@ -8,7 +8,6 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/chimesdkvoice" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -234,15 +233,16 @@ func testAccCheckVoiceConnectorExists(ctx context.Context, name string, vc *chim } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorInput{ - VoiceConnectorId: aws.String(rs.Primary.ID), - } - resp, err := conn.GetVoiceConnectorWithContext(ctx, input) + + resp, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.VoiceConnector, error) { + return tfchime.FindVoiceConnectorByID(ctx, conn, rs.Primary.ID) + }) + if err != nil { return err } - vc = resp.VoiceConnector + vc = resp return nil } From e89c152b605d238b24fcc9ed32c52cfbf684b947 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 12:24:04 -0600 Subject: [PATCH 11/22] CHANGELOG --- .changelog/34334.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changelog/34334.txt b/.changelog/34334.txt index b0e3750e74b..7dcc0b2ee50 100644 --- a/.changelog/34334.txt +++ b/.changelog/34334.txt @@ -4,4 +4,8 @@ resource/aws_chime_voice_connector: Fix `read` error when resource is not create ```release-note:bug resource/aws_chime_voice_connector_termination: Fix `read` error when resource is not created in `us-east-1` +``` + +```release-note:bug +resource/aws_chime_voice_connector_group: Fix `read` error when resource is not created in `us-east-1` ``` \ No newline at end of file From bca4e1a9516cae9e2b0039afca2357ffec8dfc47 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 12:43:07 -0600 Subject: [PATCH 12/22] aws_chime_voice_connector_logging: add retry on read --- internal/service/chime/exports_test.go | 1 + .../service/chime/voice_connector_logging.go | 45 +++++++++++++++---- .../chime/voice_connector_logging_test.go | 17 ++----- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/internal/service/chime/exports_test.go b/internal/service/chime/exports_test.go index 64e2bb7e616..c71a899062f 100644 --- a/internal/service/chime/exports_test.go +++ b/internal/service/chime/exports_test.go @@ -7,5 +7,6 @@ package chime var ( FindVoiceConnectorByID = findVoiceConnectorByID FindVoiceConnectorGroupByID = findVoiceConnectorGroupByID + FindVoiceConnectorLoggingByID = findVoiceConnectorLoggingByID FindVoiceConnectorTerminationByID = findVoiceConnectorTerminationByID ) diff --git a/internal/service/chime/voice_connector_logging.go b/internal/service/chime/voice_connector_logging.go index b19cbc78123..6d3ac502c96 100644 --- a/internal/service/chime/voice_connector_logging.go +++ b/internal/service/chime/voice_connector_logging.go @@ -11,8 +11,10 @@ import ( "github.com/aws/aws-sdk-go/service/chimesdkvoice" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/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" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) // @SDKResource("aws_chime_voice_connector_logging") @@ -70,22 +72,22 @@ func resourceVoiceConnectorLoggingCreate(ctx context.Context, d *schema.Resource func resourceVoiceConnectorLoggingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorLoggingConfigurationInput{ - VoiceConnectorId: aws.String(d.Id()), + resp, err := FindVoiceConnectorResourceWithRetry(ctx, d.IsNewResource(), func() (*chimesdkvoice.LoggingConfiguration, error) { + return findVoiceConnectorLoggingByID(ctx, conn, d.Id()) + }) + + if tfresource.TimedOut(err) { + resp, err = findVoiceConnectorLoggingByID(ctx, conn, d.Id()) } - resp, err := conn.GetVoiceConnectorLoggingConfigurationWithContext(ctx, input) - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Chime Voice Connector logging configuration %s not found", d.Id()) d.SetId("") return nil } - if err != nil || resp.LoggingConfiguration == nil { - return diag.Errorf("getting Chime Voice Connector (%s) logging configuration: %s", d.Id(), err) - } - d.Set("enable_media_metric_logs", resp.LoggingConfiguration.EnableMediaMetricLogs) - d.Set("enable_sip_logs", resp.LoggingConfiguration.EnableSIPLogs) + d.Set("enable_media_metric_logs", resp.EnableMediaMetricLogs) + d.Set("enable_sip_logs", resp.EnableSIPLogs) d.Set("voice_connector_id", d.Id()) return nil @@ -134,3 +136,28 @@ func resourceVoiceConnectorLoggingDelete(ctx context.Context, d *schema.Resource return nil } + +func findVoiceConnectorLoggingByID(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoice, id string) (*chimesdkvoice.LoggingConfiguration, error) { + in := &chimesdkvoice.GetVoiceConnectorLoggingConfigurationInput{ + VoiceConnectorId: aws.String(id), + } + + resp, err := conn.GetVoiceConnectorLoggingConfigurationWithContext(ctx, in) + + if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + if resp == nil || resp.LoggingConfiguration == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + if err != nil { + return nil, err + } + + return resp.LoggingConfiguration, nil +} diff --git a/internal/service/chime/voice_connector_logging_test.go b/internal/service/chime/voice_connector_logging_test.go index e4c1054a91a..0584dafd2ea 100644 --- a/internal/service/chime/voice_connector_logging_test.go +++ b/internal/service/chime/voice_connector_logging_test.go @@ -8,8 +8,6 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/chimesdkvoice" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -27,7 +25,6 @@ func testAccVoiceConnectorLogging_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -59,7 +56,6 @@ func testAccVoiceConnectorLogging_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -86,7 +82,6 @@ func testAccVoiceConnectorLogging_update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -158,19 +153,15 @@ func testAccCheckVoiceConnectorLoggingExists(ctx context.Context, name string) r } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorLoggingConfigurationInput{ - VoiceConnectorId: aws.String(rs.Primary.ID), - } - resp, err := conn.GetVoiceConnectorLoggingConfigurationWithContext(ctx, input) + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.LoggingConfiguration, error) { + return tfchime.FindVoiceConnectorLoggingByID(ctx, conn, rs.Primary.ID) + }) + if err != nil { return err } - if resp == nil || resp.LoggingConfiguration == nil { - return fmt.Errorf("no Chime Voice Connector logging configureation (%s) found", rs.Primary.ID) - } - return nil } } From edd69cfcb4bab88c96bbd5a0bff2f4225031958d Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 12:43:46 -0600 Subject: [PATCH 13/22] CHANGELOG --- .changelog/34334.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changelog/34334.txt b/.changelog/34334.txt index 7dcc0b2ee50..20f0c105fa0 100644 --- a/.changelog/34334.txt +++ b/.changelog/34334.txt @@ -8,4 +8,8 @@ resource/aws_chime_voice_connector_termination: Fix `read` error when resource i ```release-note:bug resource/aws_chime_voice_connector_group: Fix `read` error when resource is not created in `us-east-1` +``` + +```release-note:bug +resource/aws_chime_voice_connector_logging: Fix `read` error when resource is not created in `us-east-1` ``` \ No newline at end of file From 16bf933039359323887891ed873fd12043fec72d Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 13:32:43 -0600 Subject: [PATCH 14/22] aws_chime_voice_connector_origination: add retry --- internal/service/chime/exports_test.go | 1 + .../chime/voice_connector_logging_test.go | 6 +-- .../chime/voice_connector_origination.go | 47 ++++++++++++++----- .../chime/voice_connector_origination_test.go | 36 ++++---------- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/internal/service/chime/exports_test.go b/internal/service/chime/exports_test.go index c71a899062f..18687cd7aa3 100644 --- a/internal/service/chime/exports_test.go +++ b/internal/service/chime/exports_test.go @@ -8,5 +8,6 @@ var ( FindVoiceConnectorByID = findVoiceConnectorByID FindVoiceConnectorGroupByID = findVoiceConnectorGroupByID FindVoiceConnectorLoggingByID = findVoiceConnectorLoggingByID + FindVoiceConnectorOriginationByID = findVoiceConnectorOriginationByID FindVoiceConnectorTerminationByID = findVoiceConnectorTerminationByID ) diff --git a/internal/service/chime/voice_connector_logging_test.go b/internal/service/chime/voice_connector_logging_test.go index 0584dafd2ea..a52fb7aa13b 100644 --- a/internal/service/chime/voice_connector_logging_test.go +++ b/internal/service/chime/voice_connector_logging_test.go @@ -158,10 +158,6 @@ func testAccCheckVoiceConnectorLoggingExists(ctx context.Context, name string) r return tfchime.FindVoiceConnectorLoggingByID(ctx, conn, rs.Primary.ID) }) - if err != nil { - return err - } - - return nil + return err } } diff --git a/internal/service/chime/voice_connector_origination.go b/internal/service/chime/voice_connector_origination.go index 01cb78dbccf..501d5e457ba 100644 --- a/internal/service/chime/voice_connector_origination.go +++ b/internal/service/chime/voice_connector_origination.go @@ -11,9 +11,11 @@ import ( "github.com/aws/aws-sdk-go/service/chimesdkvoice" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) // @SDKResource("aws_chime_voice_connector_origination") @@ -106,13 +108,15 @@ func resourceVoiceConnectorOriginationCreate(ctx context.Context, d *schema.Reso func resourceVoiceConnectorOriginationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorOriginationInput{ - VoiceConnectorId: aws.String(d.Id()), - } + resp, err := FindVoiceConnectorResourceWithRetry(ctx, d.IsNewResource(), func() (*chimesdkvoice.Origination, error) { + return findVoiceConnectorOriginationByID(ctx, conn, d.Id()) + }) - resp, err := conn.GetVoiceConnectorOriginationWithContext(ctx, input) + if tfresource.TimedOut(err) { + resp, err = findVoiceConnectorOriginationByID(ctx, conn, d.Id()) + } - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Chime Voice Connector (%s) origination not found, removing from state", d.Id()) d.SetId("") return nil @@ -122,14 +126,10 @@ func resourceVoiceConnectorOriginationRead(ctx context.Context, d *schema.Resour return diag.Errorf("getting Chime Voice Connector (%s) origination: %s", d.Id(), err) } - if resp == nil || resp.Origination == nil { - return diag.Errorf("getting Chime Voice Connector (%s) origination: empty response", d.Id()) - } - - d.Set("disabled", resp.Origination.Disabled) + d.Set("disabled", resp.Disabled) d.Set("voice_connector_id", d.Id()) - if err := d.Set("route", flattenOriginationRoutes(resp.Origination.Routes)); err != nil { + if err := d.Set("route", flattenOriginationRoutes(resp.Routes)); err != nil { return diag.Errorf("setting Chime Voice Connector (%s) origination routes: %s", d.Id(), err) } @@ -215,3 +215,28 @@ func flattenOriginationRoutes(routes []*chimesdkvoice.OriginationRoute) []interf return rawRoutes } + +func findVoiceConnectorOriginationByID(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoice, id string) (*chimesdkvoice.Origination, error) { + in := &chimesdkvoice.GetVoiceConnectorOriginationInput{ + VoiceConnectorId: aws.String(id), + } + + resp, err := conn.GetVoiceConnectorOriginationWithContext(ctx, in) + + if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + if resp == nil || resp.Origination == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + if err != nil { + return nil, err + } + + return resp.Origination, nil +} diff --git a/internal/service/chime/voice_connector_origination_test.go b/internal/service/chime/voice_connector_origination_test.go index b908debd255..60334b5421e 100644 --- a/internal/service/chime/voice_connector_origination_test.go +++ b/internal/service/chime/voice_connector_origination_test.go @@ -8,16 +8,14 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/chimesdkvoice" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" 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" tfchime "github.com/hashicorp/terraform-provider-aws/internal/service/chime" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func testAccVoiceConnectorOrigination_basic(t *testing.T) { @@ -28,7 +26,6 @@ func testAccVoiceConnectorOrigination_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -63,7 +60,6 @@ func testAccVoiceConnectorOrigination_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -90,7 +86,6 @@ func testAccVoiceConnectorOrigination_update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -141,20 +136,12 @@ func testAccCheckVoiceConnectorOriginationExists(ctx context.Context, name strin } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorOriginationInput{ - VoiceConnectorId: aws.String(rs.Primary.ID), - } - - resp, err := conn.GetVoiceConnectorOriginationWithContext(ctx, input) - if err != nil { - return err - } - if resp == nil || resp.Origination == nil { - return fmt.Errorf("Chime Voice Connector Origination (%s) not found", rs.Primary.ID) - } + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.Origination, error) { + return tfchime.FindVoiceConnectorOriginationByID(ctx, conn, rs.Primary.ID) + }) - return nil + return err } } @@ -165,13 +152,12 @@ func testAccCheckVoiceConnectorOriginationDestroy(ctx context.Context) resource. continue } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetVoiceConnectorOriginationInput{ - VoiceConnectorId: aws.String(rs.Primary.ID), - } - resp, err := conn.GetVoiceConnectorOriginationWithContext(ctx, input) + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.Origination, error) { + return tfchime.FindVoiceConnectorOriginationByID(ctx, conn, rs.Primary.ID) + }) - if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + if tfresource.NotFound(err) { continue } @@ -179,9 +165,7 @@ func testAccCheckVoiceConnectorOriginationDestroy(ctx context.Context) resource. return err } - if resp != nil && resp.Origination != nil { - return fmt.Errorf("error Chime Voice Connector Origination (%s) still exists", rs.Primary.ID) - } + return fmt.Errorf("voice connector origination still exists: (%s)", rs.Primary.ID) } return nil From 7ffe28e54d1dee43138703f87f9ef84efce2677c Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 13:33:14 -0600 Subject: [PATCH 15/22] CHANGELOG --- .changelog/34334.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changelog/34334.txt b/.changelog/34334.txt index 20f0c105fa0..7a2355e2653 100644 --- a/.changelog/34334.txt +++ b/.changelog/34334.txt @@ -12,4 +12,8 @@ resource/aws_chime_voice_connector_group: Fix `read` error when resource is not ```release-note:bug resource/aws_chime_voice_connector_logging: Fix `read` error when resource is not created in `us-east-1` +``` + +```release-note:bug +resource/aws_chime_voice_connector_origination: Fix `read` error when resource is not created in `us-east-1` ``` \ No newline at end of file From 1afaec79932df5314cbbb1c1479165c5a8f846af Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 15:17:48 -0600 Subject: [PATCH 16/22] aws_chimesdkmediapipelines_media_insights_pipeline_configuration: fix eventual consistency on delete --- .../media_insights_pipeline_configuration.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/service/chimesdkmediapipelines/media_insights_pipeline_configuration.go b/internal/service/chimesdkmediapipelines/media_insights_pipeline_configuration.go index 9a4680c06e8..90c1923baed 100644 --- a/internal/service/chimesdkmediapipelines/media_insights_pipeline_configuration.go +++ b/internal/service/chimesdkmediapipelines/media_insights_pipeline_configuration.go @@ -601,9 +601,12 @@ func resourceMediaInsightsPipelineConfigurationDelete(ctx context.Context, d *sc log.Printf("[INFO] Deleting ChimeSDKMediaPipelines MediaInsightsPipelineConfiguration %s", d.Id()) - _, err := conn.DeleteMediaInsightsPipelineConfigurationWithContext(ctx, &chimesdkmediapipelines.DeleteMediaInsightsPipelineConfigurationInput{ - Identifier: aws.String(d.Id()), - }) + // eventual consistency may cause an initial failure + _, err := tfresource.RetryWhenAWSErrMessageContains(ctx, 15*time.Second, func() (interface{}, error) { + return conn.DeleteMediaInsightsPipelineConfigurationWithContext(ctx, &chimesdkmediapipelines.DeleteMediaInsightsPipelineConfigurationInput{ + Identifier: aws.String(d.Id()), + }) + }, chimesdkmediapipelines.ErrCodeConflictException, "Cannot delete a Media Insights Pipeline Configuration while it is in use by 1 or more Voice Connectors") if tfawserr.ErrCodeEquals(err, chimesdkmediapipelines.ErrCodeNotFoundException) { return nil From 8d949bf91079faeebb732c6a157fe200796aaa3a Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 15:22:37 -0600 Subject: [PATCH 17/22] CHANGELOG --- .changelog/34334.txt | 4 ++++ internal/service/chime/chime_test.go | 5 +++++ .../service/chime/voice_connector_streaming_test.go | 12 ++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.changelog/34334.txt b/.changelog/34334.txt index 7a2355e2653..5805fb11ca6 100644 --- a/.changelog/34334.txt +++ b/.changelog/34334.txt @@ -16,4 +16,8 @@ resource/aws_chime_voice_connector_logging: Fix `read` error when resource is no ```release-note:bug resource/aws_chime_voice_connector_origination: Fix `read` error when resource is not created in `us-east-1` +``` + +```release-note:bug +resource/aws_chimesdkmediapipelines_media_insights_pipeline_configuration: Fix eventual consistency error when resource is not created in `us-east-1` ``` \ No newline at end of file diff --git a/internal/service/chime/chime_test.go b/internal/service/chime/chime_test.go index 8d762e6d7ae..c9b48421ae1 100644 --- a/internal/service/chime/chime_test.go +++ b/internal/service/chime/chime_test.go @@ -34,6 +34,11 @@ func TestAccChime_serial(t *testing.T) { "disappears": testAccVoiceConnectorOrigination_disappears, "update": testAccVoiceConnectorOrigination_update, }, + "VoiceConnectorStreaming": { + "basic": testAccVoiceConnectorStreaming_basic, + "disappears": testAccVoiceConnectorStreaming_disappears, + "update": TestAccVoiceConnectorStreaming_update, + }, "VoiceConnectorTermination": { "basic": testAccVoiceConnectorTermination_basic, "disappears": testAccVoiceConnectorTermination_disappears, diff --git a/internal/service/chime/voice_connector_streaming_test.go b/internal/service/chime/voice_connector_streaming_test.go index 4c08316ada3..b31efc4f687 100644 --- a/internal/service/chime/voice_connector_streaming_test.go +++ b/internal/service/chime/voice_connector_streaming_test.go @@ -21,12 +21,12 @@ import ( tfchime "github.com/hashicorp/terraform-provider-aws/internal/service/chime" ) -func TestAccChimeVoiceConnectorStreaming_basic(t *testing.T) { +func testAccVoiceConnectorStreaming_basic(t *testing.T) { ctx := acctest.Context(t) name := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_chime_voice_connector_streaming.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) @@ -53,12 +53,12 @@ func TestAccChimeVoiceConnectorStreaming_basic(t *testing.T) { }) } -func TestAccChimeVoiceConnectorStreaming_disappears(t *testing.T) { +func testAccVoiceConnectorStreaming_disappears(t *testing.T) { ctx := acctest.Context(t) name := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_chime_voice_connector_streaming.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) @@ -79,12 +79,12 @@ func TestAccChimeVoiceConnectorStreaming_disappears(t *testing.T) { }) } -func TestAccChimeVoiceConnectorStreaming_update(t *testing.T) { +func TestAccVoiceConnectorStreaming_update(t *testing.T) { ctx := acctest.Context(t) name := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_chime_voice_connector_streaming.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) From 5025e0034fbb6343799d3c25c4f845d85bd4ab97 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 15:25:05 -0600 Subject: [PATCH 18/22] linter --- internal/service/chime/chime_test.go | 2 +- internal/service/chime/voice_connector_streaming_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/chime/chime_test.go b/internal/service/chime/chime_test.go index c9b48421ae1..5e6006300c4 100644 --- a/internal/service/chime/chime_test.go +++ b/internal/service/chime/chime_test.go @@ -37,7 +37,7 @@ func TestAccChime_serial(t *testing.T) { "VoiceConnectorStreaming": { "basic": testAccVoiceConnectorStreaming_basic, "disappears": testAccVoiceConnectorStreaming_disappears, - "update": TestAccVoiceConnectorStreaming_update, + "update": testAccVoiceConnectorStreaming_update, }, "VoiceConnectorTermination": { "basic": testAccVoiceConnectorTermination_basic, diff --git a/internal/service/chime/voice_connector_streaming_test.go b/internal/service/chime/voice_connector_streaming_test.go index b31efc4f687..538fb071318 100644 --- a/internal/service/chime/voice_connector_streaming_test.go +++ b/internal/service/chime/voice_connector_streaming_test.go @@ -79,7 +79,7 @@ func testAccVoiceConnectorStreaming_disappears(t *testing.T) { }) } -func TestAccVoiceConnectorStreaming_update(t *testing.T) { +func testAccVoiceConnectorStreaming_update(t *testing.T) { ctx := acctest.Context(t) name := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_chime_voice_connector_streaming.test" From b8bfcdbfa1406d13148829f48c85625ba11bfa3b Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 15:46:56 -0600 Subject: [PATCH 19/22] aws_chime_voice_connector_termination_credentials: add retry --- internal/service/chime/exports_test.go | 11 +++--- ...voice_connector_termination_credentials.go | 38 +++++++++++++++++-- ..._connector_termination_credentials_test.go | 33 ++++++---------- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/internal/service/chime/exports_test.go b/internal/service/chime/exports_test.go index 18687cd7aa3..edede89641d 100644 --- a/internal/service/chime/exports_test.go +++ b/internal/service/chime/exports_test.go @@ -5,9 +5,10 @@ package chime // Exports for use in tests only. var ( - FindVoiceConnectorByID = findVoiceConnectorByID - FindVoiceConnectorGroupByID = findVoiceConnectorGroupByID - FindVoiceConnectorLoggingByID = findVoiceConnectorLoggingByID - FindVoiceConnectorOriginationByID = findVoiceConnectorOriginationByID - FindVoiceConnectorTerminationByID = findVoiceConnectorTerminationByID + FindVoiceConnectorByID = findVoiceConnectorByID + FindVoiceConnectorGroupByID = findVoiceConnectorGroupByID + FindVoiceConnectorLoggingByID = findVoiceConnectorLoggingByID + FindVoiceConnectorOriginationByID = findVoiceConnectorOriginationByID + FindVoiceConnectorTerminationByID = findVoiceConnectorTerminationByID + FindVoiceConnectorTerminationCredentialsByID = findVoiceConnectorTerminationCredentialsByID ) diff --git a/internal/service/chime/voice_connector_termination_credentials.go b/internal/service/chime/voice_connector_termination_credentials.go index 81b98786ddc..5f350247fdf 100644 --- a/internal/service/chime/voice_connector_termination_credentials.go +++ b/internal/service/chime/voice_connector_termination_credentials.go @@ -11,9 +11,11 @@ import ( "github.com/aws/aws-sdk-go/service/chimesdkvoice" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) // @SDKResource("aws_chime_voice_connector_termination_credentials") @@ -81,12 +83,15 @@ func resourceVoiceConnectorTerminationCredentialsCreate(ctx context.Context, d * func resourceVoiceConnectorTerminationCredentialsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.ListVoiceConnectorTerminationCredentialsInput{ - VoiceConnectorId: aws.String(d.Id()), + _, err := FindVoiceConnectorResourceWithRetry(ctx, d.IsNewResource(), func() (*chimesdkvoice.ListVoiceConnectorTerminationCredentialsOutput, error) { + return findVoiceConnectorTerminationCredentialsByID(ctx, conn, d.Id()) + }) + + if tfresource.TimedOut(err) { + _, err = findVoiceConnectorTerminationCredentialsByID(ctx, conn, d.Id()) } - _, err := conn.ListVoiceConnectorTerminationCredentialsWithContext(ctx, input) - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Chime Voice Connector (%s) termination credentials not found, removing from state", d.Id()) d.SetId("") return nil @@ -165,3 +170,28 @@ func expandCredentials(data []interface{}) []*chimesdkvoice.Credential { return credentials } + +func findVoiceConnectorTerminationCredentialsByID(ctx context.Context, conn *chimesdkvoice.ChimeSDKVoice, id string) (*chimesdkvoice.ListVoiceConnectorTerminationCredentialsOutput, error) { + in := &chimesdkvoice.ListVoiceConnectorTerminationCredentialsInput{ + VoiceConnectorId: aws.String(id), + } + + resp, err := conn.ListVoiceConnectorTerminationCredentialsWithContext(ctx, in) + + if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + if resp == nil || resp.Usernames == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + if err != nil { + return nil, err + } + + return resp, nil +} diff --git a/internal/service/chime/voice_connector_termination_credentials_test.go b/internal/service/chime/voice_connector_termination_credentials_test.go index db12d4895c8..4156a575f56 100644 --- a/internal/service/chime/voice_connector_termination_credentials_test.go +++ b/internal/service/chime/voice_connector_termination_credentials_test.go @@ -8,16 +8,14 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/chimesdkvoice" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" 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" tfchime "github.com/hashicorp/terraform-provider-aws/internal/service/chime" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func testAccVoiceConnectorTerminationCredentials_basic(t *testing.T) { @@ -28,7 +26,6 @@ func testAccVoiceConnectorTerminationCredentials_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -60,7 +57,6 @@ func testAccVoiceConnectorTerminationCredentials_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -87,7 +83,6 @@ func testAccVoiceConnectorTerminationCredentials_update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), @@ -124,19 +119,15 @@ func testAccCheckVoiceConnectorTerminationCredentialsExists(ctx context.Context, } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.ListVoiceConnectorTerminationCredentialsInput{ - VoiceConnectorId: aws.String(rs.Primary.ID), - } - resp, err := conn.ListVoiceConnectorTerminationCredentialsWithContext(ctx, input) + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.ListVoiceConnectorTerminationCredentialsOutput, error) { + return tfchime.FindVoiceConnectorTerminationCredentialsByID(ctx, conn, rs.Primary.ID) + }) + if err != nil { return err } - if resp == nil || resp.Usernames == nil { - return fmt.Errorf("no Chime Voice Connector Termintation credentials (%s) found", rs.Primary.ID) - } - return nil } } @@ -148,12 +139,12 @@ func testAccCheckVoiceConnectorTerminationCredentialsDestroy(ctx context.Context continue } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.ListVoiceConnectorTerminationCredentialsInput{ - VoiceConnectorId: aws.String(rs.Primary.ID), - } - resp, err := conn.ListVoiceConnectorTerminationCredentialsWithContext(ctx, input) - if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.ListVoiceConnectorTerminationCredentialsOutput, error) { + return tfchime.FindVoiceConnectorTerminationCredentialsByID(ctx, conn, rs.Primary.ID) + }) + + if tfresource.NotFound(err) { continue } @@ -161,9 +152,7 @@ func testAccCheckVoiceConnectorTerminationCredentialsDestroy(ctx context.Context return err } - if resp != nil && resp.Usernames != nil { - return fmt.Errorf("error Chime Voice Connector Termination credentials still exists") - } + return fmt.Errorf("voice connector terimination credentials still exists: (%s)", rs.Primary.ID) } return nil From 55e1076b2b5e026fb396906ef2738499eacf3eb4 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 15:47:44 -0600 Subject: [PATCH 20/22] CHANGELOG --- .changelog/34334.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changelog/34334.txt b/.changelog/34334.txt index 5805fb11ca6..d296bdc3e22 100644 --- a/.changelog/34334.txt +++ b/.changelog/34334.txt @@ -18,6 +18,10 @@ resource/aws_chime_voice_connector_logging: Fix `read` error when resource is no resource/aws_chime_voice_connector_origination: Fix `read` error when resource is not created in `us-east-1` ``` +```release-note:bug +resource/aws_chime_voice_connector_termination_credentials: Fix `read` error when resource is not created in `us-east-1` +``` + ```release-note:bug resource/aws_chimesdkmediapipelines_media_insights_pipeline_configuration: Fix eventual consistency error when resource is not created in `us-east-1` ``` \ No newline at end of file From dbb56089519f177243fcacd19f424ea9c7b51400 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 10 Nov 2023 16:30:38 -0600 Subject: [PATCH 21/22] linter --- .../chime/voice_connector_termination_credentials_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/service/chime/voice_connector_termination_credentials_test.go b/internal/service/chime/voice_connector_termination_credentials_test.go index 4156a575f56..174be7c5498 100644 --- a/internal/service/chime/voice_connector_termination_credentials_test.go +++ b/internal/service/chime/voice_connector_termination_credentials_test.go @@ -124,11 +124,7 @@ func testAccCheckVoiceConnectorTerminationCredentialsExists(ctx context.Context, return tfchime.FindVoiceConnectorTerminationCredentialsByID(ctx, conn, rs.Primary.ID) }) - if err != nil { - return err - } - - return nil + return err } } From 84cc96602224b7aeeab624080798b5f0bed37a9f Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Mon, 13 Nov 2023 11:15:17 -0600 Subject: [PATCH 22/22] incorporate PR feedback --- internal/service/chime/find.go | 6 +++++- internal/service/chime/voice_connector_test.go | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/service/chime/find.go b/internal/service/chime/find.go index bfa6299e21b..2f393582460 100644 --- a/internal/service/chime/find.go +++ b/internal/service/chime/find.go @@ -11,9 +11,13 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) +const ( + voiceConnectorResourcePropagationTimeout = 1 * time.Minute +) + func FindVoiceConnectorResourceWithRetry[T any](ctx context.Context, isNewResource bool, f func() (T, error)) (T, error) { var resp T - err := tfresource.Retry(ctx, 1*time.Minute, func() *retry.RetryError { + err := tfresource.Retry(ctx, voiceConnectorResourcePropagationTimeout, func() *retry.RetryError { var err error resp, err = f() if isNewResource && tfresource.NotFound(err) { diff --git a/internal/service/chime/voice_connector_test.go b/internal/service/chime/voice_connector_test.go index b70753d8588..afb440a3b7a 100644 --- a/internal/service/chime/voice_connector_test.go +++ b/internal/service/chime/voice_connector_test.go @@ -130,9 +130,6 @@ func testAccVoiceConnector_tags(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - // Legacy chime resources are always created in us-east-1, and the ListTags operation - // can behave unexpectedly when configured with a different region. - // acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID),