From 783c4c439d4aeac7621c64949368f73e3d224ed0 Mon Sep 17 00:00:00 2001 From: Matthew Hands Date: Thu, 18 Jul 2024 07:38:11 +0100 Subject: [PATCH 01/10] add aws_media_packagev2_channel_group resource --- .../service/mediapackagev2/channel_group.go | 202 +++++++++++++ .../mediapackagev2/channel_group_test.go | 268 ++++++++++++++++++ .../service/mediapackagev2/exports_test.go | 10 + internal/service/mediapackagev2/generate.go | 1 + .../mediapackagev2/mediapackagev2_test.go | 27 ++ .../mediapackagev2/service_package_gen.go | 11 +- internal/service/mediapackagev2/tags_gen.go | 128 +++++++++ ...edia_packagev2_channel_group.html.markdown | 55 ++++ 8 files changed, 701 insertions(+), 1 deletion(-) create mode 100644 internal/service/mediapackagev2/channel_group.go create mode 100644 internal/service/mediapackagev2/channel_group_test.go create mode 100644 internal/service/mediapackagev2/exports_test.go create mode 100644 internal/service/mediapackagev2/mediapackagev2_test.go create mode 100644 internal/service/mediapackagev2/tags_gen.go create mode 100644 website/docs/r/media_packagev2_channel_group.html.markdown diff --git a/internal/service/mediapackagev2/channel_group.go b/internal/service/mediapackagev2/channel_group.go new file mode 100644 index 00000000000..68c172c9fa4 --- /dev/null +++ b/internal/service/mediapackagev2/channel_group.go @@ -0,0 +1,202 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mediapackagev2 + +import ( + "context" + "errors" + "fmt" + "log" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" + awstypes "github.com/aws/aws-sdk-go-v2/service/mediapackagev2/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-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" +) + +// @SDKResource("aws_media_packagev2_channel_group", name="Channel Group") +// @Tags(identifierAttribute="arn") +func resourceChannelGroup() *schema.Resource { + return &schema.Resource{ + CreateWithoutTimeout: resourceChannelGroupCreate, + ReadWithoutTimeout: resourceChannelGroupRead, + UpdateWithoutTimeout: resourceChannelGroupUpdate, + DeleteWithoutTimeout: resourceChannelGroupDelete, + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + Schema: map[string]*schema.Schema{ + names.AttrARN: { + Type: schema.TypeString, + Computed: true, + }, + "channel_group_name": { + Type: schema.TypeString, + Required: true, + }, + names.AttrDescription: { + Type: schema.TypeString, + Optional: true, + Default: "Managed by Terraform", + }, + "egress_domain": { + Type: schema.TypeString, + Computed: true, + }, + names.AttrKey: { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), + }, + CustomizeDiff: verify.SetTagsDiff, + } +} + +func resourceChannelGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) + + channelGroupName := d.Get("channel_group_name").(string) + input := &mediapackagev2.CreateChannelGroupInput{ + ChannelGroupName: aws.String(channelGroupName), + Tags: getTagsIn(ctx), + } + + if v, ok := d.GetOk("description"); ok { + input.Description = aws.String(v.(string)) + } + + output, err := conn.CreateChannelGroup(ctx, input) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating MediaPackageV2 Channel Group: %s", err) + } + + d.SetId(aws.ToString(output.ChannelGroupName)) + + return append(diags, resourceChannelGroupRead(ctx, d, meta)...) +} + +func resourceChannelGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) + + resp, err := findChannelGroupByID(ctx, conn, d.Id()) + + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] MediaPackageV2 Channel Group: %s not found, removing from state", d.Id()) + d.SetId("") + return diags + } + + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading MediaPackageV2 Channel Group: %s, %s", d.Id(), err) + } + + d.Set(names.AttrARN, resp.Arn) + d.Set("channel_group_name", resp.ChannelGroupName) + d.Set(names.AttrDescription, resp.Description) + d.Set("egress_domain", resp.EgressDomain) + + setTagsOut(ctx, resp.Tags) + + return diags +} + +func resourceChannelGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) + + input := &mediapackagev2.UpdateChannelGroupInput{ + ChannelGroupName: aws.String(d.Id()), + Description: aws.String(d.Get(names.AttrDescription).(string)), + } + + var _, err = conn.UpdateChannelGroup(ctx, input) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "updating MediaPackageV2 Channel Group: %s, %s", d.Id(), err) + } + + return append(diags, resourceChannelGroupRead(ctx, d, meta)...) +} + +func resourceChannelGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) + + DeleteChannelGroup := &mediapackagev2.DeleteChannelGroupInput{ + ChannelGroupName: aws.String(d.Id()), + } + _, err := conn.DeleteChannelGroup(ctx, DeleteChannelGroup) + if err != nil { + var nfe *awstypes.ResourceNotFoundException + if errors.As(err, &nfe) { + return diags + } + return sdkdiag.AppendErrorf(diags, "deleting MediaPackageV2 Channel Group: %s", err) + } + + channelGroupInput := &mediapackagev2.GetChannelGroupInput{ + ChannelGroupName: aws.String(d.Id()), + } + err = retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError { + _, err := conn.GetChannelGroup(ctx, channelGroupInput) + if err != nil { + var nfe *awstypes.ResourceNotFoundException + if errors.As(err, &nfe) { + return nil + } + return retry.NonRetryableError(err) + } + return retry.RetryableError(fmt.Errorf("MediaPackageV2 Channel Group: %s still exists", d.Id())) + }) + if tfresource.TimedOut(err) { + _, err = conn.GetChannelGroup(ctx, channelGroupInput) + } + if err != nil { + return sdkdiag.AppendErrorf(diags, "waiting for MediaPackage Channel: %s, deletion: %s", d.Id(), err) + } + + return diags +} + +func findChannelGroupByID(ctx context.Context, conn *mediapackagev2.Client, id string) (*mediapackagev2.GetChannelGroupOutput, error) { + in := &mediapackagev2.GetChannelGroupInput{ + ChannelGroupName: aws.String(id), + } + + out, err := conn.GetChannelGroup(ctx, in) + + if err != nil { + var nfe *awstypes.ResourceNotFoundException + if errors.As(err, &nfe) { + return nil, &retry.NotFoundError{ + LastRequest: in, + LastError: err, + } + } + + return nil, err + } + + if out == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + return out, nil +} diff --git a/internal/service/mediapackagev2/channel_group_test.go b/internal/service/mediapackagev2/channel_group_test.go new file mode 100644 index 00000000000..b0fc02b8598 --- /dev/null +++ b/internal/service/mediapackagev2/channel_group_test.go @@ -0,0 +1,268 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mediapackagev2_test + +import ( + "context" + "fmt" + "strings" + "testing" + + "github.com/YakDriver/regexache" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" + 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" + + tfmediapackagev2 "github.com/hashicorp/terraform-provider-aws/internal/service/mediapackagev2" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + + "github.com/hashicorp/terraform-provider-aws/names" +) + +func testAccMediaPackageChannelGroup_basic(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_media_packagev2_channel_group.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, strings.ToLower(mediapackagev2.ServiceID)) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(mediapackagev2.ServiceID)), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccChannelGroupConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckChannelExists(ctx, resourceName), + acctest.MatchResourceAttrRegionalARN(resourceName, names.AttrARN, "mediapackagev2", regexache.MustCompile(`channelGroup/.+`)), + resource.TestMatchResourceAttr(resourceName, names.AttrDescription, regexache.MustCompile("Managed by Terraform")), + resource.TestMatchResourceAttr(resourceName, "egress_domain", regexache.MustCompile(fmt.Sprintf("^[0-9a-z]+.egress.[0-9a-z]+.mediapackagev2.%s.amazonaws.com$", acctest.Region()))), + resource.TestMatchResourceAttr(resourceName, "tags.Foo", regexache.MustCompile("Bar")), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageChannelGroup_description(t *testing.T) { + ctx := acctest.Context(t) + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, strings.ToLower(mediapackagev2.ServiceID)) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(mediapackagev2.ServiceID)), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccChannelGroupConfig_description(rName, "description1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckChannelExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "description1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccChannelGroupConfig_description(rName, "description2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckChannelExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "description2"), + ), + }, + }, + }) +} + +func testAccMediaPackageChannelGroup_disappears(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_media_packagev2_channel_group.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, strings.ToLower(mediapackagev2.ServiceID)) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(mediapackagev2.ServiceID)), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccChannelGroupConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckChannelExists(ctx, resourceName), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tfmediapackagev2.ResourceChannelGroup(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testAccMediaPackageChannelGroup_tags(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_media_packagev2_channel_group.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, strings.ToLower(mediapackagev2.ServiceID)) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(mediapackagev2.ServiceID)), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccChannelGroupConfig_tags(rName, "Environment", "nonprod"), + Check: resource.ComposeTestCheckFunc( + testAccCheckChannelExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.Name", rName), + resource.TestCheckResourceAttr(resourceName, "tags.Environment", "nonprod"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccChannelGroupConfig_tags(rName, "Environment", "dev"), + Check: resource.ComposeTestCheckFunc( + testAccCheckChannelExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.Name", rName), + resource.TestCheckResourceAttr(resourceName, "tags.Environment", "dev"), + ), + }, + { + Config: testAccChannelGroupConfig_tags(rName, "Stage", "Prod"), + Check: resource.ComposeTestCheckFunc( + testAccCheckChannelExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.Name", rName), + resource.TestCheckResourceAttr(resourceName, "tags.Stage", "Prod"), + ), + }, + }, + }) +} + +func testAccCheckChannelGroupDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).MediaPackageV2Client(ctx) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_media_packagev2_channel_group" { + continue + } + + _, err := tfmediapackagev2.FindChannelGroupByID(ctx, conn, rs.Primary.ID) + if err == nil { + return fmt.Errorf("MediaPackageV2 Channel Group: %s not deleted", rs.Primary.ID) + } + + if tfresource.NotFound(err) { + continue + } + + if err != nil { + return err + } + } + + return nil + } +} + +func testAccCheckChannelExists(ctx context.Context, name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).MediaPackageV2Client(ctx) + + input := &mediapackagev2.GetChannelGroupInput{ + ChannelGroupName: aws.String(rs.Primary.ID), + } + + _, err := conn.GetChannelGroup(ctx, input) + + return err + } +} + +func testAccPreCheck(ctx context.Context, t *testing.T) { + conn := acctest.Provider.Meta().(*conns.AWSClient).MediaPackageV2Client(ctx) + + input := &mediapackagev2.ListChannelGroupsInput{} + + _, err := conn.ListChannelGroups(ctx, input) + + if acctest.PreCheckSkipError(err) { + t.Skipf("skipping acceptance testing: %s", err) + } + + if err != nil { + t.Fatalf("unexpected PreCheck error: %s", err) + } +} + +func testAccChannelGroupConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "aws_media_packagev2_channel_group" "test" { + channel_group_name = %[1]q + tags = { + Foo = "Bar" + } +} +`, rName) +} + +func testAccChannelGroupConfig_description(rName, description string) string { + return fmt.Sprintf(` +resource "aws_media_packagev2_channel_group" "test" { + channel_group_name = %[1]q + description = %[2]q +} +`, rName, description) +} + +func testAccChannelGroupConfig_tags(rName, key, value string) string { + return fmt.Sprintf(` +resource "aws_media_packagev2_channel_group" "test" { + channel_group_name = %[1]q + + tags = { + Name = %[1]q + + %[2]s = %[3]q + } +} +`, rName, key, value) +} diff --git a/internal/service/mediapackagev2/exports_test.go b/internal/service/mediapackagev2/exports_test.go new file mode 100644 index 00000000000..d9482c49355 --- /dev/null +++ b/internal/service/mediapackagev2/exports_test.go @@ -0,0 +1,10 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mediapackagev2 + +// Exports for use in tests only. +var ( + FindChannelGroupByID = findChannelGroupByID + ResourceChannelGroup = resourceChannelGroup +) diff --git a/internal/service/mediapackagev2/generate.go b/internal/service/mediapackagev2/generate.go index 2afe4d57361..e934271b39e 100644 --- a/internal/service/mediapackagev2/generate.go +++ b/internal/service/mediapackagev2/generate.go @@ -1,6 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -SkipTypesImp=true -KVTValues -ListTags -ServiceTagsMap -UpdateTags //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/mediapackagev2/mediapackagev2_test.go b/internal/service/mediapackagev2/mediapackagev2_test.go new file mode 100644 index 00000000000..03747bcf111 --- /dev/null +++ b/internal/service/mediapackagev2/mediapackagev2_test.go @@ -0,0 +1,27 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mediapackagev2_test + +import ( + "testing" + + "github.com/hashicorp/terraform-provider-aws/internal/acctest" +) + +// The Default AWS Quota for how many MediaPackage V2 Channel Groups you can have is 3 +// We'll serialize the tests to prevent hitting that quota +func TestAccMediaPackageV2_serial(t *testing.T) { + t.Parallel() + + testCases := map[string]map[string]func(t *testing.T){ + "MediaPackageChannelGroup": { + acctest.CtBasic: testAccMediaPackageChannelGroup_basic, + "description": testAccMediaPackageChannelGroup_description, + acctest.CtDisappears: testAccMediaPackageChannelGroup_disappears, + "tags": testAccMediaPackageChannelGroup_tags, + }, + } + + acctest.RunSerialTests2Levels(t, testCases, 0) +} diff --git a/internal/service/mediapackagev2/service_package_gen.go b/internal/service/mediapackagev2/service_package_gen.go index 1a5bf9e1f7a..ffa4b49652b 100644 --- a/internal/service/mediapackagev2/service_package_gen.go +++ b/internal/service/mediapackagev2/service_package_gen.go @@ -27,7 +27,16 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac } func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { - return []*types.ServicePackageSDKResource{} + return []*types.ServicePackageSDKResource{ + { + Factory: resourceChannelGroup, + TypeName: "aws_media_packagev2_channel_group", + Name: "Channel Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: names.AttrARN, + }, + }, + } } func (p *servicePackage) ServicePackageName() string { diff --git a/internal/service/mediapackagev2/tags_gen.go b/internal/service/mediapackagev2/tags_gen.go new file mode 100644 index 00000000000..3ce8bb8c3a9 --- /dev/null +++ b/internal/service/mediapackagev2/tags_gen.go @@ -0,0 +1,128 @@ +// Code generated by internal/generate/tags/main.go; DO NOT EDIT. +package mediapackagev2 + +import ( + "context" + "fmt" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/logging" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/types/option" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// listTags lists mediapackagev2 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 *mediapackagev2.Client, identifier string, optFns ...func(*mediapackagev2.Options)) (tftags.KeyValueTags, error) { + input := &mediapackagev2.ListTagsForResourceInput{ + ResourceArn: aws.String(identifier), + } + + output, err := conn.ListTagsForResource(ctx, input, optFns...) + + if err != nil { + return tftags.New(ctx, nil), err + } + + return KeyValueTags(ctx, output.Tags), nil +} + +// ListTags lists mediapackagev2 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).MediaPackageV2Client(ctx), identifier) + + if err != nil { + return err + } + + if inContext, ok := tftags.FromContext(ctx); ok { + inContext.TagsOut = option.Some(tags) + } + + return nil +} + +// map[string]string handling + +// Tags returns mediapackagev2 service tags. +func Tags(tags tftags.KeyValueTags) map[string]string { + return tags.Map() +} + +// KeyValueTags creates tftags.KeyValueTags from mediapackagev2 service tags. +func KeyValueTags(ctx context.Context, tags map[string]string) tftags.KeyValueTags { + return tftags.New(ctx, tags) +} + +// getTagsIn returns mediapackagev2 service tags from Context. +// nil is returned if there are no input tags. +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 + } + } + + return nil +} + +// setTagsOut sets mediapackagev2 service tags in Context. +func setTagsOut(ctx context.Context, tags map[string]string) { + if inContext, ok := tftags.FromContext(ctx); ok { + inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) + } +} + +// updateTags updates mediapackagev2 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 *mediapackagev2.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*mediapackagev2.Options)) error { + oldTags := tftags.New(ctx, oldTagsMap) + newTags := tftags.New(ctx, newTagsMap) + + ctx = tflog.SetField(ctx, logging.KeyResourceId, identifier) + + removedTags := oldTags.Removed(newTags) + removedTags = removedTags.IgnoreSystem(names.MediaPackageV2) + if len(removedTags) > 0 { + input := &mediapackagev2.UntagResourceInput{ + ResourceArn: aws.String(identifier), + TagKeys: removedTags.Keys(), + } + + _, err := conn.UntagResource(ctx, input, optFns...) + + if err != nil { + return fmt.Errorf("untagging resource (%s): %w", identifier, err) + } + } + + updatedTags := oldTags.Updated(newTags) + updatedTags = updatedTags.IgnoreSystem(names.MediaPackageV2) + if len(updatedTags) > 0 { + input := &mediapackagev2.TagResourceInput{ + ResourceArn: aws.String(identifier), + Tags: Tags(updatedTags), + } + + _, err := conn.TagResource(ctx, input, optFns...) + + if err != nil { + return fmt.Errorf("tagging resource (%s): %w", identifier, err) + } + } + + return nil +} + +// UpdateTags updates mediapackagev2 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).MediaPackageV2Client(ctx), identifier, oldTags, newTags) +} diff --git a/website/docs/r/media_packagev2_channel_group.html.markdown b/website/docs/r/media_packagev2_channel_group.html.markdown new file mode 100644 index 00000000000..1b5113965a8 --- /dev/null +++ b/website/docs/r/media_packagev2_channel_group.html.markdown @@ -0,0 +1,55 @@ +--- +subcategory: "Elemental MediaPackage Version 2" +layout: "aws" +page_title: "AWS: aws_media_packagev2_channel_group" +description: |- + Creates an AWS Elemental MediaPackage Version 2 Channel Group. +--- + +# Resource: aws_media_packagev2_channel_group + +Creates an AWS Elemental MediaPackage Version 2 Channel Group. + +## Example Usage + +```terraform +resource "aws_media_packagev2_channel_group" "animals" { + channel_group_name = "animal-channels" + description = "channel group for animal channels" +} +``` + +## Argument Reference + +This resource supports the following arguments: + +- `channel_group_name` - (Required) A unique identifier naming the channel group +- `description` - (Optional) A description of the channel group +- `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. + +## Attribute Reference + +This resource exports the following attributes in addition to the arguments above: + +- `id` - The same as `channel_group_name` +- `description` - The same as `description` +- `egress_domain` - The egress domain of the channel group +- `arn` - The ARN of the channel +- `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). + +## Import + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import an Elemental MediaPackage Version 2 Channel Group using the channel group's name. For example: + +```terraform +import { + to = aws_media_packagev2_channel_group.animals + id = "animal-channels" +} +``` + +Using `terraform import`, import Elemental MediaPackage Version 2 Channel Group using the channel group's name. For example: + +```console +% terraform import aws_media_packagev2_channel_group.animals animal-channels +``` From ee4ebacf0290e363ba18d5002fb75c7d2991dc82 Mon Sep 17 00:00:00 2001 From: Matthew Hands Date: Thu, 18 Jul 2024 08:07:27 +0100 Subject: [PATCH 02/10] release-note added to changelog --- .changelog/38404.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/38404.txt diff --git a/.changelog/38404.txt b/.changelog/38404.txt new file mode 100644 index 00000000000..688ff65cb98 --- /dev/null +++ b/.changelog/38404.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_media_packagev2_channel_group +``` \ No newline at end of file From 4c9565a3a893da246922bf1ec870cafa38db4fca Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Jan 2025 12:23:10 -0600 Subject: [PATCH 03/10] aws_media_packagev2_channel_group: convert to plugin framework --- .../service/mediapackagev2/channel_group.go | 368 ++++++++---------- .../mediapackagev2/channel_group_fw.go | 274 +++++++++++++ 2 files changed, 445 insertions(+), 197 deletions(-) create mode 100644 internal/service/mediapackagev2/channel_group_fw.go diff --git a/internal/service/mediapackagev2/channel_group.go b/internal/service/mediapackagev2/channel_group.go index 68c172c9fa4..4fa097f41a1 100644 --- a/internal/service/mediapackagev2/channel_group.go +++ b/internal/service/mediapackagev2/channel_group.go @@ -3,200 +3,174 @@ package mediapackagev2 -import ( - "context" - "errors" - "fmt" - "log" - "time" - - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" - awstypes "github.com/aws/aws-sdk-go-v2/service/mediapackagev2/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-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" -) - -// @SDKResource("aws_media_packagev2_channel_group", name="Channel Group") -// @Tags(identifierAttribute="arn") -func resourceChannelGroup() *schema.Resource { - return &schema.Resource{ - CreateWithoutTimeout: resourceChannelGroupCreate, - ReadWithoutTimeout: resourceChannelGroupRead, - UpdateWithoutTimeout: resourceChannelGroupUpdate, - DeleteWithoutTimeout: resourceChannelGroupDelete, - - Importer: &schema.ResourceImporter{ - StateContext: schema.ImportStatePassthroughContext, - }, - Schema: map[string]*schema.Schema{ - names.AttrARN: { - Type: schema.TypeString, - Computed: true, - }, - "channel_group_name": { - Type: schema.TypeString, - Required: true, - }, - names.AttrDescription: { - Type: schema.TypeString, - Optional: true, - Default: "Managed by Terraform", - }, - "egress_domain": { - Type: schema.TypeString, - Computed: true, - }, - names.AttrKey: { - Type: schema.TypeString, - Computed: true, - Sensitive: true, - }, - names.AttrTags: tftags.TagsSchema(), - names.AttrTagsAll: tftags.TagsSchemaComputed(), - }, - CustomizeDiff: verify.SetTagsDiff, - } -} - -func resourceChannelGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) - - channelGroupName := d.Get("channel_group_name").(string) - input := &mediapackagev2.CreateChannelGroupInput{ - ChannelGroupName: aws.String(channelGroupName), - Tags: getTagsIn(ctx), - } - - if v, ok := d.GetOk("description"); ok { - input.Description = aws.String(v.(string)) - } - - output, err := conn.CreateChannelGroup(ctx, input) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "creating MediaPackageV2 Channel Group: %s", err) - } - - d.SetId(aws.ToString(output.ChannelGroupName)) - - return append(diags, resourceChannelGroupRead(ctx, d, meta)...) -} - -func resourceChannelGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) - - resp, err := findChannelGroupByID(ctx, conn, d.Id()) - - if !d.IsNewResource() && tfresource.NotFound(err) { - log.Printf("[WARN] MediaPackageV2 Channel Group: %s not found, removing from state", d.Id()) - d.SetId("") - return diags - } - - if err != nil { - return sdkdiag.AppendErrorf(diags, "reading MediaPackageV2 Channel Group: %s, %s", d.Id(), err) - } - - d.Set(names.AttrARN, resp.Arn) - d.Set("channel_group_name", resp.ChannelGroupName) - d.Set(names.AttrDescription, resp.Description) - d.Set("egress_domain", resp.EgressDomain) - - setTagsOut(ctx, resp.Tags) - - return diags -} - -func resourceChannelGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) - - input := &mediapackagev2.UpdateChannelGroupInput{ - ChannelGroupName: aws.String(d.Id()), - Description: aws.String(d.Get(names.AttrDescription).(string)), - } - - var _, err = conn.UpdateChannelGroup(ctx, input) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "updating MediaPackageV2 Channel Group: %s, %s", d.Id(), err) - } - - return append(diags, resourceChannelGroupRead(ctx, d, meta)...) -} - -func resourceChannelGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) - - DeleteChannelGroup := &mediapackagev2.DeleteChannelGroupInput{ - ChannelGroupName: aws.String(d.Id()), - } - _, err := conn.DeleteChannelGroup(ctx, DeleteChannelGroup) - if err != nil { - var nfe *awstypes.ResourceNotFoundException - if errors.As(err, &nfe) { - return diags - } - return sdkdiag.AppendErrorf(diags, "deleting MediaPackageV2 Channel Group: %s", err) - } - - channelGroupInput := &mediapackagev2.GetChannelGroupInput{ - ChannelGroupName: aws.String(d.Id()), - } - err = retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError { - _, err := conn.GetChannelGroup(ctx, channelGroupInput) - if err != nil { - var nfe *awstypes.ResourceNotFoundException - if errors.As(err, &nfe) { - return nil - } - return retry.NonRetryableError(err) - } - return retry.RetryableError(fmt.Errorf("MediaPackageV2 Channel Group: %s still exists", d.Id())) - }) - if tfresource.TimedOut(err) { - _, err = conn.GetChannelGroup(ctx, channelGroupInput) - } - if err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for MediaPackage Channel: %s, deletion: %s", d.Id(), err) - } - - return diags -} - -func findChannelGroupByID(ctx context.Context, conn *mediapackagev2.Client, id string) (*mediapackagev2.GetChannelGroupOutput, error) { - in := &mediapackagev2.GetChannelGroupInput{ - ChannelGroupName: aws.String(id), - } - - out, err := conn.GetChannelGroup(ctx, in) - - if err != nil { - var nfe *awstypes.ResourceNotFoundException - if errors.As(err, &nfe) { - return nil, &retry.NotFoundError{ - LastRequest: in, - LastError: err, - } - } - - return nil, err - } - - if out == nil { - return nil, tfresource.NewEmptyResultError(in) - } - - return out, nil -} +//import ( +// "context" +// "errors" +// "fmt" +// "log" +// "time" +// +// "github.com/aws/aws-sdk-go-v2/aws" +// "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" +// awstypes "github.com/aws/aws-sdk-go-v2/service/mediapackagev2/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-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" +//) +// +//// @SDKResource("aws_media_packagev2_channel_group", name="Channel Group") +//// @Tags(identifierAttribute="arn") +//func ResourceChannelGroup() *schema.Resource { +// return &schema.Resource{ +// CreateWithoutTimeout: resourceChannelGroupCreate, +// ReadWithoutTimeout: resourceChannelGroupRead, +// UpdateWithoutTimeout: resourceChannelGroupUpdate, +// DeleteWithoutTimeout: resourceChannelGroupDelete, +// +// Importer: &schema.ResourceImporter{ +// StateContext: schema.ImportStatePassthroughContext, +// }, +// Schema: map[string]*schema.Schema{ +// names.AttrARN: { +// Type: schema.TypeString, +// Computed: true, +// }, +// "channel_group_name": { +// Type: schema.TypeString, +// Required: true, +// }, +// names.AttrDescription: { +// Type: schema.TypeString, +// Optional: true, +// Default: "Managed by Terraform", +// }, +// "egress_domain": { +// Type: schema.TypeString, +// Computed: true, +// }, +// names.AttrKey: { +// Type: schema.TypeString, +// Computed: true, +// Sensitive: true, +// }, +// names.AttrTags: tftags.TagsSchema(), +// names.AttrTagsAll: tftags.TagsSchemaComputed(), +// }, +// CustomizeDiff: verify.SetTagsDiff, +// } +//} +// +//func resourceChannelGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +// var diags diag.Diagnostics +// conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) +// +// channelGroupName := d.Get("channel_group_name").(string) +// input := &mediapackagev2.CreateChannelGroupInput{ +// ChannelGroupName: aws.String(channelGroupName), +// Tags: getTagsIn(ctx), +// } +// +// if v, ok := d.GetOk("description"); ok { +// input.Description = aws.String(v.(string)) +// } +// +// output, err := conn.CreateChannelGroup(ctx, input) +// +// if err != nil { +// return sdkdiag.AppendErrorf(diags, "creating MediaPackageV2 Channel Group: %s", err) +// } +// +// d.SetId(aws.ToString(output.ChannelGroupName)) +// +// return append(diags, resourceChannelGroupRead(ctx, d, meta)...) +//} +// +//func resourceChannelGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +// var diags diag.Diagnostics +// conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) +// +// resp, err := findChannelGroupByID(ctx, conn, d.Id()) +// +// if !d.IsNewResource() && tfresource.NotFound(err) { +// log.Printf("[WARN] MediaPackageV2 Channel Group: %s not found, removing from state", d.Id()) +// d.SetId("") +// return diags +// } +// +// if err != nil { +// return sdkdiag.AppendErrorf(diags, "reading MediaPackageV2 Channel Group: %s, %s", d.Id(), err) +// } +// +// d.Set(names.AttrARN, resp.Arn) +// d.Set("channel_group_name", resp.ChannelGroupName) +// d.Set(names.AttrDescription, resp.Description) +// d.Set("egress_domain", resp.EgressDomain) +// +// setTagsOut(ctx, resp.Tags) +// +// return diags +//} +// +//func resourceChannelGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +// var diags diag.Diagnostics +// conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) +// +// input := &mediapackagev2.UpdateChannelGroupInput{ +// ChannelGroupName: aws.String(d.Id()), +// Description: aws.String(d.Get(names.AttrDescription).(string)), +// } +// +// var _, err = conn.UpdateChannelGroup(ctx, input) +// +// if err != nil { +// return sdkdiag.AppendErrorf(diags, "updating MediaPackageV2 Channel Group: %s, %s", d.Id(), err) +// } +// +// return append(diags, resourceChannelGroupRead(ctx, d, meta)...) +//} +// +//func resourceChannelGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +// var diags diag.Diagnostics +// conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) +// +// DeleteChannelGroup := &mediapackagev2.DeleteChannelGroupInput{ +// ChannelGroupName: aws.String(d.Id()), +// } +// _, err := conn.DeleteChannelGroup(ctx, DeleteChannelGroup) +// if err != nil { +// var nfe *awstypes.ResourceNotFoundException +// if errors.As(err, &nfe) { +// return diags +// } +// return sdkdiag.AppendErrorf(diags, "deleting MediaPackageV2 Channel Group: %s", err) +// } +// +// channelGroupInput := &mediapackagev2.GetChannelGroupInput{ +// ChannelGroupName: aws.String(d.Id()), +// } +// err = retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError { +// _, err := conn.GetChannelGroup(ctx, channelGroupInput) +// if err != nil { +// var nfe *awstypes.ResourceNotFoundException +// if errors.As(err, &nfe) { +// return nil +// } +// return retry.NonRetryableError(err) +// } +// return retry.RetryableError(fmt.Errorf("MediaPackageV2 Channel Group: %s still exists", d.Id())) +// }) +// if tfresource.TimedOut(err) { +// _, err = conn.GetChannelGroup(ctx, channelGroupInput) +// } +// if err != nil { +// return sdkdiag.AppendErrorf(diags, "waiting for MediaPackage Channel: %s, deletion: %s", d.Id(), err) +// } +// +// return diags +//} diff --git a/internal/service/mediapackagev2/channel_group_fw.go b/internal/service/mediapackagev2/channel_group_fw.go new file mode 100644 index 00000000000..04f2fb1933d --- /dev/null +++ b/internal/service/mediapackagev2/channel_group_fw.go @@ -0,0 +1,274 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mediapackagev2 + +import ( + "context" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" + awstypes "github.com/aws/aws-sdk-go-v2/service/mediapackagev2/types" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +const ( + ResNameChannelGroup = "Channel Group" + ChannelGroupFieldNamePrefix = "ChannelGroup" +) + +// @FrameworkResource("aws_media_packagev2_channel_group", name="Channel Group") +// @Tags(identifierAttribute="arn") +func newResourceChannelGroup(context.Context) (resource.ResourceWithConfigure, error) { + r := &resourceChannelGroup{} + + return r, nil +} + +type resourceChannelGroup struct { + framework.ResourceWithConfigure +} + +func (r *resourceChannelGroup) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { + response.TypeName = "aws_media_packagev2_channel_group" +} + +func (r *resourceChannelGroup) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { + s := schema.Schema{ + Attributes: map[string]schema.Attribute{ + names.AttrARN: framework.ARNAttributeComputedOnly(), + names.AttrName: schema.StringAttribute{ + Required: true, + }, + names.AttrDescription: schema.StringAttribute{ + Optional: true, + }, + "egress_domain": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + names.AttrTags: tftags.TagsAttribute(), + names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), + }, + } + + response.Schema = s +} + +func (r *resourceChannelGroup) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + conn := r.Meta().MediaPackageV2Client(ctx) + var data resourceChannelGroupData + + response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + input := mediapackagev2.CreateChannelGroupInput{ + Tags: getTagsIn(ctx), + } + response.Diagnostics.Append(fwflex.Expand(ctx, data, &input, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + + output, err := conn.CreateChannelGroup(ctx, &input) + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionCreating, ResNameChannelGroup, data.Name.String(), err), + err.Error(), + ) + return + } + + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + + response.Diagnostics.Append(response.State.Set(ctx, &data)...) +} + +func (r *resourceChannelGroup) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + conn := r.Meta().MediaPackageV2Client(ctx) + var data resourceChannelGroupData + + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + output, err := findChannelGroupByID(ctx, conn, data.Name.ValueString()) + + if tfresource.NotFound(err) { + response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) + response.State.RemoveResource(ctx) + return + } + + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionReading, ResNameChannelGroup, data.Name.String(), err), + err.Error(), + ) + return + } + + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + + setTagsOut(ctx, output.Tags) + + response.Diagnostics.Append(response.State.Set(ctx, &data)...) +} + +func (r *resourceChannelGroup) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { + conn := r.Meta().MediaPackageV2Client(ctx) + var state, plan resourceChannelGroupData + + response.Diagnostics.Append(request.State.Get(ctx, &state)...) + if response.Diagnostics.HasError() { + return + } + + response.Diagnostics.Append(request.Plan.Get(ctx, &plan)...) + if response.Diagnostics.HasError() { + return + } + + diff, d := fwflex.Calculate(ctx, plan, state) + response.Diagnostics.Append(d...) + if response.Diagnostics.HasError() { + return + } + + if diff.HasChanges() { + input := mediapackagev2.UpdateChannelGroupInput{} + response.Diagnostics.Append(fwflex.Expand(ctx, diff, &input, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + + output, err := conn.UpdateChannelGroup(ctx, &input) + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionUpdating, ResNameChannelGroup, state.Name.String(), err), + err.Error(), + ) + return + } + + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &plan, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + } + + response.Diagnostics.Append(response.State.Set(ctx, &plan)...) +} + +func (r *resourceChannelGroup) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { + conn := r.Meta().MediaPackageV2Client(ctx) + var data resourceChannelGroupData + + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + + if response.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, "deleting Channel Group", map[string]interface{}{ + names.AttrName: data.Name.ValueString(), + }) + + input := mediapackagev2.DeleteChannelGroupInput{ + ChannelGroupName: data.Name.ValueStringPointer(), + } + + _, err := conn.DeleteChannelGroup(ctx, &input) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return + } + + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionDeleting, ResNameChannelGroup, data.Name.String(), err), + err.Error(), + ) + return + } + + _, err = tfresource.RetryUntilNotFound(ctx, 5*time.Minute, func() (interface{}, error) { + return findChannelGroupByID(ctx, conn, data.Name.ValueString()) + }) + + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionWaitingForDeletion, ResNameChannelGroup, data.Name.String(), err), + err.Error(), + ) + } +} + +func (r *resourceChannelGroup) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root(names.AttrName), request, response) +} + +func (r *resourceChannelGroup) ModifyPlan(ctx context.Context, request resource.ModifyPlanRequest, response *resource.ModifyPlanResponse) { + r.SetTagsAll(ctx, request, response) +} + +type resourceChannelGroupData struct { + ARN types.String `tfsdk:"arn"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` + EgressDomain types.String `tfsdk:"egress_domain"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` +} + +func findChannelGroupByID(ctx context.Context, conn *mediapackagev2.Client, id string) (*mediapackagev2.GetChannelGroupOutput, error) { + in := &mediapackagev2.GetChannelGroupInput{ + ChannelGroupName: aws.String(id), + } + + out, err := conn.GetChannelGroup(ctx, in) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastRequest: in, + LastError: err, + } + } + + if err != nil { + return nil, err + } + + if out == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + return out, nil +} From 26c05b8d855d7be0cf07af8cca100d25b4acf2d9 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Jan 2025 12:28:25 -0600 Subject: [PATCH 04/10] make gen --- .../service/mediapackagev2/channel_group.go | 2 +- .../mediapackagev2/channel_group_test.go | 6 +++--- .../service/mediapackagev2/exports_test.go | 2 +- internal/service/mediapackagev2/generate.go | 2 +- .../mediapackagev2/service_package_gen.go | 21 +++++++++---------- internal/service/mediapackagev2/tags_gen.go | 12 +++++------ 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/internal/service/mediapackagev2/channel_group.go b/internal/service/mediapackagev2/channel_group.go index 4fa097f41a1..49b796496b0 100644 --- a/internal/service/mediapackagev2/channel_group.go +++ b/internal/service/mediapackagev2/channel_group.go @@ -24,7 +24,7 @@ package mediapackagev2 // "github.com/hashicorp/terraform-provider-aws/names" //) // -//// @SDKResource("aws_media_packagev2_channel_group", name="Channel Group") + //// @Tags(identifierAttribute="arn") //func ResourceChannelGroup() *schema.Resource { // return &schema.Resource{ diff --git a/internal/service/mediapackagev2/channel_group_test.go b/internal/service/mediapackagev2/channel_group_test.go index b0fc02b8598..4813b60749f 100644 --- a/internal/service/mediapackagev2/channel_group_test.go +++ b/internal/service/mediapackagev2/channel_group_test.go @@ -43,7 +43,7 @@ func testAccMediaPackageChannelGroup_basic(t *testing.T) { Config: testAccChannelGroupConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckChannelExists(ctx, resourceName), - acctest.MatchResourceAttrRegionalARN(resourceName, names.AttrARN, "mediapackagev2", regexache.MustCompile(`channelGroup/.+`)), + acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "mediapackagev2", regexache.MustCompile(`channelGroup/.+`)), resource.TestMatchResourceAttr(resourceName, names.AttrDescription, regexache.MustCompile("Managed by Terraform")), resource.TestMatchResourceAttr(resourceName, "egress_domain", regexache.MustCompile(fmt.Sprintf("^[0-9a-z]+.egress.[0-9a-z]+.mediapackagev2.%s.amazonaws.com$", acctest.Region()))), resource.TestMatchResourceAttr(resourceName, "tags.Foo", regexache.MustCompile("Bar")), @@ -115,7 +115,7 @@ func testAccMediaPackageChannelGroup_disappears(t *testing.T) { Config: testAccChannelGroupConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckChannelExists(ctx, resourceName), - acctest.CheckResourceDisappears(ctx, acctest.Provider, tfmediapackagev2.ResourceChannelGroup(), resourceName), + acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfmediapackagev2.ResourceChannelGroup, resourceName), ), ExpectNonEmptyPlan: true, }, @@ -180,7 +180,7 @@ func testAccCheckChannelGroupDestroy(ctx context.Context) resource.TestCheckFunc continue } - _, err := tfmediapackagev2.FindChannelGroupByID(ctx, conn, rs.Primary.ID) + _, err := tfmediapackagev2.FindChannelGroupByID(ctx, conn, rs.Primary.Attributes[names.AttrARN]) if err == nil { return fmt.Errorf("MediaPackageV2 Channel Group: %s not deleted", rs.Primary.ID) } diff --git a/internal/service/mediapackagev2/exports_test.go b/internal/service/mediapackagev2/exports_test.go index d9482c49355..91a06d4b5df 100644 --- a/internal/service/mediapackagev2/exports_test.go +++ b/internal/service/mediapackagev2/exports_test.go @@ -6,5 +6,5 @@ package mediapackagev2 // Exports for use in tests only. var ( FindChannelGroupByID = findChannelGroupByID - ResourceChannelGroup = resourceChannelGroup + ResourceChannelGroup = newResourceChannelGroup ) diff --git a/internal/service/mediapackagev2/generate.go b/internal/service/mediapackagev2/generate.go index e934271b39e..7c7be5850c9 100644 --- a/internal/service/mediapackagev2/generate.go +++ b/internal/service/mediapackagev2/generate.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -SkipTypesImp=true -KVTValues -ListTags -ServiceTagsMap -UpdateTags +//go:generate go run ../../generate/tags/main.go -KVTValues -ListTags -ServiceTagsMap -UpdateTags //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/mediapackagev2/service_package_gen.go b/internal/service/mediapackagev2/service_package_gen.go index fef7dcc935a..2202e92f75f 100644 --- a/internal/service/mediapackagev2/service_package_gen.go +++ b/internal/service/mediapackagev2/service_package_gen.go @@ -19,7 +19,15 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv } func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { - return []*types.ServicePackageFrameworkResource{} + return []*types.ServicePackageFrameworkResource{ + { + Factory: newResourceChannelGroup, + Name: "Channel Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: names.AttrARN, + }, + }, + } } func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { @@ -27,16 +35,7 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac } func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { - return []*types.ServicePackageSDKResource{ - { - Factory: resourceChannelGroup, - TypeName: "aws_media_packagev2_channel_group", - Name: "Channel Group", - Tags: &types.ServicePackageResourceTags{ - IdentifierAttribute: names.AttrARN, - }, - }, - } + return []*types.ServicePackageSDKResource{} } func (p *servicePackage) ServicePackageName() string { diff --git a/internal/service/mediapackagev2/tags_gen.go b/internal/service/mediapackagev2/tags_gen.go index 3ce8bb8c3a9..456315ef2df 100644 --- a/internal/service/mediapackagev2/tags_gen.go +++ b/internal/service/mediapackagev2/tags_gen.go @@ -19,11 +19,11 @@ import ( // 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 *mediapackagev2.Client, identifier string, optFns ...func(*mediapackagev2.Options)) (tftags.KeyValueTags, error) { - input := &mediapackagev2.ListTagsForResourceInput{ + input := mediapackagev2.ListTagsForResourceInput{ ResourceArn: aws.String(identifier), } - output, err := conn.ListTagsForResource(ctx, input, optFns...) + output, err := conn.ListTagsForResource(ctx, &input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -91,12 +91,12 @@ func updateTags(ctx context.Context, conn *mediapackagev2.Client, identifier str removedTags := oldTags.Removed(newTags) removedTags = removedTags.IgnoreSystem(names.MediaPackageV2) if len(removedTags) > 0 { - input := &mediapackagev2.UntagResourceInput{ + input := mediapackagev2.UntagResourceInput{ ResourceArn: aws.String(identifier), TagKeys: removedTags.Keys(), } - _, err := conn.UntagResource(ctx, input, optFns...) + _, err := conn.UntagResource(ctx, &input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -106,12 +106,12 @@ func updateTags(ctx context.Context, conn *mediapackagev2.Client, identifier str updatedTags := oldTags.Updated(newTags) updatedTags = updatedTags.IgnoreSystem(names.MediaPackageV2) if len(updatedTags) > 0 { - input := &mediapackagev2.TagResourceInput{ + input := mediapackagev2.TagResourceInput{ ResourceArn: aws.String(identifier), Tags: Tags(updatedTags), } - _, err := conn.TagResource(ctx, input, optFns...) + _, err := conn.TagResource(ctx, &input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) From c344a09257c0af3e1e7ce9af9f780e88f615546c Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Jan 2025 15:43:05 -0600 Subject: [PATCH 05/10] aws_media_packagev2_channel_group: cleanup test --- .../mediapackagev2/channel_group_fw.go | 2 +- .../mediapackagev2/channel_group_test.go | 112 ++++-------------- .../mediapackagev2/mediapackagev2_test.go | 2 +- 3 files changed, 23 insertions(+), 93 deletions(-) diff --git a/internal/service/mediapackagev2/channel_group_fw.go b/internal/service/mediapackagev2/channel_group_fw.go index 04f2fb1933d..aa96715106b 100644 --- a/internal/service/mediapackagev2/channel_group_fw.go +++ b/internal/service/mediapackagev2/channel_group_fw.go @@ -164,7 +164,7 @@ func (r *resourceChannelGroup) Update(ctx context.Context, request resource.Upda if diff.HasChanges() { input := mediapackagev2.UpdateChannelGroupInput{} - response.Diagnostics.Append(fwflex.Expand(ctx, diff, &input, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + response.Diagnostics.Append(fwflex.Expand(ctx, plan, &input, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) if response.Diagnostics.HasError() { return } diff --git a/internal/service/mediapackagev2/channel_group_test.go b/internal/service/mediapackagev2/channel_group_test.go index 4813b60749f..30dd92d09a0 100644 --- a/internal/service/mediapackagev2/channel_group_test.go +++ b/internal/service/mediapackagev2/channel_group_test.go @@ -6,21 +6,18 @@ package mediapackagev2_test import ( "context" "fmt" - "strings" "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" - + "github.com/hashicorp/terraform-provider-aws/internal/create" tfmediapackagev2 "github.com/hashicorp/terraform-provider-aws/internal/service/mediapackagev2" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" - "github.com/hashicorp/terraform-provider-aws/names" ) @@ -32,10 +29,9 @@ func testAccMediaPackageChannelGroup_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, strings.ToLower(mediapackagev2.ServiceID)) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(mediapackagev2.ServiceID)), + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckChannelGroupDestroy(ctx), Steps: []resource.TestStep{ @@ -44,15 +40,15 @@ func testAccMediaPackageChannelGroup_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckChannelExists(ctx, resourceName), acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "mediapackagev2", regexache.MustCompile(`channelGroup/.+`)), - resource.TestMatchResourceAttr(resourceName, names.AttrDescription, regexache.MustCompile("Managed by Terraform")), resource.TestMatchResourceAttr(resourceName, "egress_domain", regexache.MustCompile(fmt.Sprintf("^[0-9a-z]+.egress.[0-9a-z]+.mediapackagev2.%s.amazonaws.com$", acctest.Region()))), - resource.TestMatchResourceAttr(resourceName, "tags.Foo", regexache.MustCompile("Bar")), ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrName), + ImportStateVerifyIdentifierAttribute: names.AttrName, + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -66,10 +62,9 @@ func testAccMediaPackageChannelGroup_description(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, strings.ToLower(mediapackagev2.ServiceID)) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(mediapackagev2.ServiceID)), + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckChannelGroupDestroy(ctx), Steps: []resource.TestStep{ @@ -81,9 +76,11 @@ func testAccMediaPackageChannelGroup_description(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrName), + ImportStateVerifyIdentifierAttribute: names.AttrName, + ImportState: true, + ImportStateVerify: true, }, { Config: testAccChannelGroupConfig_description(rName, "description2"), @@ -104,10 +101,9 @@ func testAccMediaPackageChannelGroup_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, strings.ToLower(mediapackagev2.ServiceID)) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(mediapackagev2.ServiceID)), + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckChannelGroupDestroy(ctx), Steps: []resource.TestStep{ @@ -123,54 +119,6 @@ func testAccMediaPackageChannelGroup_disappears(t *testing.T) { }) } -func testAccMediaPackageChannelGroup_tags(t *testing.T) { - ctx := acctest.Context(t) - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_media_packagev2_channel_group.test" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, strings.ToLower(mediapackagev2.ServiceID)) - testAccPreCheck(ctx, t) - }, - ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(mediapackagev2.ServiceID)), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckChannelGroupDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccChannelGroupConfig_tags(rName, "Environment", "nonprod"), - Check: resource.ComposeTestCheckFunc( - testAccCheckChannelExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.Name", rName), - resource.TestCheckResourceAttr(resourceName, "tags.Environment", "nonprod"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccChannelGroupConfig_tags(rName, "Environment", "dev"), - Check: resource.ComposeTestCheckFunc( - testAccCheckChannelExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.Name", rName), - resource.TestCheckResourceAttr(resourceName, "tags.Environment", "dev"), - ), - }, - { - Config: testAccChannelGroupConfig_tags(rName, "Stage", "Prod"), - Check: resource.ComposeTestCheckFunc( - testAccCheckChannelExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.Name", rName), - resource.TestCheckResourceAttr(resourceName, "tags.Stage", "Prod"), - ), - }, - }, - }) -} - func testAccCheckChannelGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).MediaPackageV2Client(ctx) @@ -190,7 +138,7 @@ func testAccCheckChannelGroupDestroy(ctx context.Context) resource.TestCheckFunc } if err != nil { - return err + return create.Error(names.MediaPackageV2, create.ErrActionCheckingDestroyed, tfmediapackagev2.ResNameChannelGroup, rs.Primary.Attributes[names.AttrName], err) } } @@ -206,14 +154,13 @@ func testAccCheckChannelExists(ctx context.Context, name string) resource.TestCh } conn := acctest.Provider.Meta().(*conns.AWSClient).MediaPackageV2Client(ctx) + _, err := tfmediapackagev2.FindChannelGroupByID(ctx, conn, rs.Primary.Attributes[names.AttrName]) - input := &mediapackagev2.GetChannelGroupInput{ - ChannelGroupName: aws.String(rs.Primary.ID), + if err != nil { + return create.Error(names.MediaPackageV2, create.ErrActionCheckingExistence, tfmediapackagev2.ResNameChannelGroup, rs.Primary.Attributes[names.AttrName], err) } - _, err := conn.GetChannelGroup(ctx, input) - - return err + return nil } } @@ -236,10 +183,7 @@ func testAccPreCheck(ctx context.Context, t *testing.T) { func testAccChannelGroupConfig_basic(rName string) string { return fmt.Sprintf(` resource "aws_media_packagev2_channel_group" "test" { - channel_group_name = %[1]q - tags = { - Foo = "Bar" - } + name = %[1]q } `, rName) } @@ -247,22 +191,8 @@ resource "aws_media_packagev2_channel_group" "test" { func testAccChannelGroupConfig_description(rName, description string) string { return fmt.Sprintf(` resource "aws_media_packagev2_channel_group" "test" { - channel_group_name = %[1]q + name = %[1]q description = %[2]q } `, rName, description) } - -func testAccChannelGroupConfig_tags(rName, key, value string) string { - return fmt.Sprintf(` -resource "aws_media_packagev2_channel_group" "test" { - channel_group_name = %[1]q - - tags = { - Name = %[1]q - - %[2]s = %[3]q - } -} -`, rName, key, value) -} diff --git a/internal/service/mediapackagev2/mediapackagev2_test.go b/internal/service/mediapackagev2/mediapackagev2_test.go index 03747bcf111..34fd7e5ef60 100644 --- a/internal/service/mediapackagev2/mediapackagev2_test.go +++ b/internal/service/mediapackagev2/mediapackagev2_test.go @@ -19,7 +19,7 @@ func TestAccMediaPackageV2_serial(t *testing.T) { acctest.CtBasic: testAccMediaPackageChannelGroup_basic, "description": testAccMediaPackageChannelGroup_description, acctest.CtDisappears: testAccMediaPackageChannelGroup_disappears, - "tags": testAccMediaPackageChannelGroup_tags, + //"tags": testAccMediaPackageChannelGroup_tags, }, } From 741f936c6199c10b6a26598f06b5572dc8356383 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Jan 2025 15:43:40 -0600 Subject: [PATCH 06/10] rename files --- .../service/mediapackagev2/channel_group.go | 440 +++++++++++------- .../mediapackagev2/channel_group_fw.go | 274 ----------- 2 files changed, 269 insertions(+), 445 deletions(-) delete mode 100644 internal/service/mediapackagev2/channel_group_fw.go diff --git a/internal/service/mediapackagev2/channel_group.go b/internal/service/mediapackagev2/channel_group.go index 49b796496b0..aa96715106b 100644 --- a/internal/service/mediapackagev2/channel_group.go +++ b/internal/service/mediapackagev2/channel_group.go @@ -3,174 +3,272 @@ package mediapackagev2 -//import ( -// "context" -// "errors" -// "fmt" -// "log" -// "time" -// -// "github.com/aws/aws-sdk-go-v2/aws" -// "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" -// awstypes "github.com/aws/aws-sdk-go-v2/service/mediapackagev2/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-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" -//) -// - -//// @Tags(identifierAttribute="arn") -//func ResourceChannelGroup() *schema.Resource { -// return &schema.Resource{ -// CreateWithoutTimeout: resourceChannelGroupCreate, -// ReadWithoutTimeout: resourceChannelGroupRead, -// UpdateWithoutTimeout: resourceChannelGroupUpdate, -// DeleteWithoutTimeout: resourceChannelGroupDelete, -// -// Importer: &schema.ResourceImporter{ -// StateContext: schema.ImportStatePassthroughContext, -// }, -// Schema: map[string]*schema.Schema{ -// names.AttrARN: { -// Type: schema.TypeString, -// Computed: true, -// }, -// "channel_group_name": { -// Type: schema.TypeString, -// Required: true, -// }, -// names.AttrDescription: { -// Type: schema.TypeString, -// Optional: true, -// Default: "Managed by Terraform", -// }, -// "egress_domain": { -// Type: schema.TypeString, -// Computed: true, -// }, -// names.AttrKey: { -// Type: schema.TypeString, -// Computed: true, -// Sensitive: true, -// }, -// names.AttrTags: tftags.TagsSchema(), -// names.AttrTagsAll: tftags.TagsSchemaComputed(), -// }, -// CustomizeDiff: verify.SetTagsDiff, -// } -//} -// -//func resourceChannelGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { -// var diags diag.Diagnostics -// conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) -// -// channelGroupName := d.Get("channel_group_name").(string) -// input := &mediapackagev2.CreateChannelGroupInput{ -// ChannelGroupName: aws.String(channelGroupName), -// Tags: getTagsIn(ctx), -// } -// -// if v, ok := d.GetOk("description"); ok { -// input.Description = aws.String(v.(string)) -// } -// -// output, err := conn.CreateChannelGroup(ctx, input) -// -// if err != nil { -// return sdkdiag.AppendErrorf(diags, "creating MediaPackageV2 Channel Group: %s", err) -// } -// -// d.SetId(aws.ToString(output.ChannelGroupName)) -// -// return append(diags, resourceChannelGroupRead(ctx, d, meta)...) -//} -// -//func resourceChannelGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { -// var diags diag.Diagnostics -// conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) -// -// resp, err := findChannelGroupByID(ctx, conn, d.Id()) -// -// if !d.IsNewResource() && tfresource.NotFound(err) { -// log.Printf("[WARN] MediaPackageV2 Channel Group: %s not found, removing from state", d.Id()) -// d.SetId("") -// return diags -// } -// -// if err != nil { -// return sdkdiag.AppendErrorf(diags, "reading MediaPackageV2 Channel Group: %s, %s", d.Id(), err) -// } -// -// d.Set(names.AttrARN, resp.Arn) -// d.Set("channel_group_name", resp.ChannelGroupName) -// d.Set(names.AttrDescription, resp.Description) -// d.Set("egress_domain", resp.EgressDomain) -// -// setTagsOut(ctx, resp.Tags) -// -// return diags -//} -// -//func resourceChannelGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { -// var diags diag.Diagnostics -// conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) -// -// input := &mediapackagev2.UpdateChannelGroupInput{ -// ChannelGroupName: aws.String(d.Id()), -// Description: aws.String(d.Get(names.AttrDescription).(string)), -// } -// -// var _, err = conn.UpdateChannelGroup(ctx, input) -// -// if err != nil { -// return sdkdiag.AppendErrorf(diags, "updating MediaPackageV2 Channel Group: %s, %s", d.Id(), err) -// } -// -// return append(diags, resourceChannelGroupRead(ctx, d, meta)...) -//} -// -//func resourceChannelGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { -// var diags diag.Diagnostics -// conn := meta.(*conns.AWSClient).MediaPackageV2Client(ctx) -// -// DeleteChannelGroup := &mediapackagev2.DeleteChannelGroupInput{ -// ChannelGroupName: aws.String(d.Id()), -// } -// _, err := conn.DeleteChannelGroup(ctx, DeleteChannelGroup) -// if err != nil { -// var nfe *awstypes.ResourceNotFoundException -// if errors.As(err, &nfe) { -// return diags -// } -// return sdkdiag.AppendErrorf(diags, "deleting MediaPackageV2 Channel Group: %s", err) -// } -// -// channelGroupInput := &mediapackagev2.GetChannelGroupInput{ -// ChannelGroupName: aws.String(d.Id()), -// } -// err = retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError { -// _, err := conn.GetChannelGroup(ctx, channelGroupInput) -// if err != nil { -// var nfe *awstypes.ResourceNotFoundException -// if errors.As(err, &nfe) { -// return nil -// } -// return retry.NonRetryableError(err) -// } -// return retry.RetryableError(fmt.Errorf("MediaPackageV2 Channel Group: %s still exists", d.Id())) -// }) -// if tfresource.TimedOut(err) { -// _, err = conn.GetChannelGroup(ctx, channelGroupInput) -// } -// if err != nil { -// return sdkdiag.AppendErrorf(diags, "waiting for MediaPackage Channel: %s, deletion: %s", d.Id(), err) -// } -// -// return diags -//} +import ( + "context" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" + awstypes "github.com/aws/aws-sdk-go-v2/service/mediapackagev2/types" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +const ( + ResNameChannelGroup = "Channel Group" + ChannelGroupFieldNamePrefix = "ChannelGroup" +) + +// @FrameworkResource("aws_media_packagev2_channel_group", name="Channel Group") +// @Tags(identifierAttribute="arn") +func newResourceChannelGroup(context.Context) (resource.ResourceWithConfigure, error) { + r := &resourceChannelGroup{} + + return r, nil +} + +type resourceChannelGroup struct { + framework.ResourceWithConfigure +} + +func (r *resourceChannelGroup) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { + response.TypeName = "aws_media_packagev2_channel_group" +} + +func (r *resourceChannelGroup) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { + s := schema.Schema{ + Attributes: map[string]schema.Attribute{ + names.AttrARN: framework.ARNAttributeComputedOnly(), + names.AttrName: schema.StringAttribute{ + Required: true, + }, + names.AttrDescription: schema.StringAttribute{ + Optional: true, + }, + "egress_domain": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + names.AttrTags: tftags.TagsAttribute(), + names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), + }, + } + + response.Schema = s +} + +func (r *resourceChannelGroup) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + conn := r.Meta().MediaPackageV2Client(ctx) + var data resourceChannelGroupData + + response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + input := mediapackagev2.CreateChannelGroupInput{ + Tags: getTagsIn(ctx), + } + response.Diagnostics.Append(fwflex.Expand(ctx, data, &input, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + + output, err := conn.CreateChannelGroup(ctx, &input) + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionCreating, ResNameChannelGroup, data.Name.String(), err), + err.Error(), + ) + return + } + + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + + response.Diagnostics.Append(response.State.Set(ctx, &data)...) +} + +func (r *resourceChannelGroup) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + conn := r.Meta().MediaPackageV2Client(ctx) + var data resourceChannelGroupData + + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + output, err := findChannelGroupByID(ctx, conn, data.Name.ValueString()) + + if tfresource.NotFound(err) { + response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) + response.State.RemoveResource(ctx) + return + } + + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionReading, ResNameChannelGroup, data.Name.String(), err), + err.Error(), + ) + return + } + + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + + setTagsOut(ctx, output.Tags) + + response.Diagnostics.Append(response.State.Set(ctx, &data)...) +} + +func (r *resourceChannelGroup) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { + conn := r.Meta().MediaPackageV2Client(ctx) + var state, plan resourceChannelGroupData + + response.Diagnostics.Append(request.State.Get(ctx, &state)...) + if response.Diagnostics.HasError() { + return + } + + response.Diagnostics.Append(request.Plan.Get(ctx, &plan)...) + if response.Diagnostics.HasError() { + return + } + + diff, d := fwflex.Calculate(ctx, plan, state) + response.Diagnostics.Append(d...) + if response.Diagnostics.HasError() { + return + } + + if diff.HasChanges() { + input := mediapackagev2.UpdateChannelGroupInput{} + response.Diagnostics.Append(fwflex.Expand(ctx, plan, &input, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + + output, err := conn.UpdateChannelGroup(ctx, &input) + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionUpdating, ResNameChannelGroup, state.Name.String(), err), + err.Error(), + ) + return + } + + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &plan, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) + if response.Diagnostics.HasError() { + return + } + } + + response.Diagnostics.Append(response.State.Set(ctx, &plan)...) +} + +func (r *resourceChannelGroup) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { + conn := r.Meta().MediaPackageV2Client(ctx) + var data resourceChannelGroupData + + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + + if response.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, "deleting Channel Group", map[string]interface{}{ + names.AttrName: data.Name.ValueString(), + }) + + input := mediapackagev2.DeleteChannelGroupInput{ + ChannelGroupName: data.Name.ValueStringPointer(), + } + + _, err := conn.DeleteChannelGroup(ctx, &input) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return + } + + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionDeleting, ResNameChannelGroup, data.Name.String(), err), + err.Error(), + ) + return + } + + _, err = tfresource.RetryUntilNotFound(ctx, 5*time.Minute, func() (interface{}, error) { + return findChannelGroupByID(ctx, conn, data.Name.ValueString()) + }) + + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionWaitingForDeletion, ResNameChannelGroup, data.Name.String(), err), + err.Error(), + ) + } +} + +func (r *resourceChannelGroup) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root(names.AttrName), request, response) +} + +func (r *resourceChannelGroup) ModifyPlan(ctx context.Context, request resource.ModifyPlanRequest, response *resource.ModifyPlanResponse) { + r.SetTagsAll(ctx, request, response) +} + +type resourceChannelGroupData struct { + ARN types.String `tfsdk:"arn"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` + EgressDomain types.String `tfsdk:"egress_domain"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` +} + +func findChannelGroupByID(ctx context.Context, conn *mediapackagev2.Client, id string) (*mediapackagev2.GetChannelGroupOutput, error) { + in := &mediapackagev2.GetChannelGroupInput{ + ChannelGroupName: aws.String(id), + } + + out, err := conn.GetChannelGroup(ctx, in) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastRequest: in, + LastError: err, + } + } + + if err != nil { + return nil, err + } + + if out == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + return out, nil +} diff --git a/internal/service/mediapackagev2/channel_group_fw.go b/internal/service/mediapackagev2/channel_group_fw.go deleted file mode 100644 index aa96715106b..00000000000 --- a/internal/service/mediapackagev2/channel_group_fw.go +++ /dev/null @@ -1,274 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package mediapackagev2 - -import ( - "context" - "time" - - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" - awstypes "github.com/aws/aws-sdk-go-v2/service/mediapackagev2/types" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" - "github.com/hashicorp/terraform-provider-aws/internal/create" - "github.com/hashicorp/terraform-provider-aws/internal/errs" - "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" - "github.com/hashicorp/terraform-provider-aws/internal/framework" - fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" - tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" - "github.com/hashicorp/terraform-provider-aws/names" -) - -const ( - ResNameChannelGroup = "Channel Group" - ChannelGroupFieldNamePrefix = "ChannelGroup" -) - -// @FrameworkResource("aws_media_packagev2_channel_group", name="Channel Group") -// @Tags(identifierAttribute="arn") -func newResourceChannelGroup(context.Context) (resource.ResourceWithConfigure, error) { - r := &resourceChannelGroup{} - - return r, nil -} - -type resourceChannelGroup struct { - framework.ResourceWithConfigure -} - -func (r *resourceChannelGroup) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { - response.TypeName = "aws_media_packagev2_channel_group" -} - -func (r *resourceChannelGroup) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { - s := schema.Schema{ - Attributes: map[string]schema.Attribute{ - names.AttrARN: framework.ARNAttributeComputedOnly(), - names.AttrName: schema.StringAttribute{ - Required: true, - }, - names.AttrDescription: schema.StringAttribute{ - Optional: true, - }, - "egress_domain": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, - names.AttrTags: tftags.TagsAttribute(), - names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), - }, - } - - response.Schema = s -} - -func (r *resourceChannelGroup) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { - conn := r.Meta().MediaPackageV2Client(ctx) - var data resourceChannelGroupData - - response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) - if response.Diagnostics.HasError() { - return - } - - input := mediapackagev2.CreateChannelGroupInput{ - Tags: getTagsIn(ctx), - } - response.Diagnostics.Append(fwflex.Expand(ctx, data, &input, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) - if response.Diagnostics.HasError() { - return - } - - output, err := conn.CreateChannelGroup(ctx, &input) - if err != nil { - response.Diagnostics.AddError( - create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionCreating, ResNameChannelGroup, data.Name.String(), err), - err.Error(), - ) - return - } - - response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) - if response.Diagnostics.HasError() { - return - } - - response.Diagnostics.Append(response.State.Set(ctx, &data)...) -} - -func (r *resourceChannelGroup) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { - conn := r.Meta().MediaPackageV2Client(ctx) - var data resourceChannelGroupData - - response.Diagnostics.Append(request.State.Get(ctx, &data)...) - if response.Diagnostics.HasError() { - return - } - - output, err := findChannelGroupByID(ctx, conn, data.Name.ValueString()) - - if tfresource.NotFound(err) { - response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) - response.State.RemoveResource(ctx) - return - } - - if err != nil { - response.Diagnostics.AddError( - create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionReading, ResNameChannelGroup, data.Name.String(), err), - err.Error(), - ) - return - } - - response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) - if response.Diagnostics.HasError() { - return - } - - setTagsOut(ctx, output.Tags) - - response.Diagnostics.Append(response.State.Set(ctx, &data)...) -} - -func (r *resourceChannelGroup) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { - conn := r.Meta().MediaPackageV2Client(ctx) - var state, plan resourceChannelGroupData - - response.Diagnostics.Append(request.State.Get(ctx, &state)...) - if response.Diagnostics.HasError() { - return - } - - response.Diagnostics.Append(request.Plan.Get(ctx, &plan)...) - if response.Diagnostics.HasError() { - return - } - - diff, d := fwflex.Calculate(ctx, plan, state) - response.Diagnostics.Append(d...) - if response.Diagnostics.HasError() { - return - } - - if diff.HasChanges() { - input := mediapackagev2.UpdateChannelGroupInput{} - response.Diagnostics.Append(fwflex.Expand(ctx, plan, &input, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) - if response.Diagnostics.HasError() { - return - } - - output, err := conn.UpdateChannelGroup(ctx, &input) - if err != nil { - response.Diagnostics.AddError( - create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionUpdating, ResNameChannelGroup, state.Name.String(), err), - err.Error(), - ) - return - } - - response.Diagnostics.Append(fwflex.Flatten(ctx, output, &plan, fwflex.WithFieldNamePrefix(ChannelGroupFieldNamePrefix))...) - if response.Diagnostics.HasError() { - return - } - } - - response.Diagnostics.Append(response.State.Set(ctx, &plan)...) -} - -func (r *resourceChannelGroup) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { - conn := r.Meta().MediaPackageV2Client(ctx) - var data resourceChannelGroupData - - response.Diagnostics.Append(request.State.Get(ctx, &data)...) - - if response.Diagnostics.HasError() { - return - } - - tflog.Debug(ctx, "deleting Channel Group", map[string]interface{}{ - names.AttrName: data.Name.ValueString(), - }) - - input := mediapackagev2.DeleteChannelGroupInput{ - ChannelGroupName: data.Name.ValueStringPointer(), - } - - _, err := conn.DeleteChannelGroup(ctx, &input) - - if errs.IsA[*awstypes.ResourceNotFoundException](err) { - return - } - - if err != nil { - response.Diagnostics.AddError( - create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionDeleting, ResNameChannelGroup, data.Name.String(), err), - err.Error(), - ) - return - } - - _, err = tfresource.RetryUntilNotFound(ctx, 5*time.Minute, func() (interface{}, error) { - return findChannelGroupByID(ctx, conn, data.Name.ValueString()) - }) - - if err != nil { - response.Diagnostics.AddError( - create.ProblemStandardMessage(names.MediaPackageV2, create.ErrActionWaitingForDeletion, ResNameChannelGroup, data.Name.String(), err), - err.Error(), - ) - } -} - -func (r *resourceChannelGroup) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root(names.AttrName), request, response) -} - -func (r *resourceChannelGroup) ModifyPlan(ctx context.Context, request resource.ModifyPlanRequest, response *resource.ModifyPlanResponse) { - r.SetTagsAll(ctx, request, response) -} - -type resourceChannelGroupData struct { - ARN types.String `tfsdk:"arn"` - Name types.String `tfsdk:"name"` - Description types.String `tfsdk:"description"` - EgressDomain types.String `tfsdk:"egress_domain"` - Tags tftags.Map `tfsdk:"tags"` - TagsAll tftags.Map `tfsdk:"tags_all"` -} - -func findChannelGroupByID(ctx context.Context, conn *mediapackagev2.Client, id string) (*mediapackagev2.GetChannelGroupOutput, error) { - in := &mediapackagev2.GetChannelGroupInput{ - ChannelGroupName: aws.String(id), - } - - out, err := conn.GetChannelGroup(ctx, in) - - if errs.IsA[*awstypes.ResourceNotFoundException](err) { - return nil, &retry.NotFoundError{ - LastRequest: in, - LastError: err, - } - } - - if err != nil { - return nil, err - } - - if out == nil { - return nil, tfresource.NewEmptyResultError(in) - } - - return out, nil -} From 4b3ab2c6804457782f1dec0392467c40126b4ae5 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Jan 2025 15:46:25 -0600 Subject: [PATCH 07/10] update documentation --- ...edia_packagev2_channel_group.html.markdown | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/website/docs/r/media_packagev2_channel_group.html.markdown b/website/docs/r/media_packagev2_channel_group.html.markdown index 1b5113965a8..574abdd65b1 100644 --- a/website/docs/r/media_packagev2_channel_group.html.markdown +++ b/website/docs/r/media_packagev2_channel_group.html.markdown @@ -13,9 +13,9 @@ Creates an AWS Elemental MediaPackage Version 2 Channel Group. ## Example Usage ```terraform -resource "aws_media_packagev2_channel_group" "animals" { - channel_group_name = "animal-channels" - description = "channel group for animal channels" +resource "aws_media_packagev2_channel_group" "example" { + name = "example" + description = "channel group for example channels" } ``` @@ -23,19 +23,18 @@ resource "aws_media_packagev2_channel_group" "animals" { This resource supports the following arguments: -- `channel_group_name` - (Required) A unique identifier naming the channel group -- `description` - (Optional) A description of the channel group -- `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. +* `name` - (Required) A unique identifier naming the channel group +* `description` - (Optional) A description of the channel group +* `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ## Attribute Reference This resource exports the following attributes in addition to the arguments above: -- `id` - The same as `channel_group_name` -- `description` - The same as `description` -- `egress_domain` - The egress domain of the channel group -- `arn` - The ARN of the channel -- `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). +* `arn` - The ARN of the channel +* `description` - The same as `description` +* `egress_domain` - The egress domain of the channel group +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). ## Import @@ -43,13 +42,13 @@ In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashico ```terraform import { - to = aws_media_packagev2_channel_group.animals - id = "animal-channels" + to = aws_media_packagev2_channel_group.example + id = "example" } ``` -Using `terraform import`, import Elemental MediaPackage Version 2 Channel Group using the channel group's name. For example: +Using `terraform import`, import Elemental MediaPackage Version 2 Channel Group using the channel group's `name`. For example: ```console -% terraform import aws_media_packagev2_channel_group.animals animal-channels +% terraform import aws_media_packagev2_channel_group.example example ``` From 7565b9a8691a70a187796e530e68e13b7a8f25f6 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Jan 2025 16:18:15 -0600 Subject: [PATCH 08/10] aws_media_packagev2_channel_group: add tags tests --- .../service/mediapackagev2/channel_group.go | 3 + .../channel_group_tags_gen_test.go | 2288 +++++++++++++++++ .../mediapackagev2/channel_group_test.go | 30 +- internal/service/mediapackagev2/generate.go | 1 + .../mediapackagev2/mediapackagev2_test.go | 10 +- .../service/mediapackagev2/tags_gen_test.go | 16 + .../testdata/ChannelGroup/tags/main_gen.tf | 20 + .../ChannelGroup/tagsComputed1/main_gen.tf | 24 + .../ChannelGroup/tagsComputed2/main_gen.tf | 35 + .../ChannelGroup/tags_defaults/main_gen.tf | 31 + .../ChannelGroup/tags_ignore/main_gen.tf | 40 + .../testdata/tmpl/channel_group_tags.gtpl | 4 + 12 files changed, 2488 insertions(+), 14 deletions(-) create mode 100644 internal/service/mediapackagev2/channel_group_tags_gen_test.go create mode 100644 internal/service/mediapackagev2/tags_gen_test.go create mode 100644 internal/service/mediapackagev2/testdata/ChannelGroup/tags/main_gen.tf create mode 100644 internal/service/mediapackagev2/testdata/ChannelGroup/tagsComputed1/main_gen.tf create mode 100644 internal/service/mediapackagev2/testdata/ChannelGroup/tagsComputed2/main_gen.tf create mode 100644 internal/service/mediapackagev2/testdata/ChannelGroup/tags_defaults/main_gen.tf create mode 100644 internal/service/mediapackagev2/testdata/ChannelGroup/tags_ignore/main_gen.tf create mode 100644 internal/service/mediapackagev2/testdata/tmpl/channel_group_tags.gtpl diff --git a/internal/service/mediapackagev2/channel_group.go b/internal/service/mediapackagev2/channel_group.go index aa96715106b..e6d281de032 100644 --- a/internal/service/mediapackagev2/channel_group.go +++ b/internal/service/mediapackagev2/channel_group.go @@ -35,6 +35,9 @@ const ( // @FrameworkResource("aws_media_packagev2_channel_group", name="Channel Group") // @Tags(identifierAttribute="arn") +// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/mediapackagev2;mediapackagev2.GetChannelGroupOutput") +// @Testing(serialize=true) +// @Testing(importStateIdFunc=testAccChannelGroupImportStateIdFunc) func newResourceChannelGroup(context.Context) (resource.ResourceWithConfigure, error) { r := &resourceChannelGroup{} diff --git a/internal/service/mediapackagev2/channel_group_tags_gen_test.go b/internal/service/mediapackagev2/channel_group_tags_gen_test.go new file mode 100644 index 00000000000..c4564f9f5e9 --- /dev/null +++ b/internal/service/mediapackagev2/channel_group_tags_gen_test.go @@ -0,0 +1,2288 @@ +// Code generated by internal/generate/tagstests/main.go; DO NOT EDIT. + +package mediapackagev2_test + +import ( + "testing" + + "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" + "github.com/hashicorp/terraform-plugin-testing/config" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func testAccMediaPackageV2ChannelGroup_tagsSerial(t *testing.T) { + t.Helper() + + testCases := map[string]func(t *testing.T){ + acctest.CtBasic: testAccMediaPackageV2ChannelGroup_tags, + "null": testAccMediaPackageV2ChannelGroup_tags_null, + "EmptyMap": testAccMediaPackageV2ChannelGroup_tags_EmptyMap, + "AddOnUpdate": testAccMediaPackageV2ChannelGroup_tags_AddOnUpdate, + "EmptyTag_OnCreate": testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnCreate, + "EmptyTag_OnUpdate_Add": testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnUpdate_Add, + "EmptyTag_OnUpdate_Replace": testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnUpdate_Replace, + "DefaultTags_providerOnly": testAccMediaPackageV2ChannelGroup_tags_DefaultTags_providerOnly, + "DefaultTags_nonOverlapping": testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nonOverlapping, + "DefaultTags_overlapping": testAccMediaPackageV2ChannelGroup_tags_DefaultTags_overlapping, + "DefaultTags_updateToProviderOnly": testAccMediaPackageV2ChannelGroup_tags_DefaultTags_updateToProviderOnly, + "DefaultTags_updateToResourceOnly": testAccMediaPackageV2ChannelGroup_tags_DefaultTags_updateToResourceOnly, + "DefaultTags_emptyResourceTag": testAccMediaPackageV2ChannelGroup_tags_DefaultTags_emptyResourceTag, + "DefaultTags_nullOverlappingResourceTag": testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nullOverlappingResourceTag, + "DefaultTags_nullNonOverlappingResourceTag": testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nullNonOverlappingResourceTag, + "ComputedTag_OnCreate": testAccMediaPackageV2ChannelGroup_tags_ComputedTag_OnCreate, + "ComputedTag_OnUpdate_Add": testAccMediaPackageV2ChannelGroup_tags_ComputedTag_OnUpdate_Add, + "ComputedTag_OnUpdate_Replace": testAccMediaPackageV2ChannelGroup_tags_ComputedTag_OnUpdate_Replace, + "IgnoreTags_Overlap_DefaultTag": testAccMediaPackageV2ChannelGroup_tags_IgnoreTags_Overlap_DefaultTag, + "IgnoreTags_Overlap_ResourceTag": testAccMediaPackageV2ChannelGroup_tags_IgnoreTags_Overlap_ResourceTag, + } + + acctest.RunSerialTests1Level(t, testCases, 0) +} + +func testAccMediaPackageV2ChannelGroup_tags(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_null(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_EmptyMap(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_AddOnUpdate(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnCreate(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnUpdate_Add(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + acctest.CtKey2: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + acctest.CtKey2: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_providerOnly(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nonOverlapping(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_overlapping(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + acctest.CtOverlapKey2: config.StringVariable("providervalue2"), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + acctest.CtOverlapKey2: config.StringVariable("providervalue2"), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_updateToProviderOnly(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_updateToResourceOnly(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_emptyResourceTag(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: nil, + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.Null(), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(""), + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.Null(), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(""), + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: nil, + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "tags.resourcekey1", // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_ComputedTag_OnCreate(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_ComputedTag_OnUpdate_Add(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tagsComputed2/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + "knownTagKey": config.StringVariable(acctest.CtKey1), + "knownTagValue": config.StringVariable(acctest.CtValue1), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(2)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapPartial(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(2)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapPartial(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tagsComputed2/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + "knownTagKey": config.StringVariable(acctest.CtKey1), + "knownTagValue": config.StringVariable(acctest.CtValue1), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable(acctest.CtKey1), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + resource.TestCheckResourceAttrPair(resourceName, acctest.CtTagsKey1, "null_resource.test", names.AttrID), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey(acctest.CtKey1)), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable(acctest.CtKey1), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + // 1: Create + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + expectFullResourceTags(resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + // 2: Update ignored tag only + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + expectFullResourceTags(resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + // 3: Update both tags + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Again), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + expectFullResourceTags(resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + }, + }) +} + +func testAccMediaPackageV2ChannelGroup_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { + ctx := acctest.Context(t) + var v mediapackagev2.GetChannelGroupOutput + resourceName := "aws_media_packagev2_channel_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.MediaPackageV2ServiceID), + CheckDestroy: testAccCheckChannelGroupDestroy(ctx), + Steps: []resource.TestStep{ + // 1: Create + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + expectFullResourceTags(resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + ExpectNonEmptyPlan: true, + }, + // 2: Update ignored tag + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + expectFullResourceTags(resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + ExpectNonEmptyPlan: true, + }, + // 3: Update both tags + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2Updated), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckChannelGroupExists(ctx, resourceName, &v), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + expectFullResourceTags(resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + }, + }, + ExpectNonEmptyPlan: true, + }, + }, + }) +} diff --git a/internal/service/mediapackagev2/channel_group_test.go b/internal/service/mediapackagev2/channel_group_test.go index 30dd92d09a0..40fbd3a1d88 100644 --- a/internal/service/mediapackagev2/channel_group_test.go +++ b/internal/service/mediapackagev2/channel_group_test.go @@ -21,8 +21,10 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -func testAccMediaPackageChannelGroup_basic(t *testing.T) { +func testAccMediaPackageV2ChannelGroup_basic(t *testing.T) { ctx := acctest.Context(t) + + var channelGroup mediapackagev2.GetChannelGroupOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_media_packagev2_channel_group.test" @@ -38,7 +40,7 @@ func testAccMediaPackageChannelGroup_basic(t *testing.T) { { Config: testAccChannelGroupConfig_basic(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckChannelExists(ctx, resourceName), + testAccCheckChannelGroupExists(ctx, resourceName, &channelGroup), acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "mediapackagev2", regexache.MustCompile(`channelGroup/.+`)), resource.TestMatchResourceAttr(resourceName, "egress_domain", regexache.MustCompile(fmt.Sprintf("^[0-9a-z]+.egress.[0-9a-z]+.mediapackagev2.%s.amazonaws.com$", acctest.Region()))), ), @@ -54,8 +56,10 @@ func testAccMediaPackageChannelGroup_basic(t *testing.T) { }) } -func testAccMediaPackageChannelGroup_description(t *testing.T) { +func testAccMediaPackageV2ChannelGroup_description(t *testing.T) { ctx := acctest.Context(t) + + var channelGroup mediapackagev2.GetChannelGroupOutput resourceName := "aws_media_packagev2_channel_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -71,7 +75,7 @@ func testAccMediaPackageChannelGroup_description(t *testing.T) { { Config: testAccChannelGroupConfig_description(rName, "description1"), Check: resource.ComposeTestCheckFunc( - testAccCheckChannelExists(ctx, resourceName), + testAccCheckChannelGroupExists(ctx, resourceName, &channelGroup), resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "description1"), ), }, @@ -85,7 +89,7 @@ func testAccMediaPackageChannelGroup_description(t *testing.T) { { Config: testAccChannelGroupConfig_description(rName, "description2"), Check: resource.ComposeTestCheckFunc( - testAccCheckChannelExists(ctx, resourceName), + testAccCheckChannelGroupExists(ctx, resourceName, &channelGroup), resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "description2"), ), }, @@ -93,8 +97,10 @@ func testAccMediaPackageChannelGroup_description(t *testing.T) { }) } -func testAccMediaPackageChannelGroup_disappears(t *testing.T) { +func testAccMediaPackageV2ChannelGroup_disappears(t *testing.T) { ctx := acctest.Context(t) + + var channelGroup mediapackagev2.GetChannelGroupOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_media_packagev2_channel_group.test" @@ -110,7 +116,7 @@ func testAccMediaPackageChannelGroup_disappears(t *testing.T) { { Config: testAccChannelGroupConfig_basic(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckChannelExists(ctx, resourceName), + testAccCheckChannelGroupExists(ctx, resourceName, &channelGroup), acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfmediapackagev2.ResourceChannelGroup, resourceName), ), ExpectNonEmptyPlan: true, @@ -119,6 +125,10 @@ func testAccMediaPackageChannelGroup_disappears(t *testing.T) { }) } +func testAccChannelGroupImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { + return acctest.AttrImportStateIdFunc(resourceName, names.AttrName) +} + func testAccCheckChannelGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).MediaPackageV2Client(ctx) @@ -146,7 +156,7 @@ func testAccCheckChannelGroupDestroy(ctx context.Context) resource.TestCheckFunc } } -func testAccCheckChannelExists(ctx context.Context, name string) resource.TestCheckFunc { +func testAccCheckChannelGroupExists(ctx context.Context, name string, channelGroup *mediapackagev2.GetChannelGroupOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -154,12 +164,14 @@ func testAccCheckChannelExists(ctx context.Context, name string) resource.TestCh } conn := acctest.Provider.Meta().(*conns.AWSClient).MediaPackageV2Client(ctx) - _, err := tfmediapackagev2.FindChannelGroupByID(ctx, conn, rs.Primary.Attributes[names.AttrName]) + resp, err := tfmediapackagev2.FindChannelGroupByID(ctx, conn, rs.Primary.Attributes[names.AttrName]) if err != nil { return create.Error(names.MediaPackageV2, create.ErrActionCheckingExistence, tfmediapackagev2.ResNameChannelGroup, rs.Primary.Attributes[names.AttrName], err) } + *channelGroup = *resp + return nil } } diff --git a/internal/service/mediapackagev2/generate.go b/internal/service/mediapackagev2/generate.go index 7c7be5850c9..3a5debbf908 100644 --- a/internal/service/mediapackagev2/generate.go +++ b/internal/service/mediapackagev2/generate.go @@ -3,6 +3,7 @@ //go:generate go run ../../generate/tags/main.go -KVTValues -ListTags -ServiceTagsMap -UpdateTags //go:generate go run ../../generate/servicepackage/main.go +//go:generate go run ../../generate/tagstests/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. package mediapackagev2 diff --git a/internal/service/mediapackagev2/mediapackagev2_test.go b/internal/service/mediapackagev2/mediapackagev2_test.go index 34fd7e5ef60..b07bd88e668 100644 --- a/internal/service/mediapackagev2/mediapackagev2_test.go +++ b/internal/service/mediapackagev2/mediapackagev2_test.go @@ -15,11 +15,11 @@ func TestAccMediaPackageV2_serial(t *testing.T) { t.Parallel() testCases := map[string]map[string]func(t *testing.T){ - "MediaPackageChannelGroup": { - acctest.CtBasic: testAccMediaPackageChannelGroup_basic, - "description": testAccMediaPackageChannelGroup_description, - acctest.CtDisappears: testAccMediaPackageChannelGroup_disappears, - //"tags": testAccMediaPackageChannelGroup_tags, + "ChannelGroup": { + acctest.CtBasic: testAccMediaPackageV2ChannelGroup_basic, + "description": testAccMediaPackageV2ChannelGroup_description, + acctest.CtDisappears: testAccMediaPackageV2ChannelGroup_disappears, + "tags": testAccMediaPackageV2ChannelGroup_tagsSerial, }, } diff --git a/internal/service/mediapackagev2/tags_gen_test.go b/internal/service/mediapackagev2/tags_gen_test.go new file mode 100644 index 00000000000..5533081fab1 --- /dev/null +++ b/internal/service/mediapackagev2/tags_gen_test.go @@ -0,0 +1,16 @@ +// Code generated by internal/generate/tagstests/main.go; DO NOT EDIT. + +package mediapackagev2_test + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + tfstatecheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/statecheck" + tfmediapackagev2 "github.com/hashicorp/terraform-provider-aws/internal/service/mediapackagev2" +) + +func expectFullResourceTags(resourceAddress string, knownValue knownvalue.Check) statecheck.StateCheck { + return tfstatecheck.ExpectFullResourceTags(tfmediapackagev2.ServicePackage(context.Background()), resourceAddress, knownValue) +} diff --git a/internal/service/mediapackagev2/testdata/ChannelGroup/tags/main_gen.tf b/internal/service/mediapackagev2/testdata/ChannelGroup/tags/main_gen.tf new file mode 100644 index 00000000000..194fff543ec --- /dev/null +++ b/internal/service/mediapackagev2/testdata/ChannelGroup/tags/main_gen.tf @@ -0,0 +1,20 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +resource "aws_media_packagev2_channel_group" "test" { + name = var.rName + + tags = var.resource_tags +} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} diff --git a/internal/service/mediapackagev2/testdata/ChannelGroup/tagsComputed1/main_gen.tf b/internal/service/mediapackagev2/testdata/ChannelGroup/tagsComputed1/main_gen.tf new file mode 100644 index 00000000000..a2e4239895e --- /dev/null +++ b/internal/service/mediapackagev2/testdata/ChannelGroup/tagsComputed1/main_gen.tf @@ -0,0 +1,24 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "null" {} + +resource "aws_media_packagev2_channel_group" "test" { + name = var.rName + + tags = { + (var.unknownTagKey) = null_resource.test.id + } +} +resource "null_resource" "test" {} + +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "unknownTagKey" { + type = string + nullable = false +} diff --git a/internal/service/mediapackagev2/testdata/ChannelGroup/tagsComputed2/main_gen.tf b/internal/service/mediapackagev2/testdata/ChannelGroup/tagsComputed2/main_gen.tf new file mode 100644 index 00000000000..5c33d3f26ea --- /dev/null +++ b/internal/service/mediapackagev2/testdata/ChannelGroup/tagsComputed2/main_gen.tf @@ -0,0 +1,35 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "null" {} + +resource "aws_media_packagev2_channel_group" "test" { + name = var.rName + + tags = { + (var.unknownTagKey) = null_resource.test.id + (var.knownTagKey) = var.knownTagValue + } +} +resource "null_resource" "test" {} + +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "unknownTagKey" { + type = string + nullable = false +} + +variable "knownTagKey" { + type = string + nullable = false +} + +variable "knownTagValue" { + type = string + nullable = false +} diff --git a/internal/service/mediapackagev2/testdata/ChannelGroup/tags_defaults/main_gen.tf b/internal/service/mediapackagev2/testdata/ChannelGroup/tags_defaults/main_gen.tf new file mode 100644 index 00000000000..290760fcd27 --- /dev/null +++ b/internal/service/mediapackagev2/testdata/ChannelGroup/tags_defaults/main_gen.tf @@ -0,0 +1,31 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "aws" { + default_tags { + tags = var.provider_tags + } +} + +resource "aws_media_packagev2_channel_group" "test" { + name = var.rName + + tags = var.resource_tags +} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} + +variable "provider_tags" { + type = map(string) + nullable = false +} diff --git a/internal/service/mediapackagev2/testdata/ChannelGroup/tags_ignore/main_gen.tf b/internal/service/mediapackagev2/testdata/ChannelGroup/tags_ignore/main_gen.tf new file mode 100644 index 00000000000..f0ababbafc7 --- /dev/null +++ b/internal/service/mediapackagev2/testdata/ChannelGroup/tags_ignore/main_gen.tf @@ -0,0 +1,40 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "aws" { + default_tags { + tags = var.provider_tags + } + ignore_tags { + keys = var.ignore_tag_keys + } +} + +resource "aws_media_packagev2_channel_group" "test" { + name = var.rName + + tags = var.resource_tags +} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} + +variable "provider_tags" { + type = map(string) + nullable = true + default = null +} + +variable "ignore_tag_keys" { + type = set(string) + nullable = false +} diff --git a/internal/service/mediapackagev2/testdata/tmpl/channel_group_tags.gtpl b/internal/service/mediapackagev2/testdata/tmpl/channel_group_tags.gtpl new file mode 100644 index 00000000000..065d33d4ab4 --- /dev/null +++ b/internal/service/mediapackagev2/testdata/tmpl/channel_group_tags.gtpl @@ -0,0 +1,4 @@ +resource "aws_media_packagev2_channel_group" "test" { + name = var.rName +{{- template "tags" . }} +} \ No newline at end of file From 701a270364f829340311f7eaad5b45e7329e0736 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Jan 2025 16:32:50 -0600 Subject: [PATCH 09/10] aws_media_packagev2_channel_group: correct tags import func --- .../service/mediapackagev2/channel_group.go | 1 + .../channel_group_tags_gen_test.go | 248 +++++++++++------- 2 files changed, 156 insertions(+), 93 deletions(-) diff --git a/internal/service/mediapackagev2/channel_group.go b/internal/service/mediapackagev2/channel_group.go index e6d281de032..ef6ee090423 100644 --- a/internal/service/mediapackagev2/channel_group.go +++ b/internal/service/mediapackagev2/channel_group.go @@ -38,6 +38,7 @@ const ( // @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/mediapackagev2;mediapackagev2.GetChannelGroupOutput") // @Testing(serialize=true) // @Testing(importStateIdFunc=testAccChannelGroupImportStateIdFunc) +// @Testing(importStateIdAttribute=name) func newResourceChannelGroup(context.Context) (resource.ResourceWithConfigure, error) { r := &resourceChannelGroup{} diff --git a/internal/service/mediapackagev2/channel_group_tags_gen_test.go b/internal/service/mediapackagev2/channel_group_tags_gen_test.go index c4564f9f5e9..48936918307 100644 --- a/internal/service/mediapackagev2/channel_group_tags_gen_test.go +++ b/internal/service/mediapackagev2/channel_group_tags_gen_test.go @@ -97,9 +97,11 @@ func testAccMediaPackageV2ChannelGroup_tags(t *testing.T) { acctest.CtKey1: config.StringVariable(acctest.CtValue1), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), @@ -146,9 +148,11 @@ func testAccMediaPackageV2ChannelGroup_tags(t *testing.T) { acctest.CtKey2: config.StringVariable(acctest.CtValue2), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), @@ -189,9 +193,11 @@ func testAccMediaPackageV2ChannelGroup_tags(t *testing.T) { acctest.CtKey2: config.StringVariable(acctest.CtValue2), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), @@ -220,9 +226,11 @@ func testAccMediaPackageV2ChannelGroup_tags(t *testing.T) { acctest.CtRName: config.StringVariable(rName), acctest.CtResourceTags: nil, }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -279,9 +287,11 @@ func testAccMediaPackageV2ChannelGroup_tags_null(t *testing.T) { acctest.CtKey1: nil, }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, ImportStateVerifyIgnore: []string{ acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" }, @@ -329,9 +339,11 @@ func testAccMediaPackageV2ChannelGroup_tags_EmptyMap(t *testing.T) { acctest.CtRName: config.StringVariable(rName), acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, ImportStateVerifyIgnore: []string{ acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" }, @@ -412,9 +424,11 @@ func testAccMediaPackageV2ChannelGroup_tags_AddOnUpdate(t *testing.T) { acctest.CtKey1: config.StringVariable(acctest.CtValue1), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -471,9 +485,11 @@ func testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnCreate(t *testing.T) { acctest.CtKey1: config.StringVariable(""), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), @@ -502,9 +518,11 @@ func testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnCreate(t *testing.T) { acctest.CtRName: config.StringVariable(rName), acctest.CtResourceTags: nil, }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -598,9 +616,11 @@ func testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnUpdate_Add(t *testing.T) acctest.CtKey2: config.StringVariable(""), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ConfigDirectory: config.StaticDirectory("testdata/ChannelGroup/tags/"), @@ -641,9 +661,11 @@ func testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnUpdate_Add(t *testing.T) acctest.CtKey1: config.StringVariable(acctest.CtValue1), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -731,9 +753,11 @@ func testAccMediaPackageV2ChannelGroup_tags_EmptyTag_OnUpdate_Replace(t *testing acctest.CtKey1: config.StringVariable(""), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -789,9 +813,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_providerOnly(t *testing. }), acctest.CtResourceTags: nil, }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -836,9 +862,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_providerOnly(t *testing. }), acctest.CtResourceTags: nil, }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -879,9 +907,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_providerOnly(t *testing. }), acctest.CtResourceTags: nil, }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -912,9 +942,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_providerOnly(t *testing. acctest.CtRName: config.StringVariable(rName), acctest.CtResourceTags: nil, }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -980,9 +1012,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nonOverlapping(t *testin acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -1039,9 +1073,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nonOverlapping(t *testin acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -1072,9 +1108,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nonOverlapping(t *testin acctest.CtRName: config.StringVariable(rName), acctest.CtResourceTags: nil, }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -1138,9 +1176,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_overlapping(t *testing.T acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -1197,9 +1237,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_overlapping(t *testing.T acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -1248,9 +1290,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_overlapping(t *testing.T acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -1338,9 +1382,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_updateToProviderOnly(t * }), acctest.CtResourceTags: nil, }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -1427,9 +1473,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_updateToResourceOnly(t * acctest.CtKey1: config.StringVariable(acctest.CtValue1), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -1493,9 +1541,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_emptyResourceTag(t *test acctest.CtKey1: config.StringVariable(""), }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -1551,9 +1601,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_emptyProviderOnlyTag(t * }), acctest.CtResourceTags: nil, }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -1617,9 +1669,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nullOverlappingResourceT acctest.CtKey1: nil, }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, ImportStateVerifyIgnore: []string{ acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" }, @@ -1688,9 +1742,11 @@ func testAccMediaPackageV2ChannelGroup_tags_DefaultTags_nullNonOverlappingResour acctest.CtResourceKey1: nil, }), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, ImportStateVerifyIgnore: []string{ "tags.resourcekey1", // The canonical value returned by the AWS API is "" }, @@ -1746,9 +1802,11 @@ func testAccMediaPackageV2ChannelGroup_tags_ComputedTag_OnCreate(t *testing.T) { acctest.CtRName: config.StringVariable(rName), "unknownTagKey": config.StringVariable("computedkey1"), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -1843,9 +1901,11 @@ func testAccMediaPackageV2ChannelGroup_tags_ComputedTag_OnUpdate_Add(t *testing. "knownTagKey": config.StringVariable(acctest.CtKey1), "knownTagValue": config.StringVariable(acctest.CtValue1), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) @@ -1930,9 +1990,11 @@ func testAccMediaPackageV2ChannelGroup_tags_ComputedTag_OnUpdate_Replace(t *test acctest.CtRName: config.StringVariable(rName), "unknownTagKey": config.StringVariable(acctest.CtKey1), }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccChannelGroupImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, }, }, }) From fdc77611d5b0453f926c7cee7349643d434b8b9b Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 9 Jan 2025 16:34:57 -0600 Subject: [PATCH 10/10] correct CHANGELOG entry --- .changelog/{38404.txt => 38406.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{38404.txt => 38406.txt} (100%) diff --git a/.changelog/38404.txt b/.changelog/38406.txt similarity index 100% rename from .changelog/38404.txt rename to .changelog/38406.txt