diff --git a/.changelog/34334.txt b/.changelog/34334.txt new file mode 100644 index 00000000000..d296bdc3e22 --- /dev/null +++ b/.changelog/34334.txt @@ -0,0 +1,27 @@ +```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` +``` + +```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` +``` + +```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_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 diff --git a/internal/service/chime/chime_test.go b/internal/service/chime/chime_test.go index 8d762e6d7ae..5e6006300c4 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/exports_test.go b/internal/service/chime/exports_test.go new file mode 100644 index 00000000000..edede89641d --- /dev/null +++ b/internal/service/chime/exports_test.go @@ -0,0 +1,14 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package chime + +// Exports for use in tests only. +var ( + FindVoiceConnectorByID = findVoiceConnectorByID + FindVoiceConnectorGroupByID = findVoiceConnectorGroupByID + FindVoiceConnectorLoggingByID = findVoiceConnectorLoggingByID + FindVoiceConnectorOriginationByID = findVoiceConnectorOriginationByID + FindVoiceConnectorTerminationByID = findVoiceConnectorTerminationByID + FindVoiceConnectorTerminationCredentialsByID = findVoiceConnectorTerminationCredentialsByID +) diff --git a/internal/service/chime/find.go b/internal/service/chime/find.go new file mode 100644 index 00000000000..2f393582460 --- /dev/null +++ b/internal/service/chime/find.go @@ -0,0 +1,35 @@ +// 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" +) + +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, voiceConnectorResourcePropagationTimeout, 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/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. diff --git a/internal/service/chime/voice_connector.go b/internal/service/chime/voice_connector.go index c70245eeeb1..2a64e145cc5 100644 --- a/internal/service/chime/voice_connector.go +++ b/internal/service/chime/voice_connector.go @@ -11,11 +11,14 @@ 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" "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" ) @@ -42,8 +45,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, @@ -62,10 +65,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) @@ -73,6 +89,7 @@ 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 { @@ -86,11 +103,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)...) } @@ -98,26 +110,29 @@ 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()), + 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()) } - 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) + 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 +174,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 +} 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_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..a52fb7aa13b 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,11 @@ 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) - 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) - } + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.LoggingConfiguration, error) { + return tfchime.FindVoiceConnectorLoggingByID(ctx, conn, rs.Primary.ID) + }) - 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 diff --git a/internal/service/chime/voice_connector_streaming_test.go b/internal/service/chime/voice_connector_streaming_test.go index 4c08316ada3..538fb071318 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) 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_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..174be7c5498 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,20 +119,12 @@ 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) - 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) - } + _, err := tfchime.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.ListVoiceConnectorTerminationCredentialsOutput, error) { + return tfchime.FindVoiceConnectorTerminationCredentialsByID(ctx, conn, rs.Primary.ID) + }) - return nil + return err } } @@ -148,12 +135,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 +148,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 diff --git a/internal/service/chime/voice_connector_termination_test.go b/internal/service/chime/voice_connector_termination_test.go index e9c9c333fe4..5d8c7a3d87f 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,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), @@ -62,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), @@ -89,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), @@ -190,12 +186,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 +199,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 15aa116a003..afb440a3b7a 100644 --- a/internal/service/chime/voice_connector_test.go +++ b/internal/service/chime/voice_connector_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 testAccVoiceConnector_basic(t *testing.T) { @@ -29,7 +28,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), @@ -41,7 +39,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 +62,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 +90,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), @@ -105,7 +101,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"), ), }, @@ -134,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), @@ -237,15 +230,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 } @@ -258,17 +252,22 @@ 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.FindVoiceConnectorResourceWithRetry(ctx, false, func() (*chimesdkvoice.VoiceConnector, error) { + return tfchime.FindVoiceConnectorByID(ctx, conn, 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 + + return fmt.Errorf("voice connector still exists: (%s)", rs.Primary.ID) } + return nil } } 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