From 8360130353768e95ee31607ebf3b24425d276bc9 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:21:58 +0100 Subject: [PATCH 1/7] ivs: Migrate to AWS SDK v2 --- go.mod | 1 + go.sum | 2 ++ internal/conns/awsclient_gen.go | 6 +++--- names/data/names_data.hcl | 2 +- names/names.go | 1 + 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index a06ee9a2225..2a2d1ff937a 100644 --- a/go.mod +++ b/go.mod @@ -123,6 +123,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/iot v1.55.3 github.com/aws/aws-sdk-go-v2/service/iotanalytics v1.24.3 github.com/aws/aws-sdk-go-v2/service/iotevents v1.25.3 + github.com/aws/aws-sdk-go-v2/service/ivs v1.37.3 github.com/aws/aws-sdk-go-v2/service/ivschat v1.14.3 github.com/aws/aws-sdk-go-v2/service/kafka v1.35.3 github.com/aws/aws-sdk-go-v2/service/kafkaconnect v1.19.3 diff --git a/go.sum b/go.sum index 6b34fe84473..28b577daf4a 100644 --- a/go.sum +++ b/go.sum @@ -276,6 +276,8 @@ github.com/aws/aws-sdk-go-v2/service/iotanalytics v1.24.3 h1:SEt8SRvlGvnOkqDV5PJ github.com/aws/aws-sdk-go-v2/service/iotanalytics v1.24.3/go.mod h1:XDi19IK0UluaSVnm1mu2AakZKHtWjg6gksitvH7+LQw= github.com/aws/aws-sdk-go-v2/service/iotevents v1.25.3 h1:9Lao6kmD9P+yywuIn9I8hrraJ2jHIztU/GJspIxn6lA= github.com/aws/aws-sdk-go-v2/service/iotevents v1.25.3/go.mod h1:V2BDVrnP+Tn+MM1xxFI7Qcb+YPhiGgY5PUoKzrKHaCQ= +github.com/aws/aws-sdk-go-v2/service/ivs v1.37.3 h1:gBK4NPueWRWK/zma5K3Hc3/hZhoYuKw00Ed2GzOVhg8= +github.com/aws/aws-sdk-go-v2/service/ivs v1.37.3/go.mod h1:gDKrqL8b+YVQ7C/Y152MZ0AxXP6FaksuQ3dbzGCpD7Y= github.com/aws/aws-sdk-go-v2/service/ivschat v1.14.3 h1:d7y5Gs9BfO+1Jhj8y1/lZhegiJXXy/DlanzwRgYrkXM= github.com/aws/aws-sdk-go-v2/service/ivschat v1.14.3/go.mod h1:rtw6VOH+4X/TWoOKQlOC+oq/WBDJD4BqaPi930II6Mk= github.com/aws/aws-sdk-go-v2/service/kafka v1.35.3 h1:MUx27PrqicGxgsiDWo7xv/Zsl4b0X8kHCRvMpX7XrQs= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 803afa93c39..470ef94b8e3 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -115,6 +115,7 @@ import ( iot_sdkv2 "github.com/aws/aws-sdk-go-v2/service/iot" iotanalytics_sdkv2 "github.com/aws/aws-sdk-go-v2/service/iotanalytics" iotevents_sdkv2 "github.com/aws/aws-sdk-go-v2/service/iotevents" + ivs_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ivs" ivschat_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ivschat" kafka_sdkv2 "github.com/aws/aws-sdk-go-v2/service/kafka" kafkaconnect_sdkv2 "github.com/aws/aws-sdk-go-v2/service/kafkaconnect" @@ -221,7 +222,6 @@ import ( guardduty_sdkv1 "github.com/aws/aws-sdk-go/service/guardduty" imagebuilder_sdkv1 "github.com/aws/aws-sdk-go/service/imagebuilder" inspector_sdkv1 "github.com/aws/aws-sdk-go/service/inspector" - ivs_sdkv1 "github.com/aws/aws-sdk-go/service/ivs" kinesisanalytics_sdkv1 "github.com/aws/aws-sdk-go/service/kinesisanalytics" kinesisanalyticsv2_sdkv1 "github.com/aws/aws-sdk-go/service/kinesisanalyticsv2" kinesisvideo_sdkv1 "github.com/aws/aws-sdk-go/service/kinesisvideo" @@ -726,8 +726,8 @@ func (c *AWSClient) IAMClient(ctx context.Context) *iam_sdkv2.Client { return errs.Must(client[*iam_sdkv2.Client](ctx, c, names.IAM, make(map[string]any))) } -func (c *AWSClient) IVSConn(ctx context.Context) *ivs_sdkv1.IVS { - return errs.Must(conn[*ivs_sdkv1.IVS](ctx, c, names.IVS, make(map[string]any))) +func (c *AWSClient) IVSClient(ctx context.Context) *ivs_sdkv2.Client { + return errs.Must(client[*ivs_sdkv2.Client](ctx, c, names.IVS, make(map[string]any))) } func (c *AWSClient) IVSChatClient(ctx context.Context) *ivschat_sdkv2.Client { diff --git a/names/data/names_data.hcl b/names/data/names_data.hcl index c0a14595d88..9c05cace0dd 100644 --- a/names/data/names_data.hcl +++ b/names/data/names_data.hcl @@ -4950,7 +4950,7 @@ service "ivs" { sdk { id = "ivs" - client_version = [1] + client_version = [2] } names { diff --git a/names/names.go b/names/names.go index e57c7a8c4ee..52513d3d423 100644 --- a/names/names.go +++ b/names/names.go @@ -78,6 +78,7 @@ const ( EvidentlyEndpointID = "evidently" FMSEndpointID = "fms" GrafanaEndpointID = "grafana" + IVSEndpointID = "ivs" IVSChatEndpointID = "ivschat" IdentityStoreEndpointID = "identitystore" Inspector2EndpointID = "inspector2" From e697948e2c8812db64e11f356be0e68fac06c55d Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:23:44 +0100 Subject: [PATCH 2/7] gopatch --- internal/service/ivs/channel.go | 31 ++++++----- internal/service/ivs/channel_test.go | 40 +++++++------- internal/service/ivs/find.go | 38 ++++++------- internal/service/ivs/playback_key_pair.go | 22 ++++---- .../service/ivs/playback_key_pair_test.go | 42 ++++++++------- .../service/ivs/recording_configuration.go | 53 ++++++++++--------- .../ivs/recording_configuration_test.go | 46 ++++++++-------- internal/service/ivs/status.go | 23 ++++---- .../service/ivs/stream_key_data_source.go | 6 +-- internal/service/ivs/wait.go | 37 ++++++------- 10 files changed, 178 insertions(+), 160 deletions(-) diff --git a/internal/service/ivs/channel.go b/internal/service/ivs/channel.go index 55fb8e4eea8..e490079ba86 100644 --- a/internal/service/ivs/channel.go +++ b/internal/service/ivs/channel.go @@ -10,14 +10,17 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ivs" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ivs" + awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" 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" @@ -61,7 +64,7 @@ func ResourceChannel() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - ValidateFunc: validation.StringInSlice(ivs.ChannelLatencyMode_Values(), false), + ValidateFunc: enum.Validate[awstypes.ChannelLatencyMode](), }, names.AttrName: { Type: schema.TypeString, @@ -85,7 +88,7 @@ func ResourceChannel() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - ValidateFunc: validation.StringInSlice(ivs.ChannelType_Values(), false), + ValidateFunc: enum.Validate[awstypes.ChannelType](), }, }, @@ -100,7 +103,7 @@ const ( func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) in := &ivs.CreateChannelInput{ Tags: getTagsIn(ctx), @@ -126,7 +129,7 @@ func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta int in.Type = aws.String(v.(string)) } - out, err := conn.CreateChannelWithContext(ctx, in) + out, err := conn.CreateChannel(ctx, in) if err != nil { return create.AppendDiagError(diags, names.IVS, create.ErrActionCreating, ResNameChannel, d.Get(names.AttrName).(string), err) } @@ -135,7 +138,7 @@ func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta int return create.AppendDiagError(diags, names.IVS, create.ErrActionCreating, ResNameChannel, d.Get(names.AttrName).(string), errors.New("empty output")) } - d.SetId(aws.StringValue(out.Channel.Arn)) + d.SetId(aws.ToString(out.Channel.Arn)) if _, err := waitChannelCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return create.AppendDiagError(diags, names.IVS, create.ErrActionWaitingForCreation, ResNameChannel, d.Id(), err) @@ -147,7 +150,7 @@ func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta int func resourceChannelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) out, err := FindChannelByID(ctx, conn, d.Id()) @@ -176,7 +179,7 @@ func resourceChannelRead(ctx context.Context, d *schema.ResourceData, meta inter func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) update := false @@ -216,7 +219,7 @@ func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta int log.Printf("[DEBUG] Updating IVS Channel (%s): %#v", d.Id(), in) - out, err := conn.UpdateChannelWithContext(ctx, in) + out, err := conn.UpdateChannel(ctx, in) if err != nil { return create.AppendDiagError(diags, names.IVS, create.ErrActionUpdating, ResNameChannel, d.Id(), err) } @@ -231,16 +234,16 @@ func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta int func resourceChannelDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) log.Printf("[INFO] Deleting IVS Channel %s", d.Id()) - _, err := conn.DeleteChannelWithContext(ctx, &ivs.DeleteChannelInput{ + _, err := conn.DeleteChannel(ctx, &ivs.DeleteChannelInput{ Arn: aws.String(d.Id()), }) if err != nil { - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return diags } diff --git a/internal/service/ivs/channel_test.go b/internal/service/ivs/channel_test.go index 6a21746635e..2150e18ab58 100644 --- a/internal/service/ivs/channel_test.go +++ b/internal/service/ivs/channel_test.go @@ -10,22 +10,24 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ivs" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ivs" + awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" + "github.com/hashicorp/aws-sdk-go-base/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" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" tfivs "github.com/hashicorp/terraform-provider-aws/internal/service/ivs" "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccIVSChannel_basic(t *testing.T) { ctx := acctest.Context(t) - var channel ivs.Channel + var channel awstypes.Channel resourceName := "aws_ivs_channel.test" @@ -61,7 +63,7 @@ func TestAccIVSChannel_basic(t *testing.T) { func TestAccIVSChannel_tags(t *testing.T) { ctx := acctest.Context(t) - var channel ivs.Channel + var channel awstypes.Channel resourceName := "aws_ivs_channel.test" @@ -111,7 +113,7 @@ func TestAccIVSChannel_tags(t *testing.T) { func TestAccIVSChannel_update(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 ivs.Channel + var v1, v2 awstypes.Channel resourceName := "aws_ivs_channel.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -156,14 +158,14 @@ func TestAccIVSChannel_update(t *testing.T) { func TestAccIVSChannel_disappears(t *testing.T) { ctx := acctest.Context(t) - var channel ivs.Channel + var channel awstypes.Channel resourceName := "aws_ivs_channel.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccChannelPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -184,7 +186,7 @@ func TestAccIVSChannel_disappears(t *testing.T) { func TestAccIVSChannel_recordingConfiguration(t *testing.T) { ctx := acctest.Context(t) - var channel ivs.Channel + var channel awstypes.Channel bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ivs_channel.test" recordingConfigurationResourceName := "aws_ivs_recording_configuration.test" @@ -192,7 +194,7 @@ func TestAccIVSChannel_recordingConfiguration(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccChannelPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -217,7 +219,7 @@ func TestAccIVSChannel_recordingConfiguration(t *testing.T) { func testAccCheckChannelDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ivs_channel" { @@ -227,9 +229,9 @@ func testAccCheckChannelDestroy(ctx context.Context) resource.TestCheckFunc { input := &ivs.GetChannelInput{ Arn: aws.String(rs.Primary.ID), } - _, err := conn.GetChannelWithContext(ctx, input) + _, err := conn.GetChannel(ctx, input) if err != nil { - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil } @@ -243,7 +245,7 @@ func testAccCheckChannelDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckChannelExists(ctx context.Context, name string, channel *ivs.Channel) resource.TestCheckFunc { +func testAccCheckChannelExists(ctx context.Context, name string, channel *awstypes.Channel) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -255,7 +257,7 @@ func testAccCheckChannelExists(ctx context.Context, name string, channel *ivs.Ch return create.Error(names.IVS, create.ErrActionCheckingExistence, tfivs.ResNameChannel, name, errors.New("not set")) } - conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx) output, err := tfivs.FindChannelByID(ctx, conn, rs.Primary.ID) @@ -270,10 +272,10 @@ func testAccCheckChannelExists(ctx context.Context, name string, channel *ivs.Ch } func testAccChannelPreCheck(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx) input := &ivs.ListChannelsInput{} - _, err := conn.ListChannelsWithContext(ctx, input) + _, err := conn.ListChannels(ctx, input) if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) @@ -284,9 +286,9 @@ func testAccChannelPreCheck(ctx context.Context, t *testing.T) { } } -func testAccCheckChannelNotRecreated(before, after *ivs.Channel) resource.TestCheckFunc { +func testAccCheckChannelNotRecreated(before, after *awstypes.Channel) resource.TestCheckFunc { return func(s *terraform.State) error { - if before, after := aws.StringValue(before.Arn), aws.StringValue(after.Arn); before != after { + if before, after := aws.ToString(before.Arn), aws.ToString(after.Arn); before != after { return create.Error(names.IVS, create.ErrActionCheckingNotRecreated, tfivs.ResNameChannel, before, errors.New("recreated")) } diff --git a/internal/service/ivs/find.go b/internal/service/ivs/find.go index d427a3c4219..561c12fddbf 100644 --- a/internal/service/ivs/find.go +++ b/internal/service/ivs/find.go @@ -6,19 +6,21 @@ package ivs import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ivs" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ivs" + awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) -func FindPlaybackKeyPairByID(ctx context.Context, conn *ivs.IVS, id string) (*ivs.PlaybackKeyPair, error) { +func FindPlaybackKeyPairByID(ctx context.Context, conn *ivs.Client, id string) (*awstypes.PlaybackKeyPair, error) { in := &ivs.GetPlaybackKeyPairInput{ Arn: aws.String(id), } - out, err := conn.GetPlaybackKeyPairWithContext(ctx, in) - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + out, err := conn.GetPlaybackKeyPair(ctx, in) + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: in, @@ -36,12 +38,12 @@ func FindPlaybackKeyPairByID(ctx context.Context, conn *ivs.IVS, id string) (*iv return out.KeyPair, nil } -func FindRecordingConfigurationByID(ctx context.Context, conn *ivs.IVS, id string) (*ivs.RecordingConfiguration, error) { +func FindRecordingConfigurationByID(ctx context.Context, conn *ivs.Client, id string) (*awstypes.RecordingConfiguration, error) { in := &ivs.GetRecordingConfigurationInput{ Arn: aws.String(id), } - out, err := conn.GetRecordingConfigurationWithContext(ctx, in) - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + out, err := conn.GetRecordingConfiguration(ctx, in) + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: in, @@ -59,13 +61,13 @@ func FindRecordingConfigurationByID(ctx context.Context, conn *ivs.IVS, id strin return out.RecordingConfiguration, nil } -func FindChannelByID(ctx context.Context, conn *ivs.IVS, arn string) (*ivs.Channel, error) { +func FindChannelByID(ctx context.Context, conn *ivs.Client, arn string) (*awstypes.Channel, error) { in := &ivs.GetChannelInput{ Arn: aws.String(arn), } - out, err := conn.GetChannelWithContext(ctx, in) + out, err := conn.GetChannel(ctx, in) if err != nil { - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: in, @@ -82,12 +84,12 @@ func FindChannelByID(ctx context.Context, conn *ivs.IVS, arn string) (*ivs.Chann return out.Channel, nil } -func FindStreamKeyByChannelID(ctx context.Context, conn *ivs.IVS, channelArn string) (*ivs.StreamKey, error) { +func FindStreamKeyByChannelID(ctx context.Context, conn *ivs.Client, channelArn string) (*awstypes.StreamKey, error) { in := &ivs.ListStreamKeysInput{ ChannelArn: aws.String(channelArn), } - out, err := conn.ListStreamKeysWithContext(ctx, in) - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + out, err := conn.ListStreamKeys(ctx, in) + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: in, @@ -109,12 +111,12 @@ func FindStreamKeyByChannelID(ctx context.Context, conn *ivs.IVS, channelArn str return findStreamKeyByID(ctx, conn, *streamKeyArn) } -func findStreamKeyByID(ctx context.Context, conn *ivs.IVS, id string) (*ivs.StreamKey, error) { +func findStreamKeyByID(ctx context.Context, conn *ivs.Client, id string) (*awstypes.StreamKey, error) { in := &ivs.GetStreamKeyInput{ Arn: aws.String(id), } - out, err := conn.GetStreamKeyWithContext(ctx, in) - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + out, err := conn.GetStreamKey(ctx, in) + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: in, diff --git a/internal/service/ivs/playback_key_pair.go b/internal/service/ivs/playback_key_pair.go index fb359a6777c..168d6696dc6 100644 --- a/internal/service/ivs/playback_key_pair.go +++ b/internal/service/ivs/playback_key_pair.go @@ -9,13 +9,15 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ivs" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ivs" + awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" 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" @@ -74,7 +76,7 @@ const ( func resourcePlaybackKeyPairCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) in := &ivs.ImportPlaybackKeyPairInput{ PublicKeyMaterial: aws.String(d.Get(names.AttrPublicKey).(string)), @@ -85,7 +87,7 @@ func resourcePlaybackKeyPairCreate(ctx context.Context, d *schema.ResourceData, in.Name = aws.String(v.(string)) } - out, err := conn.ImportPlaybackKeyPairWithContext(ctx, in) + out, err := conn.ImportPlaybackKeyPair(ctx, in) if err != nil { return create.AppendDiagError(diags, names.IVS, create.ErrActionCreating, ResNamePlaybackKeyPair, d.Get(names.AttrName).(string), err) } @@ -94,7 +96,7 @@ func resourcePlaybackKeyPairCreate(ctx context.Context, d *schema.ResourceData, return create.AppendDiagError(diags, names.IVS, create.ErrActionCreating, ResNamePlaybackKeyPair, d.Get(names.AttrName).(string), errors.New("empty output")) } - d.SetId(aws.StringValue(out.KeyPair.Arn)) + d.SetId(aws.ToString(out.KeyPair.Arn)) if _, err := waitPlaybackKeyPairCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return create.AppendDiagError(diags, names.IVS, create.ErrActionWaitingForCreation, ResNamePlaybackKeyPair, d.Id(), err) @@ -106,7 +108,7 @@ func resourcePlaybackKeyPairCreate(ctx context.Context, d *schema.ResourceData, func resourcePlaybackKeyPairRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) out, err := FindPlaybackKeyPairByID(ctx, conn, d.Id()) @@ -130,15 +132,15 @@ func resourcePlaybackKeyPairRead(ctx context.Context, d *schema.ResourceData, me func resourcePlaybackKeyPairDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) log.Printf("[INFO] Deleting IVS PlaybackKeyPair %s", d.Id()) - _, err := conn.DeletePlaybackKeyPairWithContext(ctx, &ivs.DeletePlaybackKeyPairInput{ + _, err := conn.DeletePlaybackKeyPair(ctx, &ivs.DeletePlaybackKeyPairInput{ Arn: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return diags } diff --git a/internal/service/ivs/playback_key_pair_test.go b/internal/service/ivs/playback_key_pair_test.go index ea68a002aa9..7f115ecbc1a 100644 --- a/internal/service/ivs/playback_key_pair_test.go +++ b/internal/service/ivs/playback_key_pair_test.go @@ -10,15 +10,17 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ivs" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ivs" + awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" + "github.com/hashicorp/aws-sdk-go-base/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" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" tfivs "github.com/hashicorp/terraform-provider-aws/internal/service/ivs" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -31,7 +33,7 @@ import ( func testAccPlaybackKeyPair_basic(t *testing.T) { ctx := acctest.Context(t) - var playbackKeyPair ivs.PlaybackKeyPair + var playbackKeyPair awstypes.PlaybackKeyPair resourceName := "aws_ivs_playback_key_pair.test" privateKey := acctest.TLSECDSAPrivateKeyPEM(t, "P-384") publicKeyPEM, fingerprint := acctest.TLSECDSAPublicKeyPEM(t, privateKey) @@ -39,7 +41,7 @@ func testAccPlaybackKeyPair_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccPlaybackKeyPairPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -68,7 +70,7 @@ func testAccPlaybackKeyPair_basic(t *testing.T) { func testAccPlaybackKeyPair_update(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 ivs.PlaybackKeyPair + var v1, v2 awstypes.PlaybackKeyPair rName1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ivs_playback_key_pair.test" @@ -80,7 +82,7 @@ func testAccPlaybackKeyPair_update(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccPlaybackKeyPairPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -110,7 +112,7 @@ func testAccPlaybackKeyPair_update(t *testing.T) { func testAccPlaybackKeyPair_tags(t *testing.T) { ctx := acctest.Context(t) - var v1, v2, v3 ivs.PlaybackKeyPair + var v1, v2, v3 awstypes.PlaybackKeyPair rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ivs_playback_key_pair.test" privateKey := acctest.TLSECDSAPrivateKeyPEM(t, "P-384") @@ -119,7 +121,7 @@ func testAccPlaybackKeyPair_tags(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccPlaybackKeyPairPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -163,7 +165,7 @@ func testAccPlaybackKeyPair_tags(t *testing.T) { func testAccPlaybackKeyPair_disappears(t *testing.T) { ctx := acctest.Context(t) - var playbackkeypair ivs.PlaybackKeyPair + var playbackkeypair awstypes.PlaybackKeyPair resourceName := "aws_ivs_playback_key_pair.test" privateKey := acctest.TLSECDSAPrivateKeyPEM(t, "P-384") publicKey, _ := acctest.TLSECDSAPublicKeyPEM(t, privateKey) @@ -171,7 +173,7 @@ func testAccPlaybackKeyPair_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccPlaybackKeyPairPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -192,7 +194,7 @@ func testAccPlaybackKeyPair_disappears(t *testing.T) { func testAccCheckPlaybackKeyPairDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ivs_playback_key_pair" { @@ -202,9 +204,9 @@ func testAccCheckPlaybackKeyPairDestroy(ctx context.Context) resource.TestCheckF input := &ivs.GetPlaybackKeyPairInput{ Arn: aws.String(rs.Primary.ID), } - _, err := conn.GetPlaybackKeyPairWithContext(ctx, input) + _, err := conn.GetPlaybackKeyPair(ctx, input) if err != nil { - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil } return err @@ -217,7 +219,7 @@ func testAccCheckPlaybackKeyPairDestroy(ctx context.Context) resource.TestCheckF } } -func testAccCheckPlaybackKeyPairExists(ctx context.Context, name string, playbackkeypair *ivs.PlaybackKeyPair) resource.TestCheckFunc { +func testAccCheckPlaybackKeyPairExists(ctx context.Context, name string, playbackkeypair *awstypes.PlaybackKeyPair) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -228,7 +230,7 @@ func testAccCheckPlaybackKeyPairExists(ctx context.Context, name string, playbac return create.Error(names.IVS, create.ErrActionCheckingExistence, tfivs.ResNamePlaybackKeyPair, name, errors.New("not set")) } - conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx) resp, err := tfivs.FindPlaybackKeyPairByID(ctx, conn, rs.Primary.ID) if err != nil { @@ -242,10 +244,10 @@ func testAccCheckPlaybackKeyPairExists(ctx context.Context, name string, playbac } func testAccPlaybackKeyPairPreCheck(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx) input := &ivs.ListPlaybackKeyPairsInput{} - _, err := conn.ListPlaybackKeyPairsWithContext(ctx, input) + _, err := conn.ListPlaybackKeyPairs(ctx, input) if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) @@ -256,9 +258,9 @@ func testAccPlaybackKeyPairPreCheck(ctx context.Context, t *testing.T) { } } -func testAccCheckPlaybackKeyPairRecreated(before, after *ivs.PlaybackKeyPair) resource.TestCheckFunc { +func testAccCheckPlaybackKeyPairRecreated(before, after *awstypes.PlaybackKeyPair) resource.TestCheckFunc { return func(s *terraform.State) error { - if before, after := aws.StringValue(before.Arn), aws.StringValue(after.Arn); before == after { + if before, after := aws.ToString(before.Arn), aws.ToString(after.Arn); before == after { return fmt.Errorf("Expected Playback Key Pair IDs to change, %s", before) } diff --git a/internal/service/ivs/recording_configuration.go b/internal/service/ivs/recording_configuration.go index eecb6b35e3e..cc09d4b2a7f 100644 --- a/internal/service/ivs/recording_configuration.go +++ b/internal/service/ivs/recording_configuration.go @@ -10,14 +10,17 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ivs" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ivs" + awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "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" @@ -103,7 +106,7 @@ func ResourceRecordingConfiguration() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - ValidateFunc: validation.StringInSlice(ivs.RecordingMode_Values(), false), + ValidateFunc: enum.Validate[awstypes.RecordingMode](), }, "target_interval_seconds": { Type: schema.TypeInt, @@ -127,7 +130,7 @@ const ( func resourceRecordingConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) in := &ivs.CreateRecordingConfigurationInput{ DestinationConfiguration: expandDestinationConfiguration(d.Get("destination_configuration").([]interface{})), @@ -145,12 +148,12 @@ func resourceRecordingConfigurationCreate(ctx context.Context, d *schema.Resourc if v, ok := d.GetOk("thumbnail_configuration"); ok { in.ThumbnailConfiguration = expandThumbnailConfiguration(v.([]interface{})) - if aws.StringValue(in.ThumbnailConfiguration.RecordingMode) == ivs.RecordingModeDisabled && in.ThumbnailConfiguration.TargetIntervalSeconds != nil { + if aws.ToString(in.ThumbnailConfiguration.RecordingMode) == awstypes.RecordingModeDisabled && in.ThumbnailConfiguration.TargetIntervalSeconds != nil { return sdkdiag.AppendErrorf(diags, "thumbnail configuration target interval cannot be set if recording_mode is \"DISABLED\"") } } - out, err := conn.CreateRecordingConfigurationWithContext(ctx, in) + out, err := conn.CreateRecordingConfiguration(ctx, in) if err != nil { return create.AppendDiagError(diags, names.IVS, create.ErrActionCreating, ResNameRecordingConfiguration, d.Get(names.AttrName).(string), err) } @@ -159,7 +162,7 @@ func resourceRecordingConfigurationCreate(ctx context.Context, d *schema.Resourc return create.AppendDiagError(diags, names.IVS, create.ErrActionCreating, ResNameRecordingConfiguration, d.Get(names.AttrName).(string), errors.New("empty output")) } - d.SetId(aws.StringValue(out.RecordingConfiguration.Arn)) + d.SetId(aws.ToString(out.RecordingConfiguration.Arn)) if _, err := waitRecordingConfigurationCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return create.AppendDiagError(diags, names.IVS, create.ErrActionWaitingForCreation, ResNameRecordingConfiguration, d.Id(), err) @@ -171,7 +174,7 @@ func resourceRecordingConfigurationCreate(ctx context.Context, d *schema.Resourc func resourceRecordingConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) out, err := FindRecordingConfigurationByID(ctx, conn, d.Id()) @@ -205,15 +208,15 @@ func resourceRecordingConfigurationRead(ctx context.Context, d *schema.ResourceD func resourceRecordingConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) log.Printf("[INFO] Deleting IVS RecordingConfiguration %s", d.Id()) - _, err := conn.DeleteRecordingConfigurationWithContext(ctx, &ivs.DeleteRecordingConfigurationInput{ + _, err := conn.DeleteRecordingConfiguration(ctx, &ivs.DeleteRecordingConfigurationInput{ Arn: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return diags } @@ -228,7 +231,7 @@ func resourceRecordingConfigurationDelete(ctx context.Context, d *schema.Resourc return diags } -func flattenDestinationConfiguration(apiObject *ivs.DestinationConfiguration) []interface{} { +func flattenDestinationConfiguration(apiObject *awstypes.DestinationConfiguration) []interface{} { if apiObject == nil { return []interface{}{} } @@ -242,7 +245,7 @@ func flattenDestinationConfiguration(apiObject *ivs.DestinationConfiguration) [] return []interface{}{m} } -func flattenS3DestinationConfiguration(apiObject *ivs.S3DestinationConfiguration) []interface{} { +func flattenS3DestinationConfiguration(apiObject *awstypes.S3DestinationConfiguration) []interface{} { if apiObject == nil { return []interface{}{} } @@ -250,13 +253,13 @@ func flattenS3DestinationConfiguration(apiObject *ivs.S3DestinationConfiguration m := map[string]interface{}{} if v := apiObject.BucketName; v != nil { - m[names.AttrBucketName] = aws.StringValue(v) + m[names.AttrBucketName] = aws.ToString(v) } return []interface{}{m} } -func flattenThumbnailConfiguration(apiObject *ivs.ThumbnailConfiguration) []interface{} { +func flattenThumbnailConfiguration(apiObject *awstypes.ThumbnailConfiguration) []interface{} { if apiObject == nil { return []interface{}{} } @@ -264,22 +267,22 @@ func flattenThumbnailConfiguration(apiObject *ivs.ThumbnailConfiguration) []inte m := map[string]interface{}{} if v := apiObject.RecordingMode; v != nil { - m["recording_mode"] = aws.StringValue(v) + m["recording_mode"] = aws.ToString(v) } if v := apiObject.TargetIntervalSeconds; v != nil { - m["target_interval_seconds"] = aws.Int64Value(v) + m["target_interval_seconds"] = aws.ToInt64(v) } return []interface{}{m} } -func expandDestinationConfiguration(vSettings []interface{}) *ivs.DestinationConfiguration { +func expandDestinationConfiguration(vSettings []interface{}) *awstypes.DestinationConfiguration { if len(vSettings) == 0 || vSettings[0] == nil { return nil } tfMap := vSettings[0].(map[string]interface{}) - a := &ivs.DestinationConfiguration{} + a := &awstypes.DestinationConfiguration{} if v, ok := tfMap["s3"].([]interface{}); ok && len(v) > 0 { a.S3 = expandS3DestinationConfiguration(v) @@ -288,13 +291,13 @@ func expandDestinationConfiguration(vSettings []interface{}) *ivs.DestinationCon return a } -func expandS3DestinationConfiguration(vSettings []interface{}) *ivs.S3DestinationConfiguration { +func expandS3DestinationConfiguration(vSettings []interface{}) *awstypes.S3DestinationConfiguration { if len(vSettings) == 0 || vSettings[0] == nil { return nil } tfMap := vSettings[0].(map[string]interface{}) - a := &ivs.S3DestinationConfiguration{} + a := &awstypes.S3DestinationConfiguration{} if v, ok := tfMap[names.AttrBucketName].(string); ok && v != "" { a.BucketName = aws.String(v) @@ -303,15 +306,15 @@ func expandS3DestinationConfiguration(vSettings []interface{}) *ivs.S3Destinatio return a } -func expandThumbnailConfiguration(vSettings []interface{}) *ivs.ThumbnailConfiguration { +func expandThumbnailConfiguration(vSettings []interface{}) *awstypes.ThumbnailConfiguration { if len(vSettings) == 0 || vSettings[0] == nil { return nil } - a := &ivs.ThumbnailConfiguration{} + a := &awstypes.ThumbnailConfiguration{} tfMap := vSettings[0].(map[string]interface{}) if v, ok := tfMap["recording_mode"].(string); ok && v != "" { - a.RecordingMode = aws.String(v) + a.RecordingMode = awstypes.RecordingMode(v) } if v, ok := tfMap["target_interval_seconds"].(int); ok { diff --git a/internal/service/ivs/recording_configuration_test.go b/internal/service/ivs/recording_configuration_test.go index c024ae277c6..d383c717dc8 100644 --- a/internal/service/ivs/recording_configuration_test.go +++ b/internal/service/ivs/recording_configuration_test.go @@ -10,15 +10,17 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ivs" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ivs" + awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" + "github.com/hashicorp/aws-sdk-go-base/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" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" tfivs "github.com/hashicorp/terraform-provider-aws/internal/service/ivs" tfs3 "github.com/hashicorp/terraform-provider-aws/internal/service/s3" "github.com/hashicorp/terraform-provider-aws/names" @@ -26,14 +28,14 @@ import ( func TestAccIVSRecordingConfiguration_basic(t *testing.T) { ctx := acctest.Context(t) - var recordingConfiguration ivs.RecordingConfiguration + var recordingConfiguration awstypes.RecordingConfiguration bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ivs_recording_configuration.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccRecordingConfigurationPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -62,7 +64,7 @@ func TestAccIVSRecordingConfiguration_basic(t *testing.T) { func TestAccIVSRecordingConfiguration_update(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 ivs.RecordingConfiguration + var v1, v2 awstypes.RecordingConfiguration rName1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketName1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -75,7 +77,7 @@ func TestAccIVSRecordingConfiguration_update(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccRecordingConfigurationPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -113,14 +115,14 @@ func TestAccIVSRecordingConfiguration_update(t *testing.T) { func TestAccIVSRecordingConfiguration_disappears(t *testing.T) { ctx := acctest.Context(t) - var recordingconfiguration ivs.RecordingConfiguration + var recordingconfiguration awstypes.RecordingConfiguration bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ivs_recording_configuration.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccRecordingConfigurationPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -141,7 +143,7 @@ func TestAccIVSRecordingConfiguration_disappears(t *testing.T) { func TestAccIVSRecordingConfiguration_disappears_S3Bucket(t *testing.T) { ctx := acctest.Context(t) - var recordingconfiguration ivs.RecordingConfiguration + var recordingconfiguration awstypes.RecordingConfiguration bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) parentResourceName := "aws_s3_bucket.test" resourceName := "aws_ivs_recording_configuration.test" @@ -149,7 +151,7 @@ func TestAccIVSRecordingConfiguration_disappears_S3Bucket(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccRecordingConfigurationPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -170,14 +172,14 @@ func TestAccIVSRecordingConfiguration_disappears_S3Bucket(t *testing.T) { func TestAccIVSRecordingConfiguration_tags(t *testing.T) { ctx := acctest.Context(t) - var recordingConfiguration ivs.RecordingConfiguration + var recordingConfiguration awstypes.RecordingConfiguration bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ivs_recording_configuration.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, ivs.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.IVSEndpointID) testAccRecordingConfigurationPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID), @@ -220,7 +222,7 @@ func TestAccIVSRecordingConfiguration_tags(t *testing.T) { func testAccCheckRecordingConfigurationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ivs_recording_configuration" { @@ -230,9 +232,9 @@ func testAccCheckRecordingConfigurationDestroy(ctx context.Context) resource.Tes input := &ivs.GetRecordingConfigurationInput{ Arn: aws.String(rs.Primary.ID), } - _, err := conn.GetRecordingConfigurationWithContext(ctx, input) + _, err := conn.GetRecordingConfiguration(ctx, input) if err != nil { - if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil } return err @@ -245,7 +247,7 @@ func testAccCheckRecordingConfigurationDestroy(ctx context.Context) resource.Tes } } -func testAccCheckRecordingConfigurationExists(ctx context.Context, name string, recordingconfiguration *ivs.RecordingConfiguration) resource.TestCheckFunc { +func testAccCheckRecordingConfigurationExists(ctx context.Context, name string, recordingconfiguration *awstypes.RecordingConfiguration) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -256,7 +258,7 @@ func testAccCheckRecordingConfigurationExists(ctx context.Context, name string, return create.Error(names.IVS, create.ErrActionCheckingExistence, tfivs.ResNameRecordingConfiguration, name, errors.New("not set")) } - conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx) resp, err := tfivs.FindRecordingConfigurationByID(ctx, conn, rs.Primary.ID) @@ -270,9 +272,9 @@ func testAccCheckRecordingConfigurationExists(ctx context.Context, name string, } } -func testAccCheckRecordingConfigurationRecreated(before, after *ivs.RecordingConfiguration) resource.TestCheckFunc { +func testAccCheckRecordingConfigurationRecreated(before, after *awstypes.RecordingConfiguration) resource.TestCheckFunc { return func(s *terraform.State) error { - if before, after := aws.StringValue(before.Arn), aws.StringValue(after.Arn); before == after { + if before, after := aws.ToString(before.Arn), aws.ToString(after.Arn); before == after { return fmt.Errorf("Expected Recording Configuration IDs to change, %s", before) } @@ -281,10 +283,10 @@ func testAccCheckRecordingConfigurationRecreated(before, after *ivs.RecordingCon } func testAccRecordingConfigurationPreCheck(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx) input := &ivs.ListRecordingConfigurationsInput{} - _, err := conn.ListRecordingConfigurationsWithContext(ctx, input) + _, err := conn.ListRecordingConfigurations(ctx, input) if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) diff --git a/internal/service/ivs/status.go b/internal/service/ivs/status.go index 7e3b85b9650..252bb0da895 100644 --- a/internal/service/ivs/status.go +++ b/internal/service/ivs/status.go @@ -6,8 +6,9 @@ package ivs import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ivs" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ivs" + awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) @@ -18,7 +19,7 @@ const ( statusUpdated = "Updated" ) -func statusPlaybackKeyPair(ctx context.Context, conn *ivs.IVS, id string) retry.StateRefreshFunc { +func statusPlaybackKeyPair(ctx context.Context, conn *ivs.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { out, err := FindPlaybackKeyPairByID(ctx, conn, id) if tfresource.NotFound(err) { @@ -33,7 +34,7 @@ func statusPlaybackKeyPair(ctx context.Context, conn *ivs.IVS, id string) retry. } } -func statusRecordingConfiguration(ctx context.Context, conn *ivs.IVS, id string) retry.StateRefreshFunc { +func statusRecordingConfiguration(ctx context.Context, conn *ivs.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { out, err := FindRecordingConfigurationByID(ctx, conn, id) if tfresource.NotFound(err) { @@ -44,11 +45,11 @@ func statusRecordingConfiguration(ctx context.Context, conn *ivs.IVS, id string) return nil, "", err } - return out, aws.StringValue(out.State), nil + return out, aws.ToString(out.State), nil } } -func statusChannel(ctx context.Context, conn *ivs.IVS, arn string, updateDetails *ivs.UpdateChannelInput) retry.StateRefreshFunc { +func statusChannel(ctx context.Context, conn *ivs.Client, arn string, updateDetails *ivs.UpdateChannelInput) retry.StateRefreshFunc { return func() (interface{}, string, error) { out, err := FindChannelByID(ctx, conn, arn) if tfresource.NotFound(err) { @@ -62,11 +63,11 @@ func statusChannel(ctx context.Context, conn *ivs.IVS, arn string, updateDetails if updateDetails == nil { return out, statusNormal, nil } else { - if (updateDetails.Authorized != nil && aws.BoolValue(updateDetails.Authorized) == aws.BoolValue(out.Authorized)) || - (updateDetails.LatencyMode != nil && aws.StringValue(updateDetails.LatencyMode) == aws.StringValue(out.LatencyMode)) || - (updateDetails.Name != nil && aws.StringValue(updateDetails.Name) == aws.StringValue(out.Name)) || - (updateDetails.RecordingConfigurationArn != nil && aws.StringValue(updateDetails.RecordingConfigurationArn) == aws.StringValue(out.RecordingConfigurationArn)) || - (updateDetails.Type != nil && aws.StringValue(updateDetails.Type) == aws.StringValue(out.Type)) { + if (updateDetails.Authorized != nil && aws.ToBool(updateDetails.Authorized) == aws.ToBool(out.Authorized)) || + (updateDetails.LatencyMode != nil && aws.ToString(updateDetails.LatencyMode) == aws.ToString(out.LatencyMode)) || + (updateDetails.Name != nil && aws.ToString(updateDetails.Name) == aws.ToString(out.Name)) || + (updateDetails.RecordingConfigurationArn != nil && aws.ToString(updateDetails.RecordingConfigurationArn) == aws.ToString(out.RecordingConfigurationArn)) || + (updateDetails.Type != nil && aws.ToString(updateDetails.Type) == aws.ToString(out.Type)) { return out, statusUpdated, nil } return out, statusChangePending, nil diff --git a/internal/service/ivs/stream_key_data_source.go b/internal/service/ivs/stream_key_data_source.go index 57e79eb06c1..9728b8b9745 100644 --- a/internal/service/ivs/stream_key_data_source.go +++ b/internal/service/ivs/stream_key_data_source.go @@ -6,7 +6,7 @@ package ivs import ( "context" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -44,7 +44,7 @@ const ( func dataSourceStreamKeyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).IVSConn(ctx) + conn := meta.(*conns.AWSClient).IVSClient(ctx) channelArn := d.Get("channel_arn").(string) @@ -53,7 +53,7 @@ func dataSourceStreamKeyRead(ctx context.Context, d *schema.ResourceData, meta i return create.AppendDiagError(diags, names.IVS, create.ErrActionReading, DSNameStreamKey, channelArn, err) } - d.SetId(aws.StringValue(out.Arn)) + d.SetId(aws.ToString(out.Arn)) d.Set(names.AttrARN, out.Arn) d.Set("channel_arn", out.ChannelArn) diff --git a/internal/service/ivs/wait.go b/internal/service/ivs/wait.go index 4279c735999..92ceede4019 100644 --- a/internal/service/ivs/wait.go +++ b/internal/service/ivs/wait.go @@ -7,11 +7,12 @@ import ( "context" "time" - "github.com/aws/aws-sdk-go/service/ivs" + "github.com/aws/aws-sdk-go-v2/service/ivs" + awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" ) -func waitPlaybackKeyPairCreated(ctx context.Context, conn *ivs.IVS, id string, timeout time.Duration) (*ivs.PlaybackKeyPair, error) { +func waitPlaybackKeyPairCreated(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration) (*awstypes.PlaybackKeyPair, error) { stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{statusNormal}, @@ -22,14 +23,14 @@ func waitPlaybackKeyPairCreated(ctx context.Context, conn *ivs.IVS, id string, t } outputRaw, err := stateConf.WaitForStateContext(ctx) - if out, ok := outputRaw.(*ivs.PlaybackKeyPair); ok { + if out, ok := outputRaw.(*awstypes.PlaybackKeyPair); ok { return out, err } return nil, err } -func waitPlaybackKeyPairDeleted(ctx context.Context, conn *ivs.IVS, id string, timeout time.Duration) (*ivs.PlaybackKeyPair, error) { +func waitPlaybackKeyPairDeleted(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration) (*awstypes.PlaybackKeyPair, error) { stateConf := &retry.StateChangeConf{ Pending: []string{statusNormal}, Target: []string{}, @@ -38,17 +39,17 @@ func waitPlaybackKeyPairDeleted(ctx context.Context, conn *ivs.IVS, id string, t } outputRaw, err := stateConf.WaitForStateContext(ctx) - if out, ok := outputRaw.(*ivs.PlaybackKeyPair); ok { + if out, ok := outputRaw.(*awstypes.PlaybackKeyPair); ok { return out, err } return nil, err } -func waitRecordingConfigurationCreated(ctx context.Context, conn *ivs.IVS, id string, timeout time.Duration) (*ivs.RecordingConfiguration, error) { +func waitRecordingConfigurationCreated(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration) (*awstypes.RecordingConfiguration, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{ivs.RecordingConfigurationStateCreating}, - Target: []string{ivs.RecordingConfigurationStateActive}, + Pending: []string{awstypes.RecordingConfigurationStateCreating}, + Target: []string{awstypes.RecordingConfigurationStateActive}, Refresh: statusRecordingConfiguration(ctx, conn, id), Timeout: timeout, NotFoundChecks: 20, @@ -56,30 +57,30 @@ func waitRecordingConfigurationCreated(ctx context.Context, conn *ivs.IVS, id st } outputRaw, err := stateConf.WaitForStateContext(ctx) - if out, ok := outputRaw.(*ivs.RecordingConfiguration); ok { + if out, ok := outputRaw.(*awstypes.RecordingConfiguration); ok { return out, err } return nil, err } -func waitRecordingConfigurationDeleted(ctx context.Context, conn *ivs.IVS, id string, timeout time.Duration) (*ivs.RecordingConfiguration, error) { +func waitRecordingConfigurationDeleted(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration) (*awstypes.RecordingConfiguration, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{ivs.RecordingConfigurationStateActive}, + Pending: []string{awstypes.RecordingConfigurationStateActive}, Target: []string{}, Refresh: statusRecordingConfiguration(ctx, conn, id), Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if out, ok := outputRaw.(*ivs.RecordingConfiguration); ok { + if out, ok := outputRaw.(*awstypes.RecordingConfiguration); ok { return out, err } return nil, err } -func waitChannelCreated(ctx context.Context, conn *ivs.IVS, id string, timeout time.Duration) (*ivs.Channel, error) { +func waitChannelCreated(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration) (*awstypes.Channel, error) { stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{statusNormal}, @@ -90,14 +91,14 @@ func waitChannelCreated(ctx context.Context, conn *ivs.IVS, id string, timeout t } outputRaw, err := stateConf.WaitForStateContext(ctx) - if out, ok := outputRaw.(*ivs.Channel); ok { + if out, ok := outputRaw.(*awstypes.Channel); ok { return out, err } return nil, err } -func waitChannelUpdated(ctx context.Context, conn *ivs.IVS, id string, timeout time.Duration, updateDetails *ivs.UpdateChannelInput) (*ivs.Channel, error) { +func waitChannelUpdated(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration, updateDetails *ivs.UpdateChannelInput) (*awstypes.Channel, error) { stateConf := &retry.StateChangeConf{ Pending: []string{statusChangePending}, Target: []string{statusUpdated}, @@ -108,14 +109,14 @@ func waitChannelUpdated(ctx context.Context, conn *ivs.IVS, id string, timeout t } outputRaw, err := stateConf.WaitForStateContext(ctx) - if out, ok := outputRaw.(*ivs.Channel); ok { + if out, ok := outputRaw.(*awstypes.Channel); ok { return out, err } return nil, err } -func waitChannelDeleted(ctx context.Context, conn *ivs.IVS, id string, timeout time.Duration) (*ivs.Channel, error) { +func waitChannelDeleted(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration) (*awstypes.Channel, error) { stateConf := &retry.StateChangeConf{ Pending: []string{statusNormal}, Target: []string{}, @@ -124,7 +125,7 @@ func waitChannelDeleted(ctx context.Context, conn *ivs.IVS, id string, timeout t } outputRaw, err := stateConf.WaitForStateContext(ctx) - if out, ok := outputRaw.(*ivs.Channel); ok { + if out, ok := outputRaw.(*awstypes.Channel); ok { return out, err } From 2ed3ec3b60b0672a4596a35adaee1db46d19e921 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:30:48 +0100 Subject: [PATCH 3/7] make gen --- internal/service/ivs/generate.go | 2 +- .../ivs/service_endpoint_resolver_gen.go | 66 ++++---- .../service/ivs/service_endpoints_gen_test.go | 146 +++++++++++++++--- internal/service/ivs/service_package_gen.go | 28 ++-- internal/service/ivs/tags_gen.go | 33 ++-- 5 files changed, 183 insertions(+), 92 deletions(-) diff --git a/internal/service/ivs/generate.go b/internal/service/ivs/generate.go index 5d9cc8ade7f..7807afc79bf 100644 --- a/internal/service/ivs/generate.go +++ b/internal/service/ivs/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 -ServiceTagsMap -UpdateTags +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -KVTValues -ListTags -ServiceTagsMap -SkipTypesImp -UpdateTags //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/ivs/service_endpoint_resolver_gen.go b/internal/service/ivs/service_endpoint_resolver_gen.go index 3c733fde680..58495c307fe 100644 --- a/internal/service/ivs/service_endpoint_resolver_gen.go +++ b/internal/service/ivs/service_endpoint_resolver_gen.go @@ -6,65 +6,63 @@ import ( "context" "fmt" "net" - "net/url" - endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + ivs_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ivs" + smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/errs" ) -var _ endpoints_sdkv1.Resolver = resolverSDKv1{} +var _ ivs_sdkv2.EndpointResolverV2 = resolverSDKv2{} -type resolverSDKv1 struct { - ctx context.Context +type resolverSDKv2 struct { + defaultResolver ivs_sdkv2.EndpointResolverV2 } -func newEndpointResolverSDKv1(ctx context.Context) resolverSDKv1 { - return resolverSDKv1{ - ctx: ctx, +func newEndpointResolverSDKv2() resolverSDKv2 { + return resolverSDKv2{ + defaultResolver: ivs_sdkv2.NewDefaultEndpointResolverV2(), } } -func (r resolverSDKv1) EndpointFor(service, region string, opts ...func(*endpoints_sdkv1.Options)) (endpoint endpoints_sdkv1.ResolvedEndpoint, err error) { - ctx := r.ctx +func (r resolverSDKv2) ResolveEndpoint(ctx context.Context, params ivs_sdkv2.EndpointParameters) (endpoint smithyendpoints.Endpoint, err error) { + params = params.WithDefaults() + useFIPS := aws_sdkv2.ToBool(params.UseFIPS) - var opt endpoints_sdkv1.Options - opt.Set(opts...) - - useFIPS := opt.UseFIPSEndpoint == endpoints_sdkv1.FIPSEndpointStateEnabled + if eps := params.Endpoint; aws_sdkv2.ToString(eps) != "" { + tflog.Debug(ctx, "setting endpoint", map[string]any{ + "tf_aws.endpoint": endpoint, + }) - defaultResolver := endpoints_sdkv1.DefaultResolver() + if useFIPS { + tflog.Debug(ctx, "endpoint set, ignoring UseFIPSEndpoint setting") + params.UseFIPS = aws_sdkv2.Bool(false) + } - if useFIPS { + return r.defaultResolver.ResolveEndpoint(ctx, params) + } else if useFIPS { ctx = tflog.SetField(ctx, "tf_aws.use_fips", useFIPS) - endpoint, err = defaultResolver.EndpointFor(service, region, opts...) + endpoint, err = r.defaultResolver.ResolveEndpoint(ctx, params) if err != nil { return endpoint, err } tflog.Debug(ctx, "endpoint resolved", map[string]any{ - "tf_aws.endpoint": endpoint.URL, + "tf_aws.endpoint": endpoint.URI.String(), }) - var endpointURL *url.URL - endpointURL, err = url.Parse(endpoint.URL) - if err != nil { - return endpoint, err - } - - hostname := endpointURL.Hostname() + hostname := endpoint.URI.Hostname() _, err = net.LookupHost(hostname) if err != nil { if dnsErr, ok := errs.As[*net.DNSError](err); ok && dnsErr.IsNotFound { tflog.Debug(ctx, "default endpoint host not found, disabling FIPS", map[string]any{ "tf_aws.hostname": hostname, }) - opts = append(opts, func(o *endpoints_sdkv1.Options) { - o.UseFIPSEndpoint = endpoints_sdkv1.FIPSEndpointStateDisabled - }) + params.UseFIPS = aws_sdkv2.Bool(false) } else { - err = fmt.Errorf("looking up accessanalyzer endpoint %q: %s", hostname, err) + err = fmt.Errorf("looking up ivs endpoint %q: %s", hostname, err) return } } else { @@ -72,5 +70,13 @@ func (r resolverSDKv1) EndpointFor(service, region string, opts ...func(*endpoin } } - return defaultResolver.EndpointFor(service, region, opts...) + return r.defaultResolver.ResolveEndpoint(ctx, params) +} + +func withBaseEndpoint(endpoint string) func(*ivs_sdkv2.Options) { + return func(o *ivs_sdkv2.Options) { + if endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + } } diff --git a/internal/service/ivs/service_endpoints_gen_test.go b/internal/service/ivs/service_endpoints_gen_test.go index 780ee904757..fb198412585 100644 --- a/internal/service/ivs/service_endpoints_gen_test.go +++ b/internal/service/ivs/service_endpoints_gen_test.go @@ -4,18 +4,22 @@ package ivs_test import ( "context" + "errors" "fmt" "maps" "net" "net/url" "os" "path/filepath" + "reflect" "strings" "testing" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" - ivs_sdkv1 "github.com/aws/aws-sdk-go/service/ivs" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + ivs_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ivs" + "github.com/aws/smithy-go/middleware" + smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" "github.com/hashicorp/aws-sdk-go-base/v2/servicemocks" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -240,54 +244,63 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S } func defaultEndpoint(region string) (url.URL, error) { - r := endpoints.DefaultResolver() + r := ivs_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(ivs_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), ivs_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) if err != nil { return url.URL{}, err } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return *url, nil + return ep.URI, nil } func defaultFIPSEndpoint(region string) (url.URL, error) { - r := endpoints.DefaultResolver() + r := ivs_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(ivs_sdkv1.EndpointsID, region, func(opt *endpoints.Options) { - opt.UseFIPSEndpoint = endpoints.FIPSEndpointStateEnabled + ep, err := r.ResolveEndpoint(context.Background(), ivs_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + UseFIPS: aws_sdkv2.Bool(true), }) if err != nil { return url.URL{}, err } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return *url, nil + return ep.URI, nil } func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) apiCallParams { t.Helper() - client := meta.IVSConn(ctx) + client := meta.IVSClient(ctx) - req, _ := client.ListChannelsRequest(&ivs_sdkv1.ListChannelsInput{}) + var result apiCallParams - req.HTTPRequest.URL.Path = "/" - - return apiCallParams{ - endpoint: req.HTTPRequest.URL.String(), - region: aws_sdkv1.StringValue(client.Config.Region), + _, err := client.ListChannels(ctx, &ivs_sdkv2.ListChannelsInput{}, + func(opts *ivs_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &result.endpoint), + addRetrieveRegionMiddleware(&result.region), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) } + + return result } func withNoConfig(_ *caseSetup) { @@ -466,6 +479,89 @@ func testEndpointCase(t *testing.T, region string, testcase endpointTestCase, ca } } +func addRetrieveEndpointURLMiddleware(t *testing.T, endpoint *string) func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + retrieveEndpointURLMiddleware(t, endpoint), + middleware.After, + ) + } +} + +func retrieveEndpointURLMiddleware(t *testing.T, endpoint *string) middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Retrieve Endpoint", + func(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + t.Helper() + + request, ok := in.Request.(*smithyhttp.Request) + if !ok { + t.Fatalf("Expected *github.com/aws/smithy-go/transport/http.Request, got %s", fullTypeName(in.Request)) + } + + url := request.URL + url.RawQuery = "" + url.Path = "/" + + *endpoint = url.String() + + return next.HandleFinalize(ctx, in) + }) +} + +func addRetrieveRegionMiddleware(region *string) func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Serialize.Add( + retrieveRegionMiddleware(region), + middleware.After, + ) + } +} + +func retrieveRegionMiddleware(region *string) middleware.SerializeMiddleware { + return middleware.SerializeMiddlewareFunc( + "Test: Retrieve Region", + func(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (middleware.SerializeOutput, middleware.Metadata, error) { + *region = awsmiddleware.GetRegion(ctx) + + return next.HandleSerialize(ctx, in) + }, + ) +} + +var errCancelOperation = fmt.Errorf("Test: Canceling request") + +func addCancelRequestMiddleware() func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + cancelRequestMiddleware(), + middleware.After, + ) + } +} + +// cancelRequestMiddleware creates a Smithy middleware that intercepts the request before sending and cancels it +func cancelRequestMiddleware() middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Cancel Requests", + func(_ context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + return middleware.FinalizeOutput{}, middleware.Metadata{}, errCancelOperation + }) +} + +func fullTypeName(i interface{}) string { + return fullValueTypeName(reflect.ValueOf(i)) +} + +func fullValueTypeName(v reflect.Value) string { + if v.Kind() == reflect.Ptr { + return "*" + fullValueTypeName(reflect.Indirect(v)) + } + + requestType := v.Type() + return fmt.Sprintf("%s.%s", requestType.PkgPath(), requestType.Name()) +} + func generateSharedConfigFile(config configFile) string { var buf strings.Builder diff --git a/internal/service/ivs/service_package_gen.go b/internal/service/ivs/service_package_gen.go index 04946040bcd..9af4b3e36fe 100644 --- a/internal/service/ivs/service_package_gen.go +++ b/internal/service/ivs/service_package_gen.go @@ -5,10 +5,8 @@ package ivs import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - ivs_sdkv1 "github.com/aws/aws-sdk-go/service/ivs" - "github.com/hashicorp/terraform-plugin-log/tflog" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + ivs_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ivs" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -66,22 +64,14 @@ func (p *servicePackage) ServicePackageName() string { return names.IVS } -// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*ivs_sdkv1.IVS, error) { - sess := config[names.AttrSession].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*ivs_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - cfg := aws_sdkv1.Config{} - - if endpoint := config[names.AttrEndpoint].(string); endpoint != "" { - tflog.Debug(ctx, "setting endpoint", map[string]any{ - "tf_aws.endpoint": endpoint, - }) - cfg.Endpoint = aws_sdkv1.String(endpoint) - } else { - cfg.EndpointResolver = newEndpointResolverSDKv1(ctx) - } - - return ivs_sdkv1.New(sess.Copy(&cfg)), nil + return ivs_sdkv2.NewFromConfig(cfg, + ivs_sdkv2.WithEndpointResolverV2(newEndpointResolverSDKv2()), + withBaseEndpoint(config[names.AttrEndpoint].(string)), + ), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/ivs/tags_gen.go b/internal/service/ivs/tags_gen.go index 05b645c5056..3facea49fe5 100644 --- a/internal/service/ivs/tags_gen.go +++ b/internal/service/ivs/tags_gen.go @@ -5,9 +5,8 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ivs" - "github.com/aws/aws-sdk-go/service/ivs/ivsiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ivs" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" @@ -19,12 +18,12 @@ import ( // listTags lists ivs service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func listTags(ctx context.Context, conn ivsiface.IVSAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *ivs.Client, identifier string, optFns ...func(*ivs.Options)) (tftags.KeyValueTags, error) { input := &ivs.ListTagsForResourceInput{ ResourceArn: aws.String(identifier), } - output, err := conn.ListTagsForResourceWithContext(ctx, input) + output, err := conn.ListTagsForResource(ctx, input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -36,7 +35,7 @@ func listTags(ctx context.Context, conn ivsiface.IVSAPI, identifier string) (tft // ListTags lists ivs service tags and set them in Context. // It is called from outside this package. func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier string) error { - tags, err := listTags(ctx, meta.(*conns.AWSClient).IVSConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).IVSClient(ctx), identifier) if err != nil { return err @@ -49,21 +48,21 @@ func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier stri return nil } -// map[string]*string handling +// map[string]string handling // Tags returns ivs service tags. -func Tags(tags tftags.KeyValueTags) map[string]*string { - return aws.StringMap(tags.Map()) +func Tags(tags tftags.KeyValueTags) map[string]string { + return tags.Map() } // KeyValueTags creates tftags.KeyValueTags from ivs service tags. -func KeyValueTags(ctx context.Context, tags map[string]*string) tftags.KeyValueTags { +func KeyValueTags(ctx context.Context, tags map[string]string) tftags.KeyValueTags { return tftags.New(ctx, tags) } // getTagsIn returns ivs service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) map[string]*string { +func getTagsIn(ctx context.Context) map[string]string { if inContext, ok := tftags.FromContext(ctx); ok { if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { return tags @@ -74,7 +73,7 @@ func getTagsIn(ctx context.Context) map[string]*string { } // setTagsOut sets ivs service tags in Context. -func setTagsOut(ctx context.Context, tags map[string]*string) { +func setTagsOut(ctx context.Context, tags map[string]string) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } @@ -83,7 +82,7 @@ func setTagsOut(ctx context.Context, tags map[string]*string) { // updateTags updates ivs service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func updateTags(ctx context.Context, conn ivsiface.IVSAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *ivs.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*ivs.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -94,10 +93,10 @@ func updateTags(ctx context.Context, conn ivsiface.IVSAPI, identifier string, ol if len(removedTags) > 0 { input := &ivs.UntagResourceInput{ ResourceArn: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.Keys()), + TagKeys: removedTags.Keys(), } - _, err := conn.UntagResourceWithContext(ctx, input) + _, err := conn.UntagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -112,7 +111,7 @@ func updateTags(ctx context.Context, conn ivsiface.IVSAPI, identifier string, ol Tags: Tags(updatedTags), } - _, err := conn.TagResourceWithContext(ctx, input) + _, err := conn.TagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -125,5 +124,5 @@ func updateTags(ctx context.Context, conn ivsiface.IVSAPI, identifier string, ol // UpdateTags updates ivs service tags. // It is called from outside this package. func (p *servicePackage) UpdateTags(ctx context.Context, meta any, identifier string, oldTags, newTags any) error { - return updateTags(ctx, meta.(*conns.AWSClient).IVSConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).IVSClient(ctx), identifier, oldTags, newTags) } From b0c8e9874323d2a06cb8af17d328d97424107ead Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:41:27 +0100 Subject: [PATCH 4/7] r/ivs_channel: Migrate to AWS SDK v2 --- internal/service/ivs/channel.go | 29 ++++++++++++++-------------- internal/service/ivs/channel_test.go | 1 - 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/internal/service/ivs/channel.go b/internal/service/ivs/channel.go index e490079ba86..4ae38278b67 100644 --- a/internal/service/ivs/channel.go +++ b/internal/service/ivs/channel.go @@ -13,7 +13,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ivs" awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" - "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -61,10 +60,10 @@ func ResourceChannel() *schema.Resource { Computed: true, }, "latency_mode": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: enum.Validate[awstypes.ChannelLatencyMode](), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.ChannelLatencyMode](), }, names.AttrName: { Type: schema.TypeString, @@ -85,10 +84,10 @@ func ResourceChannel() *schema.Resource { names.AttrTags: tftags.TagsSchema(), names.AttrTagsAll: tftags.TagsSchemaComputed(), names.AttrType: { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: enum.Validate[awstypes.ChannelType](), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.ChannelType](), }, }, @@ -110,11 +109,11 @@ func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("authorized"); ok { - in.Authorized = aws.Bool(v.(bool)) + in.Authorized = v.(bool) } if v, ok := d.GetOk("latency_mode"); ok { - in.LatencyMode = aws.String(v.(string)) + in.LatencyMode = awstypes.ChannelLatencyMode(v.(string)) } if v, ok := d.GetOk(names.AttrName); ok { @@ -126,7 +125,7 @@ func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk(names.AttrType); ok { - in.Type = aws.String(v.(string)) + in.Type = awstypes.ChannelType(v.(string)) } out, err := conn.CreateChannel(ctx, in) @@ -189,12 +188,12 @@ func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta int } if d.HasChanges("authorized") { - in.Authorized = aws.Bool(d.Get("authorized").(bool)) + in.Authorized = d.Get("authorized").(bool) update = true } if d.HasChanges("latency_mode") { - in.LatencyMode = aws.String(d.Get("latency_mode").(string)) + in.LatencyMode = awstypes.ChannelLatencyMode(d.Get("latency_mode").(string)) update = true } @@ -209,7 +208,7 @@ func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta int } if d.HasChanges(names.AttrType) { - in.Type = aws.String(d.Get(names.AttrType).(string)) + in.Type = awstypes.ChannelType(d.Get(names.AttrType).(string)) update = true } diff --git a/internal/service/ivs/channel_test.go b/internal/service/ivs/channel_test.go index 2150e18ab58..dc3ca225ff3 100644 --- a/internal/service/ivs/channel_test.go +++ b/internal/service/ivs/channel_test.go @@ -13,7 +13,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ivs" awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" - "github.com/hashicorp/aws-sdk-go-base/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" From 42b648c874701abe7f7f0c12460213f61a598e94 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:42:53 +0100 Subject: [PATCH 5/7] r/ivs_playback_key_pair: Migrate to AWS SDK v2 --- internal/service/ivs/playback_key_pair.go | 1 - internal/service/ivs/playback_key_pair_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/internal/service/ivs/playback_key_pair.go b/internal/service/ivs/playback_key_pair.go index 168d6696dc6..6d3e22b45ea 100644 --- a/internal/service/ivs/playback_key_pair.go +++ b/internal/service/ivs/playback_key_pair.go @@ -12,7 +12,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ivs" awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" - "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" diff --git a/internal/service/ivs/playback_key_pair_test.go b/internal/service/ivs/playback_key_pair_test.go index 7f115ecbc1a..b4f6c31700e 100644 --- a/internal/service/ivs/playback_key_pair_test.go +++ b/internal/service/ivs/playback_key_pair_test.go @@ -13,7 +13,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ivs" awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" - "github.com/hashicorp/aws-sdk-go-base/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" From 9b225e26f401efe6a8bd7150f670e0ea3f0828ea Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:44:25 +0100 Subject: [PATCH 6/7] r/ivs_recording_configuration: Migrate to AWS SDK v2 --- internal/service/ivs/recording_configuration.go | 17 +++++++---------- .../service/ivs/recording_configuration_test.go | 1 - 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/service/ivs/recording_configuration.go b/internal/service/ivs/recording_configuration.go index cc09d4b2a7f..6cb4ec7755b 100644 --- a/internal/service/ivs/recording_configuration.go +++ b/internal/service/ivs/recording_configuration.go @@ -13,7 +13,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ivs" awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" - "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -103,10 +102,10 @@ func ResourceRecordingConfiguration() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "recording_mode": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: enum.Validate[awstypes.RecordingMode](), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.RecordingMode](), }, "target_interval_seconds": { Type: schema.TypeInt, @@ -142,13 +141,13 @@ func resourceRecordingConfigurationCreate(ctx context.Context, d *schema.Resourc } if v, ok := d.GetOk("recording_reconnect_window_seconds"); ok { - in.RecordingReconnectWindowSeconds = aws.Int64(int64(v.(int))) + in.RecordingReconnectWindowSeconds = int32(v.(int)) } if v, ok := d.GetOk("thumbnail_configuration"); ok { in.ThumbnailConfiguration = expandThumbnailConfiguration(v.([]interface{})) - if aws.ToString(in.ThumbnailConfiguration.RecordingMode) == awstypes.RecordingModeDisabled && in.ThumbnailConfiguration.TargetIntervalSeconds != nil { + if in.ThumbnailConfiguration.RecordingMode == awstypes.RecordingModeDisabled && in.ThumbnailConfiguration.TargetIntervalSeconds != nil { return sdkdiag.AppendErrorf(diags, "thumbnail configuration target interval cannot be set if recording_mode is \"DISABLED\"") } } @@ -266,9 +265,7 @@ func flattenThumbnailConfiguration(apiObject *awstypes.ThumbnailConfiguration) [ m := map[string]interface{}{} - if v := apiObject.RecordingMode; v != nil { - m["recording_mode"] = aws.ToString(v) - } + m["recording_mode"] = string(apiObject.RecordingMode) if v := apiObject.TargetIntervalSeconds; v != nil { m["target_interval_seconds"] = aws.ToInt64(v) diff --git a/internal/service/ivs/recording_configuration_test.go b/internal/service/ivs/recording_configuration_test.go index d383c717dc8..d55649af552 100644 --- a/internal/service/ivs/recording_configuration_test.go +++ b/internal/service/ivs/recording_configuration_test.go @@ -13,7 +13,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ivs" awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" - "github.com/hashicorp/aws-sdk-go-base/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" From 91e9e870d55052a6fb4d110279ce3eaeeef19168 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:49:13 +0100 Subject: [PATCH 7/7] ivs: Misc fixes --- internal/service/ivs/find.go | 1 - internal/service/ivs/status.go | 9 ++++----- internal/service/ivs/wait.go | 7 ++++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/service/ivs/find.go b/internal/service/ivs/find.go index 561c12fddbf..c7535fbea96 100644 --- a/internal/service/ivs/find.go +++ b/internal/service/ivs/find.go @@ -9,7 +9,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ivs" awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" - "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" diff --git a/internal/service/ivs/status.go b/internal/service/ivs/status.go index 252bb0da895..5ff9f63a3fc 100644 --- a/internal/service/ivs/status.go +++ b/internal/service/ivs/status.go @@ -8,7 +8,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ivs" - awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) @@ -45,7 +44,7 @@ func statusRecordingConfiguration(ctx context.Context, conn *ivs.Client, id stri return nil, "", err } - return out, aws.ToString(out.State), nil + return out, string(out.State), nil } } @@ -63,11 +62,11 @@ func statusChannel(ctx context.Context, conn *ivs.Client, arn string, updateDeta if updateDetails == nil { return out, statusNormal, nil } else { - if (updateDetails.Authorized != nil && aws.ToBool(updateDetails.Authorized) == aws.ToBool(out.Authorized)) || - (updateDetails.LatencyMode != nil && aws.ToString(updateDetails.LatencyMode) == aws.ToString(out.LatencyMode)) || + if (updateDetails.Authorized == out.Authorized) || + (updateDetails.LatencyMode == out.LatencyMode) || (updateDetails.Name != nil && aws.ToString(updateDetails.Name) == aws.ToString(out.Name)) || (updateDetails.RecordingConfigurationArn != nil && aws.ToString(updateDetails.RecordingConfigurationArn) == aws.ToString(out.RecordingConfigurationArn)) || - (updateDetails.Type != nil && aws.ToString(updateDetails.Type) == aws.ToString(out.Type)) { + (updateDetails.Type == out.Type) { return out, statusUpdated, nil } return out, statusChangePending, nil diff --git a/internal/service/ivs/wait.go b/internal/service/ivs/wait.go index 92ceede4019..a7b2e5a26e0 100644 --- a/internal/service/ivs/wait.go +++ b/internal/service/ivs/wait.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/ivs" awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/enum" ) func waitPlaybackKeyPairCreated(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration) (*awstypes.PlaybackKeyPair, error) { @@ -48,8 +49,8 @@ func waitPlaybackKeyPairDeleted(ctx context.Context, conn *ivs.Client, id string func waitRecordingConfigurationCreated(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration) (*awstypes.RecordingConfiguration, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{awstypes.RecordingConfigurationStateCreating}, - Target: []string{awstypes.RecordingConfigurationStateActive}, + Pending: enum.Slice(awstypes.RecordingConfigurationStateCreating), + Target: enum.Slice(awstypes.RecordingConfigurationStateActive), Refresh: statusRecordingConfiguration(ctx, conn, id), Timeout: timeout, NotFoundChecks: 20, @@ -66,7 +67,7 @@ func waitRecordingConfigurationCreated(ctx context.Context, conn *ivs.Client, id func waitRecordingConfigurationDeleted(ctx context.Context, conn *ivs.Client, id string, timeout time.Duration) (*awstypes.RecordingConfiguration, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{awstypes.RecordingConfigurationStateActive}, + Pending: enum.Slice(awstypes.RecordingConfigurationStateActive), Target: []string{}, Refresh: statusRecordingConfiguration(ctx, conn, id), Timeout: timeout,