From 0bd72b824692d9dfcb84578fcb00315fe21fff07 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 08:24:43 -0500 Subject: [PATCH 01/18] r/aws_media_convert_queue: Use '_Values()' for string enums. --- internal/service/mediaconvert/queue.go | 41 ++++++++++---------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/internal/service/mediaconvert/queue.go b/internal/service/mediaconvert/queue.go index a03a3163695..15ba5ac9584 100644 --- a/internal/service/mediaconvert/queue.go +++ b/internal/service/mediaconvert/queue.go @@ -50,14 +50,11 @@ func ResourceQueue() *schema.Resource { Optional: true, }, "pricing_plan": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: mediaconvert.PricingPlanOnDemand, - ValidateFunc: validation.StringInSlice([]string{ - mediaconvert.PricingPlanOnDemand, - mediaconvert.PricingPlanReserved, - }, false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: mediaconvert.PricingPlanOnDemand, + ValidateFunc: validation.StringInSlice(mediaconvert.PricingPlan_Values(), false), }, "reservation_plan_settings": { Type: schema.TypeList, @@ -67,19 +64,14 @@ func ResourceQueue() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "commitment": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - mediaconvert.CommitmentOneYear, - }, false), + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(mediaconvert.Commitment_Values(), false), }, "renewal_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - mediaconvert.RenewalTypeAutoRenew, - mediaconvert.RenewalTypeExpire, - }, false), + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(mediaconvert.RenewalType_Values(), false), }, "reserved_slots": { Type: schema.TypeInt, @@ -89,13 +81,10 @@ func ResourceQueue() *schema.Resource { }, }, "status": { - Type: schema.TypeString, - Optional: true, - Default: mediaconvert.QueueStatusActive, - ValidateFunc: validation.StringInSlice([]string{ - mediaconvert.QueueStatusActive, - mediaconvert.QueueStatusPaused, - }, false), + Type: schema.TypeString, + Optional: true, + Default: mediaconvert.QueueStatusActive, + ValidateFunc: validation.StringInSlice(mediaconvert.QueueStatus_Values(), false), }, names.AttrTags: tftags.TagsSchema(), names.AttrTagsAll: tftags.TagsSchemaComputed(), From edcf454c550914cf43a8c522fa6f0da84cfc3c1c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 08:26:11 -0500 Subject: [PATCH 02/18] r/aws_media_convert_queue: Tidy up Create. --- internal/service/mediaconvert/queue.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/service/mediaconvert/queue.go b/internal/service/mediaconvert/queue.go index 15ba5ac9584..990c25dd75e 100644 --- a/internal/service/mediaconvert/queue.go +++ b/internal/service/mediaconvert/queue.go @@ -101,27 +101,29 @@ func resourceQueueCreate(ctx context.Context, d *schema.ResourceData, meta inter return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err) } - createOpts := &mediaconvert.CreateQueueInput{ - Name: aws.String(d.Get("name").(string)), - Status: aws.String(d.Get("status").(string)), + name := d.Get("name").(string) + input := &mediaconvert.CreateQueueInput{ + Name: aws.String(name), PricingPlan: aws.String(d.Get("pricing_plan").(string)), + Status: aws.String(d.Get("status").(string)), Tags: getTagsIn(ctx), } if v, ok := d.GetOk("description"); ok { - createOpts.Description = aws.String(v.(string)) + input.Description = aws.String(v.(string)) } if v, ok := d.Get("reservation_plan_settings").([]interface{}); ok && len(v) > 0 && v[0] != nil { - createOpts.ReservationPlanSettings = expandReservationPlanSettings(v[0].(map[string]interface{})) + input.ReservationPlanSettings = expandReservationPlanSettings(v[0].(map[string]interface{})) } - resp, err := conn.CreateQueueWithContext(ctx, createOpts) + output, err := conn.CreateQueueWithContext(ctx, input) + if err != nil { - return sdkdiag.AppendErrorf(diags, "creating Media Convert Queue: %s", err) + return sdkdiag.AppendErrorf(diags, "creating Media Convert Queue (%s): %s", name, err) } - d.SetId(aws.StringValue(resp.Queue.Name)) + d.SetId(aws.StringValue(output.Queue.Name)) return append(diags, resourceQueueRead(ctx, d, meta)...) } From 11c89de9e0fb3ce430fc5ae76b1121d587c0d3f4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 08:27:47 -0500 Subject: [PATCH 03/18] r/aws_media_convert_queue: Tidy up Delete. --- internal/service/mediaconvert/queue.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/service/mediaconvert/queue.go b/internal/service/mediaconvert/queue.go index 990c25dd75e..b6a373e16e4 100644 --- a/internal/service/mediaconvert/queue.go +++ b/internal/service/mediaconvert/queue.go @@ -215,14 +215,15 @@ func resourceQueueDelete(ctx context.Context, d *schema.ResourceData, meta inter return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err) } - delOpts := &mediaconvert.DeleteQueueInput{ + log.Printf("[DEBUG] Deleting Media Convert Queue: %s", d.Id()) + _, err = conn.DeleteQueueWithContext(ctx, &mediaconvert.DeleteQueueInput{ Name: aws.String(d.Id()), - } + }) - _, err = conn.DeleteQueueWithContext(ctx, delOpts) if tfawserr.ErrCodeEquals(err, mediaconvert.ErrCodeNotFoundException) { return diags } + if err != nil { return sdkdiag.AppendErrorf(diags, "deleting Media Convert Queue (%s): %s", d.Id(), err) } From 8179e52a31a6740954e694b441ba72683abdca6d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 08:28:59 -0500 Subject: [PATCH 04/18] r/aws_media_convert_queue: Tidy up Update. --- internal/service/mediaconvert/queue.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/service/mediaconvert/queue.go b/internal/service/mediaconvert/queue.go index b6a373e16e4..c1c554b1538 100644 --- a/internal/service/mediaconvert/queue.go +++ b/internal/service/mediaconvert/queue.go @@ -178,21 +178,21 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter } if d.HasChanges("description", "reservation_plan_settings", "status") { - updateOpts := &mediaconvert.UpdateQueueInput{ + input := &mediaconvert.UpdateQueueInput{ Name: aws.String(d.Id()), Status: aws.String(d.Get("status").(string)), } if v, ok := d.GetOk("description"); ok { - updateOpts.Description = aws.String(v.(string)) + input.Description = aws.String(v.(string)) } - if v, ok := d.GetOk("reservation_plan_settings"); ok { - reservationPlanSettings := v.([]interface{})[0].(map[string]interface{}) - updateOpts.ReservationPlanSettings = expandReservationPlanSettings(reservationPlanSettings) + if v, ok := d.Get("reservation_plan_settings").([]interface{}); ok && len(v) > 0 && v[0] != nil { + input.ReservationPlanSettings = expandReservationPlanSettings(v[0].(map[string]interface{})) } - _, err = conn.UpdateQueueWithContext(ctx, updateOpts) + _, err = conn.UpdateQueueWithContext(ctx, input) + if err != nil { return sdkdiag.AppendErrorf(diags, "updating Media Convert Queue (%s): %s", d.Id(), err) } From 2b30ad66b0800ce0bccf068c15c96138391b30d0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 08:35:07 -0500 Subject: [PATCH 05/18] r/aws_media_convert_queue: Tidy up Read. --- internal/service/mediaconvert/queue.go | 54 +++++++++++++++++++------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/internal/service/mediaconvert/queue.go b/internal/service/mediaconvert/queue.go index c1c554b1538..2b91195c085 100644 --- a/internal/service/mediaconvert/queue.go +++ b/internal/service/mediaconvert/queue.go @@ -13,11 +13,13 @@ import ( "github.com/aws/aws-sdk-go/service/mediaconvert" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -135,31 +137,28 @@ func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interfa return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err) } - getOpts := &mediaconvert.GetQueueInput{ - Name: aws.String(d.Id()), - } + queue, err := FindQueueByName(ctx, conn, d.Id()) - resp, err := conn.GetQueueWithContext(ctx, getOpts) - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, mediaconvert.ErrCodeNotFoundException) { + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Media Convert Queue (%s) not found, removing from state", d.Id()) d.SetId("") return diags } + if err != nil { - return sdkdiag.AppendErrorf(diags, "getting Media Convert Queue: %s", err) + return sdkdiag.AppendErrorf(diags, "reading Media Convert Queue (%s): %s", d.Id(), err) } - d.Set("arn", resp.Queue.Arn) - d.Set("name", resp.Queue.Name) - d.Set("description", resp.Queue.Description) - d.Set("pricing_plan", resp.Queue.PricingPlan) - d.Set("status", resp.Queue.Status) - - if err := d.Set("reservation_plan_settings", flattenReservationPlan(resp.Queue.ReservationPlan)); err != nil { - return sdkdiag.AppendErrorf(diags, "setting Media Convert Queue reservation_plan_settings: %s", err) + d.Set("arn", queue.Arn) + d.Set("description", queue.Description) + d.Set("name", queue.Name) + d.Set("pricing_plan", queue.PricingPlan) + if err := d.Set("reservation_plan_settings", flattenReservationPlan(queue.ReservationPlan)); err != nil { + return sdkdiag.AppendErrorf(diags, "setting reservation_plan_settings: %s", err) } + d.Set("status", queue.Status) - tags, err := listTags(ctx, conn, aws.StringValue(resp.Queue.Arn)) + tags, err := listTags(ctx, conn, aws.StringValue(queue.Arn)) if err != nil { return sdkdiag.AppendErrorf(diags, "listing tags for Media Convert Queue (%s): %s", d.Id(), err) @@ -231,6 +230,31 @@ func resourceQueueDelete(ctx context.Context, d *schema.ResourceData, meta inter return diags } +func FindQueueByName(ctx context.Context, conn *mediaconvert.MediaConvert, name string) (*mediaconvert.Queue, error) { + input := &mediaconvert.GetQueueInput{ + Name: aws.String(name), + } + + output, err := conn.GetQueueWithContext(ctx, input) + + if tfawserr.ErrCodeEquals(err, mediaconvert.ErrCodeNotFoundException) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || output.Queue == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return output.Queue, nil +} + func GetAccountClient(ctx context.Context, awsClient *conns.AWSClient) (*mediaconvert.MediaConvert, error) { const mutexKey = `mediaconvertaccountconn` conns.GlobalMutexKV.Lock(mutexKey) From 43c5a88c15a4e534ea5ef65cd7e09a30ffc33255 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 08:39:23 -0500 Subject: [PATCH 06/18] d/aws_media_convert_queue: Tidy up. --- .../service/mediaconvert/queue_data_source.go | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/internal/service/mediaconvert/queue_data_source.go b/internal/service/mediaconvert/queue_data_source.go index 8c3e9e8f404..2c0e4ecb495 100644 --- a/internal/service/mediaconvert/queue_data_source.go +++ b/internal/service/mediaconvert/queue_data_source.go @@ -7,7 +7,6 @@ import ( "context" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mediaconvert" "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" @@ -21,6 +20,10 @@ func DataSourceQueue() *schema.Resource { ReadWithoutTimeout: dataSourceQueueRead, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, "id": { Type: schema.TypeString, Required: true, @@ -29,10 +32,6 @@ func DataSourceQueue() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "arn": { - Type: schema.TypeString, - Computed: true, - }, "status": { Type: schema.TypeString, Computed: true, @@ -44,40 +43,33 @@ func DataSourceQueue() *schema.Resource { func dataSourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn, err := GetAccountClient(ctx, meta.(*conns.AWSClient)) if err != nil { return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err) } id := d.Get("id").(string) - - resp, err := conn.GetQueueWithContext(ctx, &mediaconvert.GetQueueInput{ - Name: aws.String(id), - }) + queue, err := FindQueueByName(ctx, conn, id) if err != nil { - return sdkdiag.AppendErrorf(diags, "getting Media Convert Queue (%s): %s", id, err) - } - - if resp == nil || resp.Queue == nil { - return sdkdiag.AppendErrorf(diags, "getting Media Convert Queue (%s): empty response", id) + return sdkdiag.AppendErrorf(diags, "reading Media Convert Queue (%s): %s", id, err) } - d.SetId(aws.StringValue(resp.Queue.Name)) - d.Set("name", resp.Queue.Name) - d.Set("arn", resp.Queue.Arn) - d.Set("status", resp.Queue.Status) + arn, name := aws.StringValue(queue.Arn), aws.StringValue(queue.Name) + d.SetId(name) + d.Set("arn", arn) + d.Set("name", name) + d.Set("status", queue.Status) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig - tags, err := listTags(ctx, conn, aws.StringValue(resp.Queue.Arn)) + tags, err := listTags(ctx, conn, arn) if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Media Convert Queue (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "listing tags for Media Convert Queue (%s): %s", arn, err) } if err := d.Set("tags", tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags for Media Convert Queue (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } return diags From 9a96f05f920c56d407f7f42fe5ded2eac10cdbce Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 08:48:16 -0500 Subject: [PATCH 07/18] mediaconvert: Tidy up acceptance tests. --- .../mediaconvert/queue_data_source_test.go | 76 +------- internal/service/mediaconvert/queue_test.go | 172 +++++++++--------- 2 files changed, 84 insertions(+), 164 deletions(-) diff --git a/internal/service/mediaconvert/queue_data_source_test.go b/internal/service/mediaconvert/queue_data_source_test.go index aac3fa961f8..8e3988c8370 100644 --- a/internal/service/mediaconvert/queue_data_source_test.go +++ b/internal/service/mediaconvert/queue_data_source_test.go @@ -22,63 +22,13 @@ func TestAccMediaConvertQueueDataSource_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccQueueDataSourceConfig_basic(rName), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"), + Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"), - ), - }, - }, - }) -} - -func TestAccMediaConvertQueueDataSource_withStatus(t *testing.T) { - ctx := acctest.Context(t) - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_media_convert_queue.test" - dataSourceName := "data.aws_media_convert_queue.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckQueueDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccQueueDataSourceConfig_status(rName, mediaconvert.QueueStatusActive), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"), - resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"), - resource.TestCheckResourceAttrPair(resourceName, "status", dataSourceName, "status"), - ), - }, - }, - }) -} - -func TestAccMediaConvertQueueDataSource_withTags(t *testing.T) { - ctx := acctest.Context(t) - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_media_convert_queue.test" - dataSourceName := "data.aws_media_convert_queue.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckQueueDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccQueueDataSourceConfig_tags(rName, "foo", "bar", "fizz", "buzz"), - Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"), - resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"), resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"), - resource.TestCheckResourceAttrPair(resourceName, "tags.foo", dataSourceName, "tags.foo"), - resource.TestCheckResourceAttrPair(resourceName, "tags.fizz", dataSourceName, "tags.fizz"), ), }, }, @@ -86,29 +36,7 @@ func TestAccMediaConvertQueueDataSource_withTags(t *testing.T) { } func testAccQueueDataSourceConfig_basic(rName string) string { - return acctest.ConfigCompose( - testAccQueueConfig_basic(rName), - ` -data "aws_media_convert_queue" "test" { - id = aws_media_convert_queue.test.id -} -`) -} - -func testAccQueueDataSourceConfig_status(rName, status string) string { - return acctest.ConfigCompose( - testAccQueueConfig_status(rName, status), - ` -data "aws_media_convert_queue" "test" { - id = aws_media_convert_queue.test.id -} -`) -} - -func testAccQueueDataSourceConfig_tags(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return acctest.ConfigCompose( - testAccQueueConfig_tags(rName, tagKey1, tagValue1, tagKey2, tagValue2), - ` + return acctest.ConfigCompose(testAccQueueConfig_basic(rName), ` data "aws_media_convert_queue" "test" { id = aws_media_convert_queue.test.id } diff --git a/internal/service/mediaconvert/queue_test.go b/internal/service/mediaconvert/queue_test.go index 48e8d7427b1..d5c6f118939 100644 --- a/internal/service/mediaconvert/queue_test.go +++ b/internal/service/mediaconvert/queue_test.go @@ -9,15 +9,14 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/mediaconvert" - "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" tfmediaconvert "github.com/hashicorp/terraform-provider-aws/internal/service/mediaconvert" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func TestAccMediaConvertQueue_basic(t *testing.T) { @@ -34,7 +33,7 @@ func TestAccMediaConvertQueue_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccQueueConfig_basic(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "mediaconvert", regexache.MustCompile(`queues/.+`)), resource.TestCheckResourceAttr(resourceName, "name", rName), @@ -51,11 +50,8 @@ func TestAccMediaConvertQueue_basic(t *testing.T) { }) } -func TestAccMediaConvertQueue_reservationPlanSettings(t *testing.T) { - acctest.Skip(t, "MediaConvert Reserved Queues are $400/month and cannot be deleted for 1 year.") - +func TestAccMediaConvertQueue_disappears(t *testing.T) { ctx := acctest.Context(t) - var queue mediaconvert.Queue resourceName := "aws_media_convert_queue.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -67,37 +63,18 @@ func TestAccMediaConvertQueue_reservationPlanSettings(t *testing.T) { CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccQueueConfig_reserved(rName, mediaconvert.CommitmentOneYear, mediaconvert.RenewalTypeAutoRenew, 1), - Check: resource.ComposeTestCheckFunc( - testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "pricing_plan", mediaconvert.PricingPlanReserved), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.commitment", mediaconvert.CommitmentOneYear), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.renewal_type", mediaconvert.RenewalTypeAutoRenew), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.reserved_slots", "1"), - ), - }, - { - Config: testAccQueueConfig_reserved(rName, mediaconvert.CommitmentOneYear, mediaconvert.RenewalTypeExpire, 2), + Config: testAccQueueConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "pricing_plan", mediaconvert.PricingPlanReserved), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.commitment", mediaconvert.CommitmentOneYear), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.renewal_type", mediaconvert.RenewalTypeExpire), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.reserved_slots", "1"), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tfmediaconvert.ResourceQueue(), resourceName), ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ExpectNonEmptyPlan: true, }, }, }) } -func TestAccMediaConvertQueue_withStatus(t *testing.T) { +func TestAccMediaConvertQueue_withTags(t *testing.T) { ctx := acctest.Context(t) var queue mediaconvert.Queue resourceName := "aws_media_convert_queue.test" @@ -110,29 +87,42 @@ func TestAccMediaConvertQueue_withStatus(t *testing.T) { CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccQueueConfig_status(rName, mediaconvert.QueueStatusPaused), + Config: testAccQueueConfig_tags1(rName, "key1", "value1"), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "status", mediaconvert.QueueStatusPaused), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), ), }, { - Config: testAccQueueConfig_status(rName, mediaconvert.QueueStatusActive), + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccQueueConfig_tags2(rName, "key1", "value1updated", "key2", "value2"), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "status", mediaconvert.QueueStatusActive), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccQueueConfig_tags1(rName, "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckQueueExists(ctx, resourceName, &queue), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), }, }, }) } -func TestAccMediaConvertQueue_withTags(t *testing.T) { +func TestAccMediaConvertQueue_reservationPlanSettings(t *testing.T) { + acctest.Skip(t, "MediaConvert Reserved Queues are $400/month and cannot be deleted for 1 year.") + ctx := acctest.Context(t) var queue mediaconvert.Queue resourceName := "aws_media_convert_queue.test" @@ -145,21 +135,25 @@ func TestAccMediaConvertQueue_withTags(t *testing.T) { CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccQueueConfig_tags(rName, "foo", "bar", "fizz", "buzz"), + Config: testAccQueueConfig_reserved(rName, mediaconvert.CommitmentOneYear, mediaconvert.RenewalTypeAutoRenew, 1), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"), - resource.TestCheckResourceAttr(resourceName, "tags.fizz", "buzz"), + resource.TestCheckResourceAttr(resourceName, "pricing_plan", mediaconvert.PricingPlanReserved), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.#", "1"), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.commitment", mediaconvert.CommitmentOneYear), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.renewal_type", mediaconvert.RenewalTypeAutoRenew), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.reserved_slots", "1"), ), }, { - Config: testAccQueueConfig_tags(rName, "foo", "bar2", "fizz2", "buzz2"), + Config: testAccQueueConfig_reserved(rName, mediaconvert.CommitmentOneYear, mediaconvert.RenewalTypeExpire, 2), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar2"), - resource.TestCheckResourceAttr(resourceName, "tags.fizz2", "buzz2"), + resource.TestCheckResourceAttr(resourceName, "pricing_plan", mediaconvert.PricingPlanReserved), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.#", "1"), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.commitment", mediaconvert.CommitmentOneYear), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.renewal_type", mediaconvert.RenewalTypeExpire), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.reserved_slots", "1"), ), }, { @@ -167,18 +161,11 @@ func TestAccMediaConvertQueue_withTags(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - { - Config: testAccQueueConfig_basic(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - ), - }, }, }) } -func TestAccMediaConvertQueue_disappears(t *testing.T) { +func TestAccMediaConvertQueue_withStatus(t *testing.T) { ctx := acctest.Context(t) var queue mediaconvert.Queue resourceName := "aws_media_convert_queue.test" @@ -191,12 +178,23 @@ func TestAccMediaConvertQueue_disappears(t *testing.T) { CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccQueueConfig_basic(rName), + Config: testAccQueueConfig_status(rName, mediaconvert.QueueStatusPaused), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - testAccCheckQueueDisappears(ctx, &queue), + resource.TestCheckResourceAttr(resourceName, "status", mediaconvert.QueueStatusPaused), ), - ExpectNonEmptyPlan: true, + }, + { + Config: testAccQueueConfig_status(rName, mediaconvert.QueueStatusActive), + Check: resource.ComposeTestCheckFunc( + testAccCheckQueueExists(ctx, resourceName, &queue), + resource.TestCheckResourceAttr(resourceName, "status", mediaconvert.QueueStatusActive), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -240,67 +238,49 @@ func testAccCheckQueueDestroy(ctx context.Context) resource.TestCheckFunc { if rs.Type != "aws_media_convert_queue" { continue } + conn, err := tfmediaconvert.GetAccountClient(ctx, acctest.Provider.Meta().(*conns.AWSClient)) if err != nil { return fmt.Errorf("Error getting Media Convert Account Client: %s", err) } - _, err = conn.GetQueueWithContext(ctx, &mediaconvert.GetQueueInput{ - Name: aws.String(rs.Primary.ID), - }) + _, err = tfmediaconvert.FindQueueByName(ctx, conn, rs.Primary.ID) + + if tfresource.NotFound(err) { + continue + } + if err != nil { - if tfawserr.ErrCodeEquals(err, mediaconvert.ErrCodeNotFoundException) { - continue - } return err } - } - return nil - } -} - -func testAccCheckQueueDisappears(ctx context.Context, queue *mediaconvert.Queue) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn, err := tfmediaconvert.GetAccountClient(ctx, acctest.Provider.Meta().(*conns.AWSClient)) - if err != nil { - return fmt.Errorf("Error getting Media Convert Account Client: %s", err) + return fmt.Errorf("Media Convert Queue %s still exists", rs.Primary.ID) } - _, err = conn.DeleteQueueWithContext(ctx, &mediaconvert.DeleteQueueInput{ - Name: queue.Name, - }) - if err != nil { - return fmt.Errorf("Deleting Media Convert Queue: %s", err) - } return nil } } -func testAccCheckQueueExists(ctx context.Context, n string, queue *mediaconvert.Queue) resource.TestCheckFunc { +func testAccCheckQueueExists(ctx context.Context, n string, v *mediaconvert.Queue) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No Queue id is set") - } - conn, err := tfmediaconvert.GetAccountClient(ctx, acctest.Provider.Meta().(*conns.AWSClient)) if err != nil { return fmt.Errorf("Error getting Media Convert Account Client: %s", err) } - resp, err := conn.GetQueueWithContext(ctx, &mediaconvert.GetQueueInput{ - Name: aws.String(rs.Primary.ID), - }) + output, err := tfmediaconvert.FindQueueByName(ctx, conn, rs.Primary.ID) + if err != nil { - return fmt.Errorf("Error getting queue: %s", err) + return err } - *queue = *resp.Queue + *v = *output + return nil } } @@ -343,7 +323,19 @@ resource "aws_media_convert_queue" "test" { `, rName, description) } -func testAccQueueConfig_tags(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { +func testAccQueueConfig_tags1(rName, tagKey1, tagValue1 string) string { + return fmt.Sprintf(` +resource "aws_media_convert_queue" "test" { + name = %[1]q + + tags = { + %[2]s = %[3]q + } +} +`, rName, tagKey1, tagValue1) +} + +func testAccQueueConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { return fmt.Sprintf(` resource "aws_media_convert_queue" "test" { name = %[1]q From 6772f964c69d71287c12275658437246643ead9e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 09:13:50 -0500 Subject: [PATCH 08/18] Acceptance test output: % make testacc TESTARGS='-run=TestAccMediaConvert' PKG=mediaconvert ACCTEST_PARALLELISM=2 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/mediaconvert/... -v -count 1 -parallel 2 -run=TestAccMediaConvert -timeout 360m === RUN TestAccMediaConvertQueueDataSource_basic === PAUSE TestAccMediaConvertQueueDataSource_basic === RUN TestAccMediaConvertQueue_basic === PAUSE TestAccMediaConvertQueue_basic === RUN TestAccMediaConvertQueue_disappears === PAUSE TestAccMediaConvertQueue_disappears === RUN TestAccMediaConvertQueue_withTags === PAUSE TestAccMediaConvertQueue_withTags === RUN TestAccMediaConvertQueue_reservationPlanSettings acctest.go:93: MediaConvert Reserved Queues are $400/month and cannot be deleted for 1 year. --- SKIP: TestAccMediaConvertQueue_reservationPlanSettings (0.00s) === RUN TestAccMediaConvertQueue_withStatus === PAUSE TestAccMediaConvertQueue_withStatus === RUN TestAccMediaConvertQueue_withDescription === PAUSE TestAccMediaConvertQueue_withDescription === CONT TestAccMediaConvertQueueDataSource_basic === CONT TestAccMediaConvertQueue_withTags --- PASS: TestAccMediaConvertQueueDataSource_basic (42.69s) === CONT TestAccMediaConvertQueue_withDescription --- PASS: TestAccMediaConvertQueue_withTags (118.81s) === CONT TestAccMediaConvertQueue_disappears --- PASS: TestAccMediaConvertQueue_withDescription (78.13s) === CONT TestAccMediaConvertQueue_basic --- PASS: TestAccMediaConvertQueue_disappears (65.92s) === CONT TestAccMediaConvertQueue_withStatus --- PASS: TestAccMediaConvertQueue_basic (80.26s) --- PASS: TestAccMediaConvertQueue_withStatus (52.32s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/mediaconvert 247.966s From ac9bb513a144a5d3e7b6eb98045ca429d49ded7c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 09:23:35 -0500 Subject: [PATCH 09/18] mediaconvert: Use standard API connection. --- internal/conns/awsclient.go | 22 +++---- internal/service/mediaconvert/queue.go | 64 ++----------------- .../service/mediaconvert/queue_data_source.go | 5 +- .../mediaconvert/queue_data_source_test.go | 2 +- internal/service/mediaconvert/queue_test.go | 36 +++-------- 5 files changed, 27 insertions(+), 102 deletions(-) diff --git a/internal/conns/awsclient.go b/internal/conns/awsclient.go index 273f5ae3bd4..ba065efc2df 100644 --- a/internal/conns/awsclient.go +++ b/internal/conns/awsclient.go @@ -16,7 +16,6 @@ import ( endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints" session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" apigatewayv2_sdkv1 "github.com/aws/aws-sdk-go/service/apigatewayv2" - mediaconvert_sdkv1 "github.com/aws/aws-sdk-go/service/mediaconvert" baselogging "github.com/hashicorp/aws-sdk-go-base/v2/logging" "github.com/hashicorp/terraform-provider-aws/internal/errs" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -25,17 +24,16 @@ import ( ) type AWSClient struct { - AccountID string - DefaultTagsConfig *tftags.DefaultConfig - DNSSuffix string - IgnoreTagsConfig *tftags.IgnoreConfig - MediaConvertAccountConn *mediaconvert_sdkv1.MediaConvert - Partition string - Region string - ReverseDNSPrefix string - ServicePackages map[string]ServicePackage - Session *session_sdkv1.Session - TerraformVersion string + AccountID string + DefaultTagsConfig *tftags.DefaultConfig + DNSSuffix string + IgnoreTagsConfig *tftags.IgnoreConfig + Partition string + Region string + ReverseDNSPrefix string + ServicePackages map[string]ServicePackage + Session *session_sdkv1.Session + TerraformVersion string awsConfig *aws_sdkv2.Config clients map[string]any diff --git a/internal/service/mediaconvert/queue.go b/internal/service/mediaconvert/queue.go index 2b91195c085..a7a0d71ee17 100644 --- a/internal/service/mediaconvert/queue.go +++ b/internal/service/mediaconvert/queue.go @@ -5,11 +5,9 @@ package mediaconvert import ( "context" - "fmt" "log" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mediaconvert" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -98,10 +96,7 @@ func ResourceQueue() *schema.Resource { func resourceQueueCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn, err := GetAccountClient(ctx, meta.(*conns.AWSClient)) - if err != nil { - return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err) - } + conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) name := d.Get("name").(string) input := &mediaconvert.CreateQueueInput{ @@ -132,10 +127,7 @@ func resourceQueueCreate(ctx context.Context, d *schema.ResourceData, meta inter func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn, err := GetAccountClient(ctx, meta.(*conns.AWSClient)) - if err != nil { - return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err) - } + conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) queue, err := FindQueueByName(ctx, conn, d.Id()) @@ -171,10 +163,7 @@ func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interfa func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn, err := GetAccountClient(ctx, meta.(*conns.AWSClient)) - if err != nil { - return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err) - } + conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) if d.HasChanges("description", "reservation_plan_settings", "status") { input := &mediaconvert.UpdateQueueInput{ @@ -190,7 +179,7 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter input.ReservationPlanSettings = expandReservationPlanSettings(v[0].(map[string]interface{})) } - _, err = conn.UpdateQueueWithContext(ctx, input) + _, err := conn.UpdateQueueWithContext(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating Media Convert Queue (%s): %s", d.Id(), err) @@ -209,13 +198,10 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter func resourceQueueDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn, err := GetAccountClient(ctx, meta.(*conns.AWSClient)) - if err != nil { - return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err) - } + conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) log.Printf("[DEBUG] Deleting Media Convert Queue: %s", d.Id()) - _, err = conn.DeleteQueueWithContext(ctx, &mediaconvert.DeleteQueueInput{ + _, err := conn.DeleteQueueWithContext(ctx, &mediaconvert.DeleteQueueInput{ Name: aws.String(d.Id()), }) @@ -254,41 +240,3 @@ func FindQueueByName(ctx context.Context, conn *mediaconvert.MediaConvert, name return output.Queue, nil } - -func GetAccountClient(ctx context.Context, awsClient *conns.AWSClient) (*mediaconvert.MediaConvert, error) { - const mutexKey = `mediaconvertaccountconn` - conns.GlobalMutexKV.Lock(mutexKey) - defer conns.GlobalMutexKV.Unlock(mutexKey) - - if awsClient.MediaConvertAccountConn != nil { - return awsClient.MediaConvertAccountConn, nil - } - - input := &mediaconvert.DescribeEndpointsInput{ - Mode: aws.String(mediaconvert.DescribeEndpointsModeDefault), - } - - output, err := awsClient.MediaConvertConn(ctx).DescribeEndpointsWithContext(ctx, input) - - if err != nil { - return nil, fmt.Errorf("describing MediaConvert Endpoints: %w", err) - } - - if output == nil || len(output.Endpoints) == 0 || output.Endpoints[0] == nil || output.Endpoints[0].Url == nil { - return nil, fmt.Errorf("describing MediaConvert Endpoints: empty response or URL") - } - - endpointURL := aws.StringValue(output.Endpoints[0].Url) - - sess, err := session.NewSession(&awsClient.MediaConvertConn(ctx).Config) - - if err != nil { - return nil, fmt.Errorf("creating AWS MediaConvert session: %w", err) - } - - conn := mediaconvert.New(sess.Copy(&aws.Config{Endpoint: aws.String(endpointURL)})) - - awsClient.MediaConvertAccountConn = conn - - return conn, nil -} diff --git a/internal/service/mediaconvert/queue_data_source.go b/internal/service/mediaconvert/queue_data_source.go index 2c0e4ecb495..6835bc1497b 100644 --- a/internal/service/mediaconvert/queue_data_source.go +++ b/internal/service/mediaconvert/queue_data_source.go @@ -43,10 +43,7 @@ func DataSourceQueue() *schema.Resource { func dataSourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn, err := GetAccountClient(ctx, meta.(*conns.AWSClient)) - if err != nil { - return sdkdiag.AppendErrorf(diags, "getting Media Convert Account Client: %s", err) - } + conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) id := d.Get("id").(string) queue, err := FindQueueByName(ctx, conn, id) diff --git a/internal/service/mediaconvert/queue_data_source_test.go b/internal/service/mediaconvert/queue_data_source_test.go index 8e3988c8370..90d63a283e9 100644 --- a/internal/service/mediaconvert/queue_data_source_test.go +++ b/internal/service/mediaconvert/queue_data_source_test.go @@ -19,7 +19,7 @@ func TestAccMediaConvertQueueDataSource_basic(t *testing.T) { dataSourceName := "data.aws_media_convert_queue.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ diff --git a/internal/service/mediaconvert/queue_test.go b/internal/service/mediaconvert/queue_test.go index d5c6f118939..278eab1b49e 100644 --- a/internal/service/mediaconvert/queue_test.go +++ b/internal/service/mediaconvert/queue_test.go @@ -26,7 +26,7 @@ func TestAccMediaConvertQueue_basic(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), @@ -57,7 +57,7 @@ func TestAccMediaConvertQueue_disappears(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), @@ -81,7 +81,7 @@ func TestAccMediaConvertQueue_withTags(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), @@ -129,7 +129,7 @@ func TestAccMediaConvertQueue_reservationPlanSettings(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), @@ -172,7 +172,7 @@ func TestAccMediaConvertQueue_withStatus(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), @@ -209,7 +209,7 @@ func TestAccMediaConvertQueue_withDescription(t *testing.T) { description2 := sdkacctest.RandomWithPrefix("Description: ") resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), @@ -239,12 +239,9 @@ func testAccCheckQueueDestroy(ctx context.Context) resource.TestCheckFunc { continue } - conn, err := tfmediaconvert.GetAccountClient(ctx, acctest.Provider.Meta().(*conns.AWSClient)) - if err != nil { - return fmt.Errorf("Error getting Media Convert Account Client: %s", err) - } + conn := acctest.Provider.Meta().(*conns.AWSClient).MediaConvertConn(ctx) - _, err = tfmediaconvert.FindQueueByName(ctx, conn, rs.Primary.ID) + _, err := tfmediaconvert.FindQueueByName(ctx, conn, rs.Primary.ID) if tfresource.NotFound(err) { continue @@ -268,10 +265,7 @@ func testAccCheckQueueExists(ctx context.Context, n string, v *mediaconvert.Queu return fmt.Errorf("Not found: %s", n) } - conn, err := tfmediaconvert.GetAccountClient(ctx, acctest.Provider.Meta().(*conns.AWSClient)) - if err != nil { - return fmt.Errorf("Error getting Media Convert Account Client: %s", err) - } + conn := acctest.Provider.Meta().(*conns.AWSClient).MediaConvertConn(ctx) output, err := tfmediaconvert.FindQueueByName(ctx, conn, rs.Primary.ID) @@ -285,18 +279,6 @@ func testAccCheckQueueExists(ctx context.Context, n string, v *mediaconvert.Queu } } -func testAccPreCheck(ctx context.Context, t *testing.T) { - _, err := tfmediaconvert.GetAccountClient(ctx, acctest.Provider.Meta().(*conns.AWSClient)) - - if acctest.PreCheckSkipError(err) { - t.Skipf("skipping acceptance testing: %s", err) - } - - if err != nil { - t.Fatalf("unexpected PreCheck error: %s", err) - } -} - func testAccQueueConfig_basic(rName string) string { return fmt.Sprintf(` resource "aws_media_convert_queue" "test" { From 3eecf433e680598c05ef3603e8c00c127bae9813 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 10:12:15 -0500 Subject: [PATCH 10/18] Acceptance test output: % make testacc TESTARGS='-run=TestAccMediaConvert' PKG=mediaconvert ACCTEST_PARALLELISM=2 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/mediaconvert/... -v -count 1 -parallel 2 -run=TestAccMediaConvert -timeout 360m === RUN TestAccMediaConvertQueueDataSource_basic === PAUSE TestAccMediaConvertQueueDataSource_basic === RUN TestAccMediaConvertQueue_basic === PAUSE TestAccMediaConvertQueue_basic === RUN TestAccMediaConvertQueue_disappears === PAUSE TestAccMediaConvertQueue_disappears === RUN TestAccMediaConvertQueue_withTags === PAUSE TestAccMediaConvertQueue_withTags === RUN TestAccMediaConvertQueue_reservationPlanSettings acctest.go:93: MediaConvert Reserved Queues are $400/month and cannot be deleted for 1 year. --- SKIP: TestAccMediaConvertQueue_reservationPlanSettings (0.00s) === RUN TestAccMediaConvertQueue_withStatus === PAUSE TestAccMediaConvertQueue_withStatus === RUN TestAccMediaConvertQueue_withDescription === PAUSE TestAccMediaConvertQueue_withDescription === CONT TestAccMediaConvertQueueDataSource_basic === CONT TestAccMediaConvertQueue_withTags --- PASS: TestAccMediaConvertQueueDataSource_basic (17.37s) === CONT TestAccMediaConvertQueue_withDescription --- PASS: TestAccMediaConvertQueue_withTags (44.88s) === CONT TestAccMediaConvertQueue_disappears --- PASS: TestAccMediaConvertQueue_withDescription (27.56s) === CONT TestAccMediaConvertQueue_basic --- PASS: TestAccMediaConvertQueue_disappears (16.32s) === CONT TestAccMediaConvertQueue_withStatus --- PASS: TestAccMediaConvertQueue_basic (19.36s) --- PASS: TestAccMediaConvertQueue_withStatus (28.81s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/mediaconvert 99.890s From c96b3260249b15d48270defa59d48e4642c89235 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 10:14:55 -0500 Subject: [PATCH 11/18] mediaconvert: Use AWS SDK for Go v2. --- names/data/names_data.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/names/data/names_data.csv b/names/data/names_data.csv index d5145f5fc52..9f28bbf62d2 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -142,7 +142,7 @@ es,es,elasticsearchservice,elasticsearchservice,elasticsearch,es,,es;elasticsear elbv2,elbv2,elbv2,elasticloadbalancingv2,,elbv2,,elasticloadbalancingv2,ELBV2,ELBV2,,1,2,aws_a?lb(\b|_listener|_target_group|s|_trust_store),aws_elbv2_,,lbs?\.;lb_listener;lb_target_group;lb_hosted;lb_trust_store,ELB (Elastic Load Balancing),,,,,,,,Elastic Load Balancing v2,DescribeLoadBalancers,, elb,elb,elb,elasticloadbalancing,,elb,,elasticloadbalancing,ELB,ELB,,1,,aws_(app_cookie_stickiness_policy|elb|lb_cookie_stickiness_policy|lb_ssl_negotiation_policy|load_balancer_|proxy_protocol_policy),aws_elb_,,app_cookie_stickiness_policy;elb;lb_cookie_stickiness_policy;lb_ssl_negotiation_policy;load_balancer;proxy_protocol_policy,ELB Classic,,,,,,,,Elastic Load Balancing,DescribeLoadBalancers,, mediaconnect,mediaconnect,mediaconnect,mediaconnect,,mediaconnect,,,MediaConnect,MediaConnect,,,2,,aws_mediaconnect_,,mediaconnect_,Elemental MediaConnect,AWS,,,,,,,MediaConnect,ListBridges,, -mediaconvert,mediaconvert,mediaconvert,mediaconvert,,mediaconvert,,,MediaConvert,MediaConvert,,1,,aws_media_convert_,aws_mediaconvert_,,media_convert_,Elemental MediaConvert,AWS,,,,,,,MediaConvert,ListJobs,, +mediaconvert,mediaconvert,mediaconvert,mediaconvert,,mediaconvert,,,MediaConvert,MediaConvert,,,2,aws_media_convert_,aws_mediaconvert_,,media_convert_,Elemental MediaConvert,AWS,,,,,,,MediaConvert,ListJobs,, medialive,medialive,medialive,medialive,,medialive,,,MediaLive,MediaLive,,,2,,aws_medialive_,,medialive_,Elemental MediaLive,AWS,,,,,,,MediaLive,ListOfferings,, mediapackage,mediapackage,mediapackage,mediapackage,,mediapackage,,,MediaPackage,MediaPackage,,,2,aws_media_package_,aws_mediapackage_,,media_package_,Elemental MediaPackage,AWS,,,,,,,MediaPackage,ListChannels,, mediapackage-vod,mediapackagevod,mediapackagevod,mediapackagevod,,mediapackagevod,,,MediaPackageVOD,MediaPackageVod,,1,,,aws_mediapackagevod_,,mediapackagevod_,Elemental MediaPackage VOD,AWS,,x,,,,,MediaPackage Vod,,, From f307921bbdf9b14db28fa0cff2dceecd623a472a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 10:18:18 -0500 Subject: [PATCH 12/18] Run 'make gen'. --- internal/conns/awsclient_gen.go | 6 +-- internal/service/mediaconvert/generate.go | 2 +- .../service_endpoints_gen_test.go | 40 ++++++++++++------- .../mediaconvert/service_package_gen.go | 17 ++++---- internal/service/mediaconvert/tags_gen.go | 33 ++++++++------- 5 files changed, 55 insertions(+), 43 deletions(-) diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index a091ff814b7..728545c95b5 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -67,6 +67,7 @@ import ( lookoutmetrics_sdkv2 "github.com/aws/aws-sdk-go-v2/service/lookoutmetrics" m2_sdkv2 "github.com/aws/aws-sdk-go-v2/service/m2" mediaconnect_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediaconnect" + mediaconvert_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediaconvert" medialive_sdkv2 "github.com/aws/aws-sdk-go-v2/service/medialive" mediapackage_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediapackage" mediapackagev2_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" @@ -198,7 +199,6 @@ import ( locationservice_sdkv1 "github.com/aws/aws-sdk-go/service/locationservice" macie2_sdkv1 "github.com/aws/aws-sdk-go/service/macie2" managedgrafana_sdkv1 "github.com/aws/aws-sdk-go/service/managedgrafana" - mediaconvert_sdkv1 "github.com/aws/aws-sdk-go/service/mediaconvert" mediastore_sdkv1 "github.com/aws/aws-sdk-go/service/mediastore" memorydb_sdkv1 "github.com/aws/aws-sdk-go/service/memorydb" mwaa_sdkv1 "github.com/aws/aws-sdk-go/service/mwaa" @@ -825,8 +825,8 @@ func (c *AWSClient) MediaConnectClient(ctx context.Context) *mediaconnect_sdkv2. return errs.Must(client[*mediaconnect_sdkv2.Client](ctx, c, names.MediaConnect, make(map[string]any))) } -func (c *AWSClient) MediaConvertConn(ctx context.Context) *mediaconvert_sdkv1.MediaConvert { - return errs.Must(conn[*mediaconvert_sdkv1.MediaConvert](ctx, c, names.MediaConvert, make(map[string]any))) +func (c *AWSClient) MediaConvertClient(ctx context.Context) *mediaconvert_sdkv2.Client { + return errs.Must(client[*mediaconvert_sdkv2.Client](ctx, c, names.MediaConvert, make(map[string]any))) } func (c *AWSClient) MediaLiveClient(ctx context.Context) *medialive_sdkv2.Client { diff --git a/internal/service/mediaconvert/generate.go b/internal/service/mediaconvert/generate.go index e85db640728..204feb2919b 100644 --- a/internal/service/mediaconvert/generate.go +++ b/internal/service/mediaconvert/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=Arn -ListTagsOutTagsElem=ResourceTags.Tags -ServiceTagsMap -TagInIDElem=Arn -UpdateTags +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsInIDElem=Arn -ListTagsOutTagsElem=ResourceTags.Tags -ServiceTagsMap -TagInIDElem=Arn -UpdateTags -KVTValues -SkipTypesImp //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/mediaconvert/service_endpoints_gen_test.go b/internal/service/mediaconvert/service_endpoints_gen_test.go index 869112cc794..d0d724fbf32 100644 --- a/internal/service/mediaconvert/service_endpoints_gen_test.go +++ b/internal/service/mediaconvert/service_endpoints_gen_test.go @@ -4,16 +4,16 @@ package mediaconvert_test import ( "context" + "errors" "fmt" - "net/url" "os" "path/filepath" "reflect" "strings" "testing" - "github.com/aws/aws-sdk-go/aws/endpoints" - mediaconvert_sdkv1 "github.com/aws/aws-sdk-go/service/mediaconvert" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + mediaconvert_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediaconvert" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -212,32 +212,42 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S } func defaultEndpoint(region string) string { - r := endpoints.DefaultResolver() + r := mediaconvert_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(mediaconvert_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), mediaconvert_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) if err != nil { return err.Error() } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return url.String() + return ep.URI.String() } func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { t.Helper() - client := meta.MediaConvertConn(ctx) - - req, _ := client.ListJobsRequest(&mediaconvert_sdkv1.ListJobsInput{}) + var endpoint string - req.HTTPRequest.URL.Path = "/" + client := meta.MediaConvertClient(ctx) - endpoint := req.HTTPRequest.URL.String() + _, err := client.ListJobs(ctx, &mediaconvert_sdkv2.ListJobsInput{}, + func(opts *mediaconvert_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &endpoint), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) + } return endpoint } diff --git a/internal/service/mediaconvert/service_package_gen.go b/internal/service/mediaconvert/service_package_gen.go index 602ea90b139..7a40a73bfe7 100644 --- a/internal/service/mediaconvert/service_package_gen.go +++ b/internal/service/mediaconvert/service_package_gen.go @@ -5,9 +5,8 @@ package mediaconvert import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - mediaconvert_sdkv1 "github.com/aws/aws-sdk-go/service/mediaconvert" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + mediaconvert_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediaconvert" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -48,11 +47,15 @@ func (p *servicePackage) ServicePackageName() string { return names.MediaConvert } -// 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) (*mediaconvert_sdkv1.MediaConvert, error) { - sess := config["session"].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*mediaconvert_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return mediaconvert_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil + return mediaconvert_sdkv2.NewFromConfig(cfg, func(o *mediaconvert_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/mediaconvert/tags_gen.go b/internal/service/mediaconvert/tags_gen.go index 71fde3560ac..771483a7513 100644 --- a/internal/service/mediaconvert/tags_gen.go +++ b/internal/service/mediaconvert/tags_gen.go @@ -5,9 +5,8 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mediaconvert" - "github.com/aws/aws-sdk-go/service/mediaconvert/mediaconvertiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mediaconvert" "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 mediaconvert 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 mediaconvertiface.MediaConvertAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *mediaconvert.Client, identifier string, optFns ...func(*mediaconvert.Options)) (tftags.KeyValueTags, error) { input := &mediaconvert.ListTagsForResourceInput{ Arn: 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 mediaconvertiface.MediaConvertAPI, ident // ListTags lists mediaconvert 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).MediaConvertConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).MediaConvertClient(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 mediaconvert 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 mediaconvert 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 mediaconvert 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 mediaconvert 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 mediaconvert 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 mediaconvertiface.MediaConvertAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *mediaconvert.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*mediaconvert.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -94,10 +93,10 @@ func updateTags(ctx context.Context, conn mediaconvertiface.MediaConvertAPI, ide if len(removedTags) > 0 { input := &mediaconvert.UntagResourceInput{ Arn: 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 mediaconvertiface.MediaConvertAPI, ide 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 mediaconvertiface.MediaConvertAPI, ide // UpdateTags updates mediaconvert 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).MediaConvertConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).MediaConvertClient(ctx), identifier, oldTags, newTags) } From 8a7ae023153bf1ac81aebac1c8ecdc77cf615d95 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 10:20:01 -0500 Subject: [PATCH 13/18] Run 'go get github.com/aws/aws-sdk-go-v2/service/mediaconvert@v1.49.1 && go mod tidy'. --- go.mod | 1 + go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/go.mod b/go.mod index 06025b5a6b6..905cffaac6c 100644 --- a/go.mod +++ b/go.mod @@ -73,6 +73,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/lookoutmetrics v1.25.6 github.com/aws/aws-sdk-go-v2/service/m2 v1.10.7 github.com/aws/aws-sdk-go-v2/service/mediaconnect v1.25.1 + github.com/aws/aws-sdk-go-v2/service/mediaconvert v1.49.1 github.com/aws/aws-sdk-go-v2/service/medialive v1.44.1 github.com/aws/aws-sdk-go-v2/service/mediapackage v1.28.7 github.com/aws/aws-sdk-go-v2/service/mediapackagev2 v1.7.7 diff --git a/go.sum b/go.sum index 0871043f946..8e64054afa6 100644 --- a/go.sum +++ b/go.sum @@ -180,6 +180,8 @@ github.com/aws/aws-sdk-go-v2/service/m2 v1.10.7 h1:5etXqoLGqO/63wcrEJHhZ42+pA/sT github.com/aws/aws-sdk-go-v2/service/m2 v1.10.7/go.mod h1:RwwoIKmTLC0noLzjd3V+Tm/zPriuaBXd1/uXmGKIAko= github.com/aws/aws-sdk-go-v2/service/mediaconnect v1.25.1 h1:GnROse8mFPn5tiUrcLrSlCl64N3HZoLKVJlnM+1Txzo= github.com/aws/aws-sdk-go-v2/service/mediaconnect v1.25.1/go.mod h1:YtYScucFEyg+/50YWZlIt8XjYMTIQbjw6dgz9/UYZXA= +github.com/aws/aws-sdk-go-v2/service/mediaconvert v1.49.1 h1:7W2XOA9H0ddbkhZjKCez0e9aVqVQXyqxQhdLDDqfASI= +github.com/aws/aws-sdk-go-v2/service/mediaconvert v1.49.1/go.mod h1:aCUF5+yUBBaesG5FH67HY4pIYOMJK3UzajdnXSCOFGg= github.com/aws/aws-sdk-go-v2/service/medialive v1.44.1 h1:5iU4di93LKUIUAvcHY9TXR8MvrHKhrOjpL/CINGuV04= github.com/aws/aws-sdk-go-v2/service/medialive v1.44.1/go.mod h1:SITOSt2FpMrkZzTD/8ykcnK0zpbBLcjk/1LUhcU/gzE= github.com/aws/aws-sdk-go-v2/service/mediapackage v1.28.7 h1:vdaaK74RcQKM7Db8GAEqM+J76AR9mhJztLPb+6wYpfQ= From f23e5b78036d1e1727a42f6358132afc70c58be0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 10:39:50 -0500 Subject: [PATCH 14/18] r/aws_media_convert_queue: Migrate to AWS SDK for Go v2. --- internal/service/mediaconvert/exports_test.go | 11 ++ internal/service/mediaconvert/queue.go | 144 +++++++++++------- .../mediaconvert/service_package_gen.go | 6 +- internal/service/mediaconvert/structure.go | 41 ----- 4 files changed, 100 insertions(+), 102 deletions(-) create mode 100644 internal/service/mediaconvert/exports_test.go delete mode 100644 internal/service/mediaconvert/structure.go diff --git a/internal/service/mediaconvert/exports_test.go b/internal/service/mediaconvert/exports_test.go new file mode 100644 index 00000000000..527989e71f2 --- /dev/null +++ b/internal/service/mediaconvert/exports_test.go @@ -0,0 +1,11 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mediaconvert + +// Exports for use in tests only. +var ( + ResourceQueue = resourceQueue + + FindQueueByName = findQueueByName +) diff --git a/internal/service/mediaconvert/queue.go b/internal/service/mediaconvert/queue.go index a7a0d71ee17..af26803ffeb 100644 --- a/internal/service/mediaconvert/queue.go +++ b/internal/service/mediaconvert/queue.go @@ -7,14 +7,15 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mediaconvert" - "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/mediaconvert" + "github.com/aws/aws-sdk-go-v2/service/mediaconvert/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "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" @@ -23,8 +24,8 @@ import ( ) // @SDKResource("aws_media_convert_queue", name="Queue") -// @Tags -func ResourceQueue() *schema.Resource { +// @Tags(identifierAttribute="arn") +func resourceQueue() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceQueueCreate, ReadWithoutTimeout: resourceQueueRead, @@ -40,21 +41,21 @@ func ResourceQueue() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "description": { + Type: schema.TypeString, + Optional: true, + }, "name": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "description": { - Type: schema.TypeString, - Optional: true, - }, "pricing_plan": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: mediaconvert.PricingPlanOnDemand, - ValidateFunc: validation.StringInSlice(mediaconvert.PricingPlan_Values(), false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: types.PricingPlanOnDemand, + ValidateDiagFunc: enum.Validate[types.PricingPlan](), }, "reservation_plan_settings": { Type: schema.TypeList, @@ -64,14 +65,14 @@ func ResourceQueue() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "commitment": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(mediaconvert.Commitment_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[types.Commitment](), }, "renewal_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(mediaconvert.RenewalType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[types.RenewalType](), }, "reserved_slots": { Type: schema.TypeInt, @@ -81,10 +82,10 @@ func ResourceQueue() *schema.Resource { }, }, "status": { - Type: schema.TypeString, - Optional: true, - Default: mediaconvert.QueueStatusActive, - ValidateFunc: validation.StringInSlice(mediaconvert.QueueStatus_Values(), false), + Type: schema.TypeString, + Optional: true, + Default: types.QueueStatusActive, + ValidateDiagFunc: enum.Validate[types.QueueStatus](), }, names.AttrTags: tftags.TagsSchema(), names.AttrTagsAll: tftags.TagsSchemaComputed(), @@ -96,13 +97,13 @@ func ResourceQueue() *schema.Resource { func resourceQueueCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) + conn := meta.(*conns.AWSClient).MediaConvertClient(ctx) name := d.Get("name").(string) input := &mediaconvert.CreateQueueInput{ Name: aws.String(name), - PricingPlan: aws.String(d.Get("pricing_plan").(string)), - Status: aws.String(d.Get("status").(string)), + PricingPlan: types.PricingPlan(d.Get("pricing_plan").(string)), + Status: types.QueueStatus(d.Get("status").(string)), Tags: getTagsIn(ctx), } @@ -114,22 +115,22 @@ func resourceQueueCreate(ctx context.Context, d *schema.ResourceData, meta inter input.ReservationPlanSettings = expandReservationPlanSettings(v[0].(map[string]interface{})) } - output, err := conn.CreateQueueWithContext(ctx, input) + output, err := conn.CreateQueue(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating Media Convert Queue (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Queue.Name)) + d.SetId(aws.ToString(output.Queue.Name)) return append(diags, resourceQueueRead(ctx, d, meta)...) } func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) + conn := meta.(*conns.AWSClient).MediaConvertClient(ctx) - queue, err := FindQueueByName(ctx, conn, d.Id()) + queue, err := findQueueByName(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Media Convert Queue (%s) not found, removing from state", d.Id()) @@ -145,30 +146,26 @@ func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interfa d.Set("description", queue.Description) d.Set("name", queue.Name) d.Set("pricing_plan", queue.PricingPlan) - if err := d.Set("reservation_plan_settings", flattenReservationPlan(queue.ReservationPlan)); err != nil { - return sdkdiag.AppendErrorf(diags, "setting reservation_plan_settings: %s", err) + if queue.ReservationPlan != nil { + if err := d.Set("reservation_plan_settings", []interface{}{flattenReservationPlan(queue.ReservationPlan)}); err != nil { + return sdkdiag.AppendErrorf(diags, "setting reservation_plan_settings: %s", err) + } + } else { + d.Set("reservation_plan_settings", nil) } d.Set("status", queue.Status) - tags, err := listTags(ctx, conn, aws.StringValue(queue.Arn)) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Media Convert Queue (%s): %s", d.Id(), err) - } - - setTagsOut(ctx, Tags(tags)) - return diags } func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) + conn := meta.(*conns.AWSClient).MediaConvertClient(ctx) - if d.HasChanges("description", "reservation_plan_settings", "status") { + if d.HasChangesExcept("tags", "tags_all") { input := &mediaconvert.UpdateQueueInput{ Name: aws.String(d.Id()), - Status: aws.String(d.Get("status").(string)), + Status: types.QueueStatus(d.Get("status").(string)), } if v, ok := d.GetOk("description"); ok { @@ -179,33 +176,26 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter input.ReservationPlanSettings = expandReservationPlanSettings(v[0].(map[string]interface{})) } - _, err := conn.UpdateQueueWithContext(ctx, input) + _, err := conn.UpdateQueue(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating Media Convert Queue (%s): %s", d.Id(), err) } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - if err := updateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceQueueRead(ctx, d, meta)...) } func resourceQueueDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) + conn := meta.(*conns.AWSClient).MediaConvertClient(ctx) log.Printf("[DEBUG] Deleting Media Convert Queue: %s", d.Id()) - _, err := conn.DeleteQueueWithContext(ctx, &mediaconvert.DeleteQueueInput{ + _, err := conn.DeleteQueue(ctx, &mediaconvert.DeleteQueueInput{ Name: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, mediaconvert.ErrCodeNotFoundException) { + if errs.IsA[*types.NotFoundException](err) { return diags } @@ -216,14 +206,14 @@ func resourceQueueDelete(ctx context.Context, d *schema.ResourceData, meta inter return diags } -func FindQueueByName(ctx context.Context, conn *mediaconvert.MediaConvert, name string) (*mediaconvert.Queue, error) { +func findQueueByName(ctx context.Context, conn *mediaconvert.Client, name string) (*types.Queue, error) { input := &mediaconvert.GetQueueInput{ Name: aws.String(name), } - output, err := conn.GetQueueWithContext(ctx, input) + output, err := conn.GetQueue(ctx, input) - if tfawserr.ErrCodeEquals(err, mediaconvert.ErrCodeNotFoundException) { + if errs.IsA[*types.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -240,3 +230,39 @@ func FindQueueByName(ctx context.Context, conn *mediaconvert.MediaConvert, name return output.Queue, nil } + +func expandReservationPlanSettings(tfMap map[string]interface{}) *types.ReservationPlanSettings { + if tfMap == nil { + return nil + } + + apiObject := &types.ReservationPlanSettings{} + + if v, ok := tfMap["commitment"]; ok { + apiObject.Commitment = types.Commitment(v.(string)) + } + + if v, ok := tfMap["renewal_type"]; ok { + apiObject.RenewalType = types.RenewalType(v.(string)) + } + + if v, ok := tfMap["reserved_slots"]; ok { + apiObject.ReservedSlots = aws.Int32(int32(v.(int))) + } + + return apiObject +} + +func flattenReservationPlan(apiObject *types.ReservationPlan) map[string]interface{} { + if apiObject == nil { + return nil + } + + tfMap := map[string]interface{}{ + "commitment": apiObject.Commitment, + "renewal_type": apiObject.RenewalType, + "reserved_slots": aws.ToInt32(apiObject.ReservedSlots), + } + + return tfMap +} diff --git a/internal/service/mediaconvert/service_package_gen.go b/internal/service/mediaconvert/service_package_gen.go index 7a40a73bfe7..e20e82566b8 100644 --- a/internal/service/mediaconvert/service_package_gen.go +++ b/internal/service/mediaconvert/service_package_gen.go @@ -35,10 +35,12 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { return []*types.ServicePackageSDKResource{ { - Factory: ResourceQueue, + Factory: resourceQueue, TypeName: "aws_media_convert_queue", Name: "Queue", - Tags: &types.ServicePackageResourceTags{}, + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, } } diff --git a/internal/service/mediaconvert/structure.go b/internal/service/mediaconvert/structure.go deleted file mode 100644 index e9a9c18eb04..00000000000 --- a/internal/service/mediaconvert/structure.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package mediaconvert - -import ( - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mediaconvert" -) - -func expandReservationPlanSettings(config map[string]interface{}) *mediaconvert.ReservationPlanSettings { - reservationPlanSettings := &mediaconvert.ReservationPlanSettings{} - - if v, ok := config["commitment"]; ok { - reservationPlanSettings.Commitment = aws.String(v.(string)) - } - - if v, ok := config["renewal_type"]; ok { - reservationPlanSettings.RenewalType = aws.String(v.(string)) - } - - if v, ok := config["reserved_slots"]; ok { - reservationPlanSettings.ReservedSlots = aws.Int64(int64(v.(int))) - } - - return reservationPlanSettings -} - -func flattenReservationPlan(reservationPlan *mediaconvert.ReservationPlan) []interface{} { - if reservationPlan == nil { - return []interface{}{} - } - - m := map[string]interface{}{ - "commitment": aws.StringValue(reservationPlan.Commitment), - "renewal_type": aws.StringValue(reservationPlan.RenewalType), - "reserved_slots": aws.Int64Value(reservationPlan.ReservedSlots), - } - - return []interface{}{m} -} From 7c6e2c00cd616cacb2e6d0244214e4a115dcb3a5 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 10:42:01 -0500 Subject: [PATCH 15/18] d/aws_media_convert_queue: Migrate to AWS SDK for Go v2. --- .../service/mediaconvert/queue_data_source.go | 24 ++++++------------- .../mediaconvert/service_package_gen.go | 5 +++- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/internal/service/mediaconvert/queue_data_source.go b/internal/service/mediaconvert/queue_data_source.go index 6835bc1497b..93add4ca4b0 100644 --- a/internal/service/mediaconvert/queue_data_source.go +++ b/internal/service/mediaconvert/queue_data_source.go @@ -6,7 +6,7 @@ package mediaconvert 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" @@ -15,7 +15,8 @@ import ( ) // @SDKDataSource("aws_media_convert_queue", name="Queue") -func DataSourceQueue() *schema.Resource { +// @Tags(identifierAttribute="arn") +func dataSourceQueue() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceQueueRead, @@ -43,31 +44,20 @@ func DataSourceQueue() *schema.Resource { func dataSourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MediaConvertConn(ctx) + conn := meta.(*conns.AWSClient).MediaConvertClient(ctx) id := d.Get("id").(string) - queue, err := FindQueueByName(ctx, conn, id) + queue, err := findQueueByName(ctx, conn, id) if err != nil { return sdkdiag.AppendErrorf(diags, "reading Media Convert Queue (%s): %s", id, err) } - arn, name := aws.StringValue(queue.Arn), aws.StringValue(queue.Name) + name := aws.ToString(queue.Name) d.SetId(name) - d.Set("arn", arn) + d.Set("arn", queue.Arn) d.Set("name", name) d.Set("status", queue.Status) - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig - tags, err := listTags(ctx, conn, arn) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Media Convert Queue (%s): %s", arn, err) - } - - if err := d.Set("tags", tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - return diags } diff --git a/internal/service/mediaconvert/service_package_gen.go b/internal/service/mediaconvert/service_package_gen.go index e20e82566b8..64e4eb37d00 100644 --- a/internal/service/mediaconvert/service_package_gen.go +++ b/internal/service/mediaconvert/service_package_gen.go @@ -25,9 +25,12 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { return []*types.ServicePackageSDKDataSource{ { - Factory: DataSourceQueue, + Factory: dataSourceQueue, TypeName: "aws_media_convert_queue", Name: "Queue", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, } } From 4c15e0819caec9f3c0e92d7ca52193b8efe92a87 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 10:48:06 -0500 Subject: [PATCH 16/18] mediaconvert: Migrate acceptance tests to AWS SDK for Go v2. --- .../mediaconvert/queue_data_source_test.go | 4 +- internal/service/mediaconvert/queue_test.go | 64 ++++++++++--------- names/names.go | 1 + 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/internal/service/mediaconvert/queue_data_source_test.go b/internal/service/mediaconvert/queue_data_source_test.go index 90d63a283e9..7e7bb127454 100644 --- a/internal/service/mediaconvert/queue_data_source_test.go +++ b/internal/service/mediaconvert/queue_data_source_test.go @@ -6,10 +6,10 @@ package mediaconvert_test import ( "testing" - "github.com/aws/aws-sdk-go/service/mediaconvert" sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccMediaConvertQueueDataSource_basic(t *testing.T) { @@ -20,7 +20,7 @@ func TestAccMediaConvertQueueDataSource_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MediaConvertEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/service/mediaconvert/queue_test.go b/internal/service/mediaconvert/queue_test.go index 278eab1b49e..2a68019a54e 100644 --- a/internal/service/mediaconvert/queue_test.go +++ b/internal/service/mediaconvert/queue_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/mediaconvert" + "github.com/aws/aws-sdk-go-v2/service/mediaconvert/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -17,17 +17,18 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfmediaconvert "github.com/hashicorp/terraform-provider-aws/internal/service/mediaconvert" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccMediaConvertQueue_basic(t *testing.T) { ctx := acctest.Context(t) - var queue mediaconvert.Queue + var queue types.Queue resourceName := "aws_media_convert_queue.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MediaConvertEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ @@ -37,8 +38,9 @@ func TestAccMediaConvertQueue_basic(t *testing.T) { testAccCheckQueueExists(ctx, resourceName, &queue), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "mediaconvert", regexache.MustCompile(`queues/.+`)), resource.TestCheckResourceAttr(resourceName, "name", rName), - resource.TestCheckResourceAttr(resourceName, "pricing_plan", mediaconvert.PricingPlanOnDemand), - resource.TestCheckResourceAttr(resourceName, "status", mediaconvert.QueueStatusActive), + resource.TestCheckResourceAttr(resourceName, "pricing_plan", string(types.PricingPlanOnDemand)), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.#", "0"), + resource.TestCheckResourceAttr(resourceName, "status", string(types.QueueStatusActive)), ), }, { @@ -52,13 +54,13 @@ func TestAccMediaConvertQueue_basic(t *testing.T) { func TestAccMediaConvertQueue_disappears(t *testing.T) { ctx := acctest.Context(t) - var queue mediaconvert.Queue + var queue types.Queue resourceName := "aws_media_convert_queue.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MediaConvertEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ @@ -76,13 +78,13 @@ func TestAccMediaConvertQueue_disappears(t *testing.T) { func TestAccMediaConvertQueue_withTags(t *testing.T) { ctx := acctest.Context(t) - var queue mediaconvert.Queue + var queue types.Queue resourceName := "aws_media_convert_queue.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MediaConvertEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ @@ -124,35 +126,35 @@ func TestAccMediaConvertQueue_reservationPlanSettings(t *testing.T) { acctest.Skip(t, "MediaConvert Reserved Queues are $400/month and cannot be deleted for 1 year.") ctx := acctest.Context(t) - var queue mediaconvert.Queue + var queue types.Queue resourceName := "aws_media_convert_queue.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MediaConvertEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccQueueConfig_reserved(rName, mediaconvert.CommitmentOneYear, mediaconvert.RenewalTypeAutoRenew, 1), + Config: testAccQueueConfig_reserved(rName, string(types.CommitmentOneYear), string(types.RenewalTypeAutoRenew), 1), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "pricing_plan", mediaconvert.PricingPlanReserved), + resource.TestCheckResourceAttr(resourceName, "pricing_plan", string(types.PricingPlanReserved)), resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.commitment", mediaconvert.CommitmentOneYear), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.renewal_type", mediaconvert.RenewalTypeAutoRenew), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.commitment", string(types.CommitmentOneYear)), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.renewal_type", string(types.RenewalTypeAutoRenew)), resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.reserved_slots", "1"), ), }, { - Config: testAccQueueConfig_reserved(rName, mediaconvert.CommitmentOneYear, mediaconvert.RenewalTypeExpire, 2), + Config: testAccQueueConfig_reserved(rName, string(types.CommitmentOneYear), string(types.RenewalTypeExpire), 2), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "pricing_plan", mediaconvert.PricingPlanReserved), + resource.TestCheckResourceAttr(resourceName, "pricing_plan", string(types.PricingPlanReserved)), resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.commitment", mediaconvert.CommitmentOneYear), - resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.renewal_type", mediaconvert.RenewalTypeExpire), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.commitment", string(types.CommitmentOneYear)), + resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.renewal_type", string(types.RenewalTypeExpire)), resource.TestCheckResourceAttr(resourceName, "reservation_plan_settings.0.reserved_slots", "1"), ), }, @@ -167,28 +169,28 @@ func TestAccMediaConvertQueue_reservationPlanSettings(t *testing.T) { func TestAccMediaConvertQueue_withStatus(t *testing.T) { ctx := acctest.Context(t) - var queue mediaconvert.Queue + var queue types.Queue resourceName := "aws_media_convert_queue.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MediaConvertEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccQueueConfig_status(rName, mediaconvert.QueueStatusPaused), + Config: testAccQueueConfig_status(rName, string(types.QueueStatusPaused)), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "status", mediaconvert.QueueStatusPaused), + resource.TestCheckResourceAttr(resourceName, "status", string(types.QueueStatusPaused)), ), }, { - Config: testAccQueueConfig_status(rName, mediaconvert.QueueStatusActive), + Config: testAccQueueConfig_status(rName, string(types.QueueStatusActive)), Check: resource.ComposeTestCheckFunc( testAccCheckQueueExists(ctx, resourceName, &queue), - resource.TestCheckResourceAttr(resourceName, "status", mediaconvert.QueueStatusActive), + resource.TestCheckResourceAttr(resourceName, "status", string(types.QueueStatusActive)), ), }, { @@ -202,7 +204,7 @@ func TestAccMediaConvertQueue_withStatus(t *testing.T) { func TestAccMediaConvertQueue_withDescription(t *testing.T) { ctx := acctest.Context(t) - var queue mediaconvert.Queue + var queue types.Queue resourceName := "aws_media_convert_queue.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) description1 := sdkacctest.RandomWithPrefix("Description: ") @@ -210,7 +212,7 @@ func TestAccMediaConvertQueue_withDescription(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mediaconvert.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MediaConvertEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckQueueDestroy(ctx), Steps: []resource.TestStep{ @@ -239,7 +241,7 @@ func testAccCheckQueueDestroy(ctx context.Context) resource.TestCheckFunc { continue } - conn := acctest.Provider.Meta().(*conns.AWSClient).MediaConvertConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MediaConvertClient(ctx) _, err := tfmediaconvert.FindQueueByName(ctx, conn, rs.Primary.ID) @@ -258,14 +260,14 @@ func testAccCheckQueueDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckQueueExists(ctx context.Context, n string, v *mediaconvert.Queue) resource.TestCheckFunc { +func testAccCheckQueueExists(ctx context.Context, n string, v *types.Queue) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).MediaConvertConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MediaConvertClient(ctx) output, err := tfmediaconvert.FindQueueByName(ctx, conn, rs.Primary.ID) @@ -342,5 +344,5 @@ resource "aws_media_convert_queue" "test" { reserved_slots = %[5]d } } -`, rName, mediaconvert.PricingPlanReserved, commitment, renewalType, reservedSlots) +`, rName, string(types.PricingPlanReserved), commitment, renewalType, reservedSlots) } diff --git a/names/names.go b/names/names.go index d99a17407e8..c204f8aea59 100644 --- a/names/names.go +++ b/names/names.go @@ -71,6 +71,7 @@ const ( KinesisEndpointID = "kinesis" LambdaEndpointID = "lambda" LexV2ModelsEndpointID = "models-v2-lex" + MediaConvertEndpointID = "mediaconvert" MediaLiveEndpointID = "medialive" MQEndpointID = "mq" ObservabilityAccessManagerEndpointID = "oam" From d592cb8535eaaccae33c47583037c903bb382433 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 10:54:59 -0500 Subject: [PATCH 17/18] Add CHANGELOG entries. --- .changelog/#####.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/#####.txt diff --git a/.changelog/#####.txt b/.changelog/#####.txt new file mode 100644 index 00000000000..4a076d9182a --- /dev/null +++ b/.changelog/#####.txt @@ -0,0 +1,7 @@ +```release-note:note +resource/aws_media_convert_queue: The AWS Elemental MediaConvert service has been converted to use standard [Regional endpoints](https://docs.aws.amazon.com/general/latest/gr/mediaconvert.html#mediaconvert_region) instead of deprecated per-account endpoints +``` + +```release-note:note +data-source/aws_media_convert_queue: The AWS Elemental MediaConvert service has been converted to use standard [Regional endpoints](https://docs.aws.amazon.com/general/latest/gr/mediaconvert.html#mediaconvert_region) instead of deprecated per-account endpoints +``` \ No newline at end of file From 135bd4765fe233e19f21960bc6b35ebc27ffd9e1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Feb 2024 11:07:24 -0500 Subject: [PATCH 18/18] Correct CHANGELOG entry file name. --- .changelog/{#####.txt => 35615.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{#####.txt => 35615.txt} (100%) diff --git a/.changelog/#####.txt b/.changelog/35615.txt similarity index 100% rename from .changelog/#####.txt rename to .changelog/35615.txt