From 9485cfb6528d1b18f922871a97d81d38ce9937ab Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 5 Apr 2023 17:37:16 -0400 Subject: [PATCH 1/3] Remove tagging boilerplate for Plugin SDK resources - neptune. --- internal/service/neptune/cluster.go | 41 +++------------ internal/service/neptune/cluster_endpoint.go | 50 ++++-------------- internal/service/neptune/cluster_instance.go | 39 +++----------- .../neptune/cluster_parameter_group.go | 40 +++------------ .../service/neptune/event_subscription.go | 51 +++++-------------- internal/service/neptune/parameter_group.go | 39 +++----------- .../service/neptune/service_package_gen.go | 28 ++++++++++ internal/service/neptune/subnet_group.go | 39 +++----------- 8 files changed, 80 insertions(+), 247 deletions(-) diff --git a/internal/service/neptune/cluster.go b/internal/service/neptune/cluster.go index 6a1f8c666c1..0215c97b398 100644 --- a/internal/service/neptune/cluster.go +++ b/internal/service/neptune/cluster.go @@ -22,6 +22,7 @@ import ( 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" ) const ( @@ -37,7 +38,8 @@ const ( ServerlessMaxNCUs = 128.0 ) -// @SDKResource("aws_neptune_cluster") +// @SDKResource("aws_neptune_cluster", name="Cluster") +// @Tags(identifierAttribute="arn") func ResourceCluster() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceClusterCreate, @@ -278,8 +280,8 @@ func ResourceCluster() *schema.Resource { ForceNew: true, Default: false, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "vpc_security_group_ids": { Type: schema.TypeSet, Optional: true, @@ -295,8 +297,6 @@ func ResourceCluster() *schema.Resource { func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) // Check if any of the parameters that require a cluster modification after creation are set. // See https://docs.aws.amazon.com/neptune/latest/userguide/backup-restore-restore-snapshot.html#backup-restore-restore-snapshot-considerations. @@ -322,7 +322,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int Port: aws.Int64(int64(d.Get("port").(int))), StorageEncrypted: aws.Bool(d.Get("storage_encrypted").(bool)), DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), ServerlessV2ScalingConfiguration: serverlessConfiguration, } inputR := &neptune.RestoreDBClusterFromSnapshotInput{ @@ -332,7 +332,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int Port: aws.Int64(int64(d.Get("port").(int))), SnapshotIdentifier: aws.String(d.Get("snapshot_identifier").(string)), DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), ServerlessV2ScalingConfiguration: serverlessConfiguration, } inputM := &neptune.ModifyDBClusterInput{ @@ -482,8 +482,6 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig dbc, err := FindClusterByID(ctx, conn, d.Id()) @@ -549,23 +547,6 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter } d.Set("vpc_security_group_ids", securityGroupIDs) - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Neptune Cluster (%s): %s", arn, err) - } - - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } @@ -728,14 +709,6 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating Neptune Cluster (%s) tags: %s", d.Get("arn").(string), err) - } - } - return append(diags, resourceClusterRead(ctx, d, meta)...) } diff --git a/internal/service/neptune/cluster_endpoint.go b/internal/service/neptune/cluster_endpoint.go index ec60e9523d5..faf742d5a73 100644 --- a/internal/service/neptune/cluster_endpoint.go +++ b/internal/service/neptune/cluster_endpoint.go @@ -18,9 +18,11 @@ import ( 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_neptune_cluster_endpoint") +// @SDKResource("aws_neptune_cluster_endpoint", name="Cluster Endpoint") +// @Tags(identifierAttribute="arn") func ResourceClusterEndpoint() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceClusterEndpointCreate, @@ -68,8 +70,8 @@ func ResourceClusterEndpoint() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -79,13 +81,12 @@ func ResourceClusterEndpoint() *schema.Resource { func resourceClusterEndpointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) input := &neptune.CreateDBClusterEndpointInput{ DBClusterEndpointIdentifier: aws.String(d.Get("cluster_endpoint_identifier").(string)), DBClusterIdentifier: aws.String(d.Get("cluster_identifier").(string)), EndpointType: aws.String(d.Get("endpoint_type").(string)), + Tags: GetTagsIn(ctx), } if attr := d.Get("static_members").(*schema.Set); attr.Len() > 0 { @@ -97,8 +98,8 @@ func resourceClusterEndpointCreate(ctx context.Context, d *schema.ResourceData, } // Tags are currently only supported in AWS Commercial. - if len(tags) > 0 && meta.(*conns.AWSClient).Partition == endpoints.AwsPartitionID { - input.Tags = Tags(tags.IgnoreAWS()) + if meta.(*conns.AWSClient).Partition != endpoints.AwsPartitionID { + input.Tags = nil } out, err := conn.CreateDBClusterEndpointWithContext(ctx, input) @@ -121,10 +122,9 @@ func resourceClusterEndpointCreate(ctx context.Context, d *schema.ResourceData, func resourceClusterEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig resp, err := FindEndpointByID(ctx, conn, d.Id()) + if !d.IsNewResource() && tfresource.NotFound(err) { d.SetId("") log.Printf("[DEBUG] Neptune Cluster Endpoint (%s) not found", d.Id()) @@ -145,29 +145,6 @@ func resourceClusterEndpointRead(ctx context.Context, d *schema.ResourceData, me arn := aws.StringValue(resp.DBClusterEndpointArn) d.Set("arn", arn) - // Tags are currently only supported in AWS Commercial. - if meta.(*conns.AWSClient).Partition == endpoints.AwsPartitionID { - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Neptune Cluster Endpoint (%s): %s", arn, err) - } - - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - } else { - d.Set("tags", nil) - d.Set("tags_all", nil) - } - return diags } @@ -203,15 +180,6 @@ func resourceClusterEndpointUpdate(ctx context.Context, d *schema.ResourceData, } } - // Tags are currently only supported in AWS Commercial. - if d.HasChange("tags_all") && meta.(*conns.AWSClient).Partition == endpoints.AwsPartitionID { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating Neptune Cluster Endpoint (%s) tags: %s", d.Get("arn").(string), err) - } - } - return append(diags, resourceClusterEndpointRead(ctx, d, meta)...) } diff --git a/internal/service/neptune/cluster_instance.go b/internal/service/neptune/cluster_instance.go index b71fb9bb0a0..30e1f246c75 100644 --- a/internal/service/neptune/cluster_instance.go +++ b/internal/service/neptune/cluster_instance.go @@ -19,9 +19,11 @@ import ( 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_neptune_cluster_instance") +// @SDKResource("aws_neptune_cluster_instance", name="Cluster") +// @Tags(identifierAttribute="arn") func ResourceClusterInstance() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceClusterInstanceCreate, @@ -164,8 +166,8 @@ func ResourceClusterInstance() *schema.Resource { Type: schema.TypeBool, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "writer": { Type: schema.TypeBool, Computed: true, @@ -179,8 +181,6 @@ func ResourceClusterInstance() *schema.Resource { func resourceClusterInstanceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) var instanceID string if v, ok := d.GetOk("identifier"); ok { @@ -199,7 +199,7 @@ func resourceClusterInstanceCreate(ctx context.Context, d *schema.ResourceData, Engine: aws.String(d.Get("engine").(string)), PromotionTier: aws.Int64(int64(d.Get("promotion_tier").(int))), PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("availability_zone"); ok { @@ -246,8 +246,6 @@ func resourceClusterInstanceCreate(ctx context.Context, d *schema.ResourceData, func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig db, err := FindClusterInstanceByID(ctx, conn, d.Id()) @@ -301,23 +299,6 @@ func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, me d.Set("writer", m.IsClusterWriter) - tags, err := ListTags(ctx, conn, d.Get("arn").(string)) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Neptune Cluster Instance (%s): %s", d.Get("arn").(string), err) - } - - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } @@ -368,14 +349,6 @@ func resourceClusterInstanceUpdate(ctx context.Context, d *schema.ResourceData, } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating Neptune Cluster Instance (%s) tags: %s", d.Get("arn").(string), err) - } - } - return append(diags, resourceClusterInstanceRead(ctx, d, meta)...) } diff --git a/internal/service/neptune/cluster_parameter_group.go b/internal/service/neptune/cluster_parameter_group.go index 1ef8de82742..92e8cbe29c1 100644 --- a/internal/service/neptune/cluster_parameter_group.go +++ b/internal/service/neptune/cluster_parameter_group.go @@ -15,11 +15,13 @@ import ( "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/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) const clusterParameterGroupMaxParamsBulkEdit = 20 -// @SDKResource("aws_neptune_cluster_parameter_group") +// @SDKResource("aws_neptune_cluster_parameter_group", name="Cluster Parameter Group") +// @Tags(identifierAttribute="arn") func ResourceClusterParameterGroup() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceClusterParameterGroupCreate, @@ -87,9 +89,8 @@ func ResourceClusterParameterGroup() *schema.Resource { }, }, }, - - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -99,8 +100,6 @@ func ResourceClusterParameterGroup() *schema.Resource { func resourceClusterParameterGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) var groupName string if v, ok := d.GetOk("name"); ok { @@ -115,7 +114,7 @@ func resourceClusterParameterGroupCreate(ctx context.Context, d *schema.Resource DBClusterParameterGroupName: aws.String(groupName), DBParameterGroupFamily: aws.String(d.Get("family").(string)), Description: aws.String(d.Get("description").(string)), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), } _, err := conn.CreateDBClusterParameterGroupWithContext(ctx, &createOpts) @@ -138,8 +137,6 @@ func resourceClusterParameterGroupCreate(ctx context.Context, d *schema.Resource func resourceClusterParameterGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig describeOpts := neptune.DescribeDBClusterParameterGroupsInput{ DBClusterParameterGroupName: aws.String(d.Id()), @@ -187,23 +184,6 @@ func resourceClusterParameterGroupRead(ctx context.Context, d *schema.ResourceDa return sdkdiag.AppendErrorf(diags, "setting neptune parameter: %s", err) } - tags, err := ListTags(ctx, conn, d.Get("arn").(string)) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Neptune Cluster Parameter Group (%s): %s", d.Id(), err) - } - - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } @@ -233,14 +213,6 @@ func resourceClusterParameterGroupUpdate(ctx context.Context, d *schema.Resource } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating Neptune Cluster Parameter Group (%s) tags: %s", d.Id(), err) - } - } - return append(diags, resourceClusterParameterGroupRead(ctx, d, meta)...) } diff --git a/internal/service/neptune/event_subscription.go b/internal/service/neptune/event_subscription.go index 62ff39757bf..9d9433696bb 100644 --- a/internal/service/neptune/event_subscription.go +++ b/internal/service/neptune/event_subscription.go @@ -17,9 +17,11 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_neptune_event_subscription") +// @SDKResource("aws_neptune_event_subscription", name="Event Subscription") +// @Tags(identifierAttribute="arn") func ResourceEventSubscription() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceEventSubscriptionCreate, @@ -86,8 +88,8 @@ func ResourceEventSubscription() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -97,8 +99,6 @@ func ResourceEventSubscription() *schema.Resource { func resourceEventSubscriptionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) if v, ok := d.GetOk("name"); ok { d.Set("name", v.(string)) @@ -108,11 +108,11 @@ func resourceEventSubscriptionCreate(ctx context.Context, d *schema.ResourceData d.Set("name", id.PrefixedUniqueId("tf-")) } - request := &neptune.CreateEventSubscriptionInput{ + input := &neptune.CreateEventSubscriptionInput{ SubscriptionName: aws.String(d.Get("name").(string)), SnsTopicArn: aws.String(d.Get("sns_topic_arn").(string)), Enabled: aws.Bool(d.Get("enabled").(bool)), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("source_ids"); ok { @@ -121,7 +121,7 @@ func resourceEventSubscriptionCreate(ctx context.Context, d *schema.ResourceData for i, sourceId := range sourceIdsSet.List() { sourceIds[i] = aws.String(sourceId.(string)) } - request.SourceIds = sourceIds + input.SourceIds = sourceIds } if v, ok := d.GetOk("event_categories"); ok { @@ -130,16 +130,16 @@ func resourceEventSubscriptionCreate(ctx context.Context, d *schema.ResourceData for i, eventCategory := range eventCategoriesSet.List() { eventCategories[i] = aws.String(eventCategory.(string)) } - request.EventCategories = eventCategories + input.EventCategories = eventCategories } if v, ok := d.GetOk("source_type"); ok { - request.SourceType = aws.String(v.(string)) + input.SourceType = aws.String(v.(string)) } - log.Println("[DEBUG] Create Neptune Event Subscription:", request) + log.Println("[DEBUG] Create Neptune Event Subscription:", input) - output, err := conn.CreateEventSubscriptionWithContext(ctx, request) + output, err := conn.CreateEventSubscriptionWithContext(ctx, input) if err != nil || output.EventSubscription == nil { return sdkdiag.AppendErrorf(diags, "creating Neptune Event Subscription %s: %s", d.Get("name").(string), err) } @@ -169,8 +169,6 @@ func resourceEventSubscriptionCreate(ctx context.Context, d *schema.ResourceData func resourceEventSubscriptionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig sub, err := resourceEventSubscriptionRetrieve(ctx, d.Id(), conn) if err != nil { @@ -202,23 +200,6 @@ func resourceEventSubscriptionRead(ctx context.Context, d *schema.ResourceData, } } - tags, err := ListTags(ctx, conn, d.Get("arn").(string)) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Neptune Event Subscription (%s): %s", d.Get("arn").(string), err) - } - - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } @@ -283,14 +264,6 @@ func resourceEventSubscriptionUpdate(ctx context.Context, d *schema.ResourceData } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating Neptune Cluster Event Subscription (%s) tags: %s", d.Get("arn").(string), err) - } - } - if d.HasChange("source_ids") { o, n := d.GetChange("source_ids") if o == nil { diff --git a/internal/service/neptune/parameter_group.go b/internal/service/neptune/parameter_group.go index 31aabf7d8f9..8ea1ed86110 100644 --- a/internal/service/neptune/parameter_group.go +++ b/internal/service/neptune/parameter_group.go @@ -18,13 +18,15 @@ import ( 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" ) // We can only modify 20 parameters at a time, so walk them until // we've got them all. const maxParams = 20 -// @SDKResource("aws_neptune_parameter_group") +// @SDKResource("aws_neptune_parameter_group", name="Parameter Group") +// @Tags(identifierAttribute="arn") func ResourceParameterGroup() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceParameterGroupCreate, @@ -83,8 +85,8 @@ func ResourceParameterGroup() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -94,14 +96,12 @@ func ResourceParameterGroup() *schema.Resource { func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) createOpts := neptune.CreateDBParameterGroupInput{ DBParameterGroupName: aws.String(d.Get("name").(string)), DBParameterGroupFamily: aws.String(d.Get("family").(string)), Description: aws.String(d.Get("description").(string)), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), } log.Printf("[DEBUG] Create Neptune Parameter Group: %#v", createOpts) @@ -120,8 +120,6 @@ func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, m func resourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig describeOpts := neptune.DescribeDBParameterGroupsInput{ DBParameterGroupName: aws.String(d.Id()), @@ -172,23 +170,6 @@ func resourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "setting parameter: %s", err) } - tags, err := ListTags(ctx, conn, d.Get("arn").(string)) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Neptune Parameter Group (%s): %s", d.Get("arn").(string), err) - } - - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } @@ -267,14 +248,6 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m } } - if !d.IsNewResource() && d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating Neptune Parameter Group (%s) tags: %s", d.Get("arn").(string), err) - } - } - return append(diags, resourceParameterGroupRead(ctx, d, meta)...) } diff --git a/internal/service/neptune/service_package_gen.go b/internal/service/neptune/service_package_gen.go index 3423f8cb80f..bbc041d004e 100644 --- a/internal/service/neptune/service_package_gen.go +++ b/internal/service/neptune/service_package_gen.go @@ -37,18 +37,34 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceCluster, TypeName: "aws_neptune_cluster", + Name: "Cluster", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceClusterEndpoint, TypeName: "aws_neptune_cluster_endpoint", + Name: "Cluster Endpoint", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceClusterInstance, TypeName: "aws_neptune_cluster_instance", + Name: "Cluster", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceClusterParameterGroup, TypeName: "aws_neptune_cluster_parameter_group", + Name: "Cluster Parameter Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceClusterSnapshot, @@ -57,6 +73,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceEventSubscription, TypeName: "aws_neptune_event_subscription", + Name: "Event Subscription", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceGlobalCluster, @@ -65,10 +85,18 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceParameterGroup, TypeName: "aws_neptune_parameter_group", + Name: "Parameter Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceSubnetGroup, TypeName: "aws_neptune_subnet_group", + Name: "Subnet Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, } } diff --git a/internal/service/neptune/subnet_group.go b/internal/service/neptune/subnet_group.go index 9aa84c6f47e..47f7d3f21e1 100644 --- a/internal/service/neptune/subnet_group.go +++ b/internal/service/neptune/subnet_group.go @@ -17,9 +17,11 @@ import ( 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_neptune_subnet_group") +// @SDKResource("aws_neptune_subnet_group", name="Subnet Group") +// @Tags(identifierAttribute="arn") func ResourceSubnetGroup() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceSubnetGroupCreate, @@ -63,8 +65,8 @@ func ResourceSubnetGroup() *schema.Resource { MinItems: 1, Elem: &schema.Schema{Type: schema.TypeString}, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -74,15 +76,13 @@ func ResourceSubnetGroup() *schema.Resource { func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := create.Name(d.Get("name").(string), d.Get("name_prefix").(string)) input := &neptune.CreateDBSubnetGroupInput{ DBSubnetGroupName: aws.String(name), DBSubnetGroupDescription: aws.String(d.Get("description").(string)), SubnetIds: flex.ExpandStringSet(d.Get("subnet_ids").(*schema.Set)), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), } output, err := conn.CreateDBSubnetGroupWithContext(ctx, input) @@ -99,8 +99,6 @@ func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).NeptuneConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig subnetGroup, err := FindSubnetGroupByName(ctx, conn, d.Id()) @@ -125,23 +123,6 @@ func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta i } d.Set("subnet_ids", subnetIDs) - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Neptune Subnet Group (%s): %s", arn, err) - } - - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } @@ -163,14 +144,6 @@ func resourceSubnetGroupUpdate(ctx context.Context, d *schema.ResourceData, meta } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating Neptune Subnet Group (%s) tags: %s", d.Id(), err) - } - } - return append(diags, resourceSubnetGroupRead(ctx, d, meta)...) } From 85d5b30f48de5c9386a0df71ce1bf72c0ab8c51e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 5 Apr 2023 17:37:24 -0400 Subject: [PATCH 2/3] Remove tagging boilerplate for Plugin SDK resources - networkfirewall. --- internal/service/networkfirewall/firewall.go | 36 ++++--------------- .../networkfirewall/firewall_policy.go | 36 ++++--------------- .../service/networkfirewall/rule_group.go | 36 ++++--------------- .../networkfirewall/service_package_gen.go | 12 +++++++ 4 files changed, 33 insertions(+), 87 deletions(-) diff --git a/internal/service/networkfirewall/firewall.go b/internal/service/networkfirewall/firewall.go index ca4de7a6f07..4a6d2bf654a 100644 --- a/internal/service/networkfirewall/firewall.go +++ b/internal/service/networkfirewall/firewall.go @@ -20,9 +20,11 @@ import ( 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_networkfirewall_firewall") +// @SDKResource("aws_networkfirewall_firewall", name="Firewall") +// @Tags(identifierAttribute="id") func ResourceFirewall() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceFirewallCreate, @@ -128,8 +130,8 @@ func ResourceFirewall() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "update_token": { Type: schema.TypeString, Computed: true, @@ -145,14 +147,13 @@ func ResourceFirewall() *schema.Resource { func resourceFirewallCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkFirewallConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &networkfirewall.CreateFirewallInput{ FirewallName: aws.String(name), FirewallPolicyArn: aws.String(d.Get("firewall_policy_arn").(string)), SubnetMappings: expandSubnetMappings(d.Get("subnet_mapping").(*schema.Set).List()), + Tags: GetTagsIn(ctx), VpcId: aws.String(d.Get("vpc_id").(string)), } @@ -176,10 +177,6 @@ func resourceFirewallCreate(ctx context.Context, d *schema.ResourceData, meta in input.SubnetChangeProtection = aws.Bool(v.(bool)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - output, err := conn.CreateFirewallWithContext(ctx, input) if err != nil { @@ -197,8 +194,6 @@ func resourceFirewallCreate(ctx context.Context, d *schema.ResourceData, meta in func resourceFirewallRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkFirewallConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig output, err := FindFirewallByARN(ctx, conn, d.Id()) @@ -232,16 +227,7 @@ func resourceFirewallRead(ctx context.Context, d *schema.ResourceData, meta inte d.Set("update_token", output.UpdateToken) d.Set("vpc_id", firewall.VpcId) - tags := KeyValueTags(ctx, firewall.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, firewall.Tags) return nil } @@ -394,14 +380,6 @@ func resourceFirewallUpdate(ctx context.Context, d *schema.ResourceData, meta in } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Id(), o, n); err != nil { - return diag.Errorf("updating NetworkFirewall Firewall (%s) tags: %s", d.Id(), err) - } - } - return resourceFirewallRead(ctx, d, meta) } diff --git a/internal/service/networkfirewall/firewall_policy.go b/internal/service/networkfirewall/firewall_policy.go index 3ab3fe781b0..8a5553300d5 100644 --- a/internal/service/networkfirewall/firewall_policy.go +++ b/internal/service/networkfirewall/firewall_policy.go @@ -18,9 +18,11 @@ import ( 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_networkfirewall_firewall_policy") +// @SDKResource("aws_networkfirewall_firewall_policy", name="Firewall Policy") +// @Tags(identifierAttribute="id") func ResourceFirewallPolicy() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceFirewallPolicyCreate, @@ -136,8 +138,8 @@ func ResourceFirewallPolicy() *schema.Resource { Required: true, ForceNew: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "update_token": { Type: schema.TypeString, Computed: true, @@ -157,13 +159,12 @@ func ResourceFirewallPolicy() *schema.Resource { func resourceFirewallPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkFirewallConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &networkfirewall.CreateFirewallPolicyInput{ FirewallPolicy: expandFirewallPolicy(d.Get("firewall_policy").([]interface{})), FirewallPolicyName: aws.String(d.Get("name").(string)), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("description"); ok { @@ -173,10 +174,6 @@ func resourceFirewallPolicyCreate(ctx context.Context, d *schema.ResourceData, m input.EncryptionConfiguration = expandEncryptionConfiguration(v.([]interface{})) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - output, err := conn.CreateFirewallPolicyWithContext(ctx, input) if err != nil { @@ -190,8 +187,6 @@ func resourceFirewallPolicyCreate(ctx context.Context, d *schema.ResourceData, m func resourceFirewallPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkFirewallConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig output, err := FindFirewallPolicyByARN(ctx, conn, d.Id()) @@ -215,16 +210,7 @@ func resourceFirewallPolicyRead(ctx context.Context, d *schema.ResourceData, met d.Set("name", response.FirewallPolicyName) d.Set("update_token", output.UpdateToken) - tags := KeyValueTags(ctx, response.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, response.Tags) return nil } @@ -254,14 +240,6 @@ func resourceFirewallPolicyUpdate(ctx context.Context, d *schema.ResourceData, m } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Id(), o, n); err != nil { - return diag.Errorf("updating NetworkFirewall Firewall Policy (%s) tags: %s", d.Id(), err) - } - } - return resourceFirewallPolicyRead(ctx, d, meta) } diff --git a/internal/service/networkfirewall/rule_group.go b/internal/service/networkfirewall/rule_group.go index 006e185d890..77f24cfc2c2 100644 --- a/internal/service/networkfirewall/rule_group.go +++ b/internal/service/networkfirewall/rule_group.go @@ -19,9 +19,11 @@ import ( 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_networkfirewall_rule_group") +// @SDKResource("aws_networkfirewall_rule_group", name="Rule Group") +// @Tags(identifierAttribute="id") func ResourceRuleGroup() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRuleGroupCreate, @@ -428,8 +430,8 @@ func ResourceRuleGroup() *schema.Resource { Type: schema.TypeString, Optional: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "type": { Type: schema.TypeString, Required: true, @@ -454,13 +456,12 @@ func ResourceRuleGroup() *schema.Resource { func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkFirewallConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &networkfirewall.CreateRuleGroupInput{ Capacity: aws.Int64(int64(d.Get("capacity").(int))), RuleGroupName: aws.String(name), + Tags: GetTagsIn(ctx), Type: aws.String(d.Get("type").(string)), } @@ -480,10 +481,6 @@ func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta i input.Rules = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - output, err := conn.CreateRuleGroupWithContext(ctx, input) if err != nil { @@ -497,8 +494,6 @@ func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta i func resourceRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkFirewallConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig output, err := FindRuleGroupByARN(ctx, conn, d.Id()) @@ -528,16 +523,7 @@ func resourceRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta int d.Set("type", response.Type) d.Set("update_token", output.UpdateToken) - tags := KeyValueTags(ctx, response.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, response.Tags) return nil } @@ -590,14 +576,6 @@ func resourceRuleGroupUpdate(ctx context.Context, d *schema.ResourceData, meta i } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Id(), o, n); err != nil { - return diag.Errorf("updating NetworkFirewall Rule Group (%s) tags: %s", d.Id(), err) - } - } - return resourceRuleGroupRead(ctx, d, meta) } diff --git a/internal/service/networkfirewall/service_package_gen.go b/internal/service/networkfirewall/service_package_gen.go index 3e1f6f86b4d..ce316bf53d3 100644 --- a/internal/service/networkfirewall/service_package_gen.go +++ b/internal/service/networkfirewall/service_package_gen.go @@ -37,10 +37,18 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceFirewall, TypeName: "aws_networkfirewall_firewall", + Name: "Firewall", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "id", + }, }, { Factory: ResourceFirewallPolicy, TypeName: "aws_networkfirewall_firewall_policy", + Name: "Firewall Policy", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "id", + }, }, { Factory: ResourceLoggingConfiguration, @@ -53,6 +61,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceRuleGroup, TypeName: "aws_networkfirewall_rule_group", + Name: "Rule Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "id", + }, }, } } From f9fa9caf0569f0b2afb46c0ef243b8b4f9e20327 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 5 Apr 2023 17:37:24 -0400 Subject: [PATCH 3/3] Remove tagging boilerplate for Plugin SDK resources - networkmanager. --- .../networkmanager/connect_attachment.go | 39 ++++----------- .../service/networkmanager/connect_peer.go | 38 ++++----------- internal/service/networkmanager/connection.go | 37 +++----------- .../service/networkmanager/core_network.go | 39 +++------------ internal/service/networkmanager/device.go | 37 +++----------- .../service/networkmanager/global_network.go | 39 ++++----------- internal/service/networkmanager/link.go | 36 +++----------- .../networkmanager/service_package_gen.go | 48 +++++++++++++++++++ internal/service/networkmanager/site.go | 36 +++----------- .../site_to_site_vpn_attachment.go | 38 ++++----------- .../networkmanager/transit_gateway_peering.go | 39 ++++----------- .../transit_gateway_route_table_attachment.go | 39 ++++----------- .../service/networkmanager/vpc_attachment.go | 36 +++----------- 13 files changed, 139 insertions(+), 362 deletions(-) diff --git a/internal/service/networkmanager/connect_attachment.go b/internal/service/networkmanager/connect_attachment.go index 9536316d292..014043615d8 100644 --- a/internal/service/networkmanager/connect_attachment.go +++ b/internal/service/networkmanager/connect_attachment.go @@ -19,9 +19,11 @@ import ( 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_networkmanager_connect_attachment") +// @SDKResource("aws_networkmanager_connect_attachment", name="Connect Attachment") +// @Tags(identifierAttribute="arn") func ResourceConnectAttachment() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceConnectAttachmentCreate, @@ -109,8 +111,8 @@ func ResourceConnectAttachment() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "transport_attachment_id": { Type: schema.TypeString, Required: true, @@ -126,8 +128,6 @@ func ResourceConnectAttachment() *schema.Resource { func resourceConnectAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) coreNetworkID := d.Get("core_network_id").(string) edgeLocation := d.Get("edge_location").(string) @@ -141,13 +141,10 @@ func resourceConnectAttachmentCreate(ctx context.Context, d *schema.ResourceData CoreNetworkId: aws.String(coreNetworkID), EdgeLocation: aws.String(edgeLocation), Options: options, + Tags: GetTagsIn(ctx), TransportAttachmentId: aws.String(transportAttachmentID), } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - outputRaw, err := tfresource.RetryWhen(ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { return conn.CreateConnectAttachmentWithContext(ctx, input) @@ -192,8 +189,6 @@ func resourceConnectAttachmentCreate(ctx context.Context, d *schema.ResourceData func resourceConnectAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig connectAttachment, err := FindConnectAttachmentByID(ctx, conn, d.Id()) @@ -234,31 +229,13 @@ func resourceConnectAttachmentRead(ctx context.Context, d *schema.ResourceData, d.Set("state", a.State) d.Set("transport_attachment_id", connectAttachment.TransportAttachmentId) - tags := KeyValueTags(ctx, a.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, a.Tags) return nil } func resourceConnectAttachmentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).NetworkManagerConn() - - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.FromErr(fmt.Errorf("updating Network Manager Connect Attachment (%s) tags: %s", d.Get("arn").(string), err)) - } - } - + // Tags only. return resourceConnectAttachmentRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/connect_peer.go b/internal/service/networkmanager/connect_peer.go index b94c219b410..ed32aa0412b 100644 --- a/internal/service/networkmanager/connect_peer.go +++ b/internal/service/networkmanager/connect_peer.go @@ -22,9 +22,11 @@ import ( 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_networkmanager_connect_peer") +// @SDKResource("aws_networkmanager_connect_peer", name="Connect Peer") +// @Tags(identifierAttribute="arn") func ResourceConnectPeer() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceConnectPeerCreate, @@ -169,16 +171,14 @@ func ResourceConnectPeer() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, } } func resourceConnectPeerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) connectAttachmentID := d.Get("connect_attachment_id").(string) insideCIDRBlocks := flex.ExpandStringList(d.Get("inside_cidr_blocks").([]interface{})) @@ -187,6 +187,7 @@ func resourceConnectPeerCreate(ctx context.Context, d *schema.ResourceData, meta ConnectAttachmentId: aws.String(connectAttachmentID), InsideCidrBlocks: insideCIDRBlocks, PeerAddress: aws.String(peerAddress), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("bgp_options"); ok && len(v.([]interface{})) > 0 { @@ -197,10 +198,6 @@ func resourceConnectPeerCreate(ctx context.Context, d *schema.ResourceData, meta input.CoreNetworkAddress = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - outputRaw, err := tfresource.RetryWhen(ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { return conn.CreateConnectPeerWithContext(ctx, input) @@ -242,8 +239,6 @@ func resourceConnectPeerCreate(ctx context.Context, d *schema.ResourceData, meta func resourceConnectPeerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig connectPeer, err := FindConnectPeerByID(ctx, conn, d.Id()) @@ -281,30 +276,13 @@ func resourceConnectPeerRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("peer_address", connectPeer.Configuration.PeerAddress) d.Set("state", connectPeer.State) - tags := KeyValueTags(ctx, connectPeer.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("settings tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, connectPeer.Tags) return nil } func resourceConnectPeerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).NetworkManagerConn() - - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("updating Network Manager Connect Peer (%s) tags: %s", d.Get("arn").(string), err) - } - } - + // Tags only. return resourceConnectPeerRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/connection.go b/internal/service/networkmanager/connection.go index 0f1b651b98a..c8f7dc825d5 100644 --- a/internal/service/networkmanager/connection.go +++ b/internal/service/networkmanager/connection.go @@ -19,9 +19,11 @@ import ( 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_networkmanager_connection") +// @SDKResource("aws_networkmanager_connection", name="Connection") +// @Tags(identifierAttribute="arn") func ResourceConnection() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceConnectionCreate, @@ -92,23 +94,21 @@ func ResourceConnection() *schema.Resource { Type: schema.TypeString, Optional: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, } } func resourceConnectionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) globalNetworkID := d.Get("global_network_id").(string) - input := &networkmanager.CreateConnectionInput{ ConnectedDeviceId: aws.String(d.Get("connected_device_id").(string)), DeviceId: aws.String(d.Get("device_id").(string)), GlobalNetworkId: aws.String(globalNetworkID), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("connected_link_id"); ok { @@ -123,10 +123,6 @@ func resourceConnectionCreate(ctx context.Context, d *schema.ResourceData, meta input.LinkId = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - log.Printf("[DEBUG] Creating Network Manager Connection: %s", input) output, err := conn.CreateConnectionWithContext(ctx, input) @@ -145,8 +141,6 @@ func resourceConnectionCreate(ctx context.Context, d *schema.ResourceData, meta func resourceConnectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig globalNetworkID := d.Get("global_network_id").(string) connection, err := FindConnectionByTwoPartKey(ctx, conn, globalNetworkID, d.Id()) @@ -169,16 +163,7 @@ func resourceConnectionRead(ctx context.Context, d *schema.ResourceData, meta in d.Set("global_network_id", connection.GlobalNetworkId) d.Set("link_id", connection.LinkId) - tags := KeyValueTags(ctx, connection.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("error setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("error setting tags_all: %s", err) - } + SetTagsOut(ctx, connection.Tags) return nil } @@ -208,14 +193,6 @@ func resourceConnectionUpdate(ctx context.Context, d *schema.ResourceData, meta } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("error updating Network Manager Connection (%s) tags: %s", d.Id(), err) - } - } - return resourceConnectionRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/core_network.go b/internal/service/networkmanager/core_network.go index bd4a5cd91fb..5b644e36cca 100644 --- a/internal/service/networkmanager/core_network.go +++ b/internal/service/networkmanager/core_network.go @@ -22,6 +22,7 @@ import ( 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" ) const ( @@ -29,9 +30,8 @@ const ( coreNetworkStatePending = "PENDING" ) -// This resource is explicitly NOT exported from the provider until design is finalized. -// Its Delete handler is used by sweepers. -// @SDKResource("aws_networkmanager_core_network") +// @SDKResource("aws_networkmanager_core_network", name="Core Network") +// @Tags(identifierAttribute="arn") func ResourceCoreNetwork() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceCoreNetworkCreate, @@ -161,22 +161,20 @@ func ResourceCoreNetwork() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, } } func resourceCoreNetworkCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) globalNetworkID := d.Get("global_network_id").(string) - input := &networkmanager.CreateCoreNetworkInput{ ClientToken: aws.String(id.UniqueId()), GlobalNetworkId: aws.String(globalNetworkID), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("description"); ok { @@ -207,10 +205,6 @@ func resourceCoreNetworkCreate(ctx context.Context, d *schema.ResourceData, meta input.PolicyDocument = aws.String(policyDocumentTarget) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - output, err := conn.CreateCoreNetworkWithContext(ctx, input) if err != nil { @@ -228,8 +222,6 @@ func resourceCoreNetworkCreate(ctx context.Context, d *schema.ResourceData, meta func resourceCoreNetworkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig coreNetwork, err := FindCoreNetworkByID(ctx, conn, d.Id()) @@ -277,16 +269,7 @@ func resourceCoreNetworkRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("policy_document", encodedPolicyDocument) } - tags := KeyValueTags(ctx, coreNetwork.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, coreNetwork.Tags) return nil } @@ -349,14 +332,6 @@ func resourceCoreNetworkUpdate(ctx context.Context, d *schema.ResourceData, meta } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("updating Network Manager Core Network (%s) tags: %s", d.Id(), err) - } - } - return resourceCoreNetworkRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/device.go b/internal/service/networkmanager/device.go index d952bbf4324..818a92d89c6 100644 --- a/internal/service/networkmanager/device.go +++ b/internal/service/networkmanager/device.go @@ -19,9 +19,11 @@ import ( 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_networkmanager_device") +// @SDKResource("aws_networkmanager_device", name="Device") +// @Tags(identifierAttribute="arn") func ResourceDevice() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceDeviceCreate, @@ -132,8 +134,8 @@ func ResourceDevice() *schema.Resource { Type: schema.TypeString, Optional: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "type": { Type: schema.TypeString, Optional: true, @@ -150,13 +152,11 @@ func ResourceDevice() *schema.Resource { func resourceDeviceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) globalNetworkID := d.Get("global_network_id").(string) - input := &networkmanager.CreateDeviceInput{ GlobalNetworkId: aws.String(globalNetworkID), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("description"); ok { @@ -191,10 +191,6 @@ func resourceDeviceCreate(ctx context.Context, d *schema.ResourceData, meta inte input.Vendor = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - log.Printf("[DEBUG] Creating Network Manager Device: %s", input) output, err := conn.CreateDeviceWithContext(ctx, input) @@ -213,8 +209,6 @@ func resourceDeviceCreate(ctx context.Context, d *schema.ResourceData, meta inte func resourceDeviceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig globalNetworkID := d.Get("global_network_id").(string) device, err := FindDeviceByTwoPartKey(ctx, conn, globalNetworkID, d.Id()) @@ -252,16 +246,7 @@ func resourceDeviceRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set("type", device.Type) d.Set("vendor", device.Vendor) - tags := KeyValueTags(ctx, device.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("error setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("error setting tags_all: %s", err) - } + SetTagsOut(ctx, device.Tags) return nil } @@ -302,14 +287,6 @@ func resourceDeviceUpdate(ctx context.Context, d *schema.ResourceData, meta inte } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("error updating Network Manager Device (%s) tags: %s", d.Id(), err) - } - } - return resourceDeviceRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/global_network.go b/internal/service/networkmanager/global_network.go index 4c78c208540..cb8e2ed1a02 100644 --- a/internal/service/networkmanager/global_network.go +++ b/internal/service/networkmanager/global_network.go @@ -16,9 +16,11 @@ import ( 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_networkmanager_global_network") +// @SDKResource("aws_networkmanager_global_network", name="Global Network") +// @Tags(identifierAttribute="arn") func ResourceGlobalNetwork() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceGlobalNetworkCreate, @@ -48,27 +50,23 @@ func ResourceGlobalNetwork() *schema.Resource { Optional: true, ValidateFunc: validation.StringLenBetween(0, 256), }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, } } func resourceGlobalNetworkCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) - input := &networkmanager.CreateGlobalNetworkInput{} + input := &networkmanager.CreateGlobalNetworkInput{ + Tags: GetTagsIn(ctx), + } if v, ok := d.GetOk("description"); ok { input.Description = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - log.Printf("[DEBUG] Creating Network Manager Global Network: %s", input) output, err := conn.CreateGlobalNetworkWithContext(ctx, input) @@ -87,8 +85,6 @@ func resourceGlobalNetworkCreate(ctx context.Context, d *schema.ResourceData, me func resourceGlobalNetworkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig globalNetwork, err := FindGlobalNetworkByID(ctx, conn, d.Id()) @@ -105,16 +101,7 @@ func resourceGlobalNetworkRead(ctx context.Context, d *schema.ResourceData, meta d.Set("arn", globalNetwork.GlobalNetworkArn) d.Set("description", globalNetwork.Description) - tags := KeyValueTags(ctx, globalNetwork.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("error setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("error setting tags_all: %s", err) - } + SetTagsOut(ctx, globalNetwork.Tags) return nil } @@ -140,14 +127,6 @@ func resourceGlobalNetworkUpdate(ctx context.Context, d *schema.ResourceData, me } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("error updating Network Manager Global Network (%s) tags: %s", d.Id(), err) - } - } - return resourceGlobalNetworkRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/link.go b/internal/service/networkmanager/link.go index 577a1eab8ca..cd12b761e61 100644 --- a/internal/service/networkmanager/link.go +++ b/internal/service/networkmanager/link.go @@ -19,9 +19,11 @@ import ( 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_networkmanager_link") +// @SDKResource("aws_networkmanager_link", name="Link") +// @Tags(identifierAttribute="arn") func ResourceLink() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceLinkCreate, @@ -101,8 +103,8 @@ func ResourceLink() *schema.Resource { Required: true, ForceNew: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "type": { Type: schema.TypeString, Optional: true, @@ -114,13 +116,12 @@ func ResourceLink() *schema.Resource { func resourceLinkCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) globalNetworkID := d.Get("global_network_id").(string) input := &networkmanager.CreateLinkInput{ GlobalNetworkId: aws.String(globalNetworkID), SiteId: aws.String(d.Get("site_id").(string)), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("bandwidth"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { @@ -139,10 +140,6 @@ func resourceLinkCreate(ctx context.Context, d *schema.ResourceData, meta interf input.Type = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - log.Printf("[DEBUG] Creating Network Manager Link: %s", input) output, err := conn.CreateLinkWithContext(ctx, input) @@ -161,8 +158,6 @@ func resourceLinkCreate(ctx context.Context, d *schema.ResourceData, meta interf func resourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig globalNetworkID := d.Get("global_network_id").(string) link, err := FindLinkByTwoPartKey(ctx, conn, globalNetworkID, d.Id()) @@ -191,16 +186,7 @@ func resourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interfac d.Set("site_id", link.SiteId) d.Set("type", link.Type) - tags := KeyValueTags(ctx, link.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("error setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("error setting tags_all: %s", err) - } + SetTagsOut(ctx, link.Tags) return nil } @@ -234,14 +220,6 @@ func resourceLinkUpdate(ctx context.Context, d *schema.ResourceData, meta interf } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("error updating Network Manager Link (%s) tags: %s", d.Id(), err) - } - } - return resourceLinkRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/service_package_gen.go b/internal/service/networkmanager/service_package_gen.go index 293c10378f3..d86064f1006 100644 --- a/internal/service/networkmanager/service_package_gen.go +++ b/internal/service/networkmanager/service_package_gen.go @@ -77,18 +77,34 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceConnectAttachment, TypeName: "aws_networkmanager_connect_attachment", + Name: "Connect Attachment", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceConnectPeer, TypeName: "aws_networkmanager_connect_peer", + Name: "Connect Peer", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceConnection, TypeName: "aws_networkmanager_connection", + Name: "Connection", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceCoreNetwork, TypeName: "aws_networkmanager_core_network", + Name: "Core Network", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceCoreNetworkPolicyAttachment, @@ -101,14 +117,26 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceDevice, TypeName: "aws_networkmanager_device", + Name: "Device", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceGlobalNetwork, TypeName: "aws_networkmanager_global_network", + Name: "Global Network", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceLink, TypeName: "aws_networkmanager_link", + Name: "Link", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceLinkAssociation, @@ -117,10 +145,18 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceSite, TypeName: "aws_networkmanager_site", + Name: "Site", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceSiteToSiteVPNAttachment, TypeName: "aws_networkmanager_site_to_site_vpn_attachment", + Name: "Site To Site VPN Attachment", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceTransitGatewayConnectPeerAssociation, @@ -129,6 +165,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceTransitGatewayPeering, TypeName: "aws_networkmanager_transit_gateway_peering", + Name: "Transit Gateway Peering", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceTransitGatewayRegistration, @@ -137,10 +177,18 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceTransitGatewayRouteTableAttachment, TypeName: "aws_networkmanager_transit_gateway_route_table_attachment", + Name: "Transit Gateway Route Table Attachment", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceVPCAttachment, TypeName: "aws_networkmanager_vpc_attachment", + Name: "VPC Attachment", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, } } diff --git a/internal/service/networkmanager/site.go b/internal/service/networkmanager/site.go index 7b603256e69..7f6623ea2c0 100644 --- a/internal/service/networkmanager/site.go +++ b/internal/service/networkmanager/site.go @@ -19,9 +19,11 @@ import ( 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_networkmanager_site") +// @SDKResource("aws_networkmanager_site", name="Site") +// @Tags(identifierAttribute="arn") func ResourceSite() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceSiteCreate, @@ -98,20 +100,19 @@ func ResourceSite() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, } } func resourceSiteCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) globalNetworkID := d.Get("global_network_id").(string) input := &networkmanager.CreateSiteInput{ GlobalNetworkId: aws.String(globalNetworkID), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("description"); ok { @@ -122,10 +123,6 @@ func resourceSiteCreate(ctx context.Context, d *schema.ResourceData, meta interf input.Location = expandLocation(v.([]interface{})[0].(map[string]interface{})) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - log.Printf("[DEBUG] Creating Network Manager Site: %s", input) output, err := conn.CreateSiteWithContext(ctx, input) @@ -144,8 +141,6 @@ func resourceSiteCreate(ctx context.Context, d *schema.ResourceData, meta interf func resourceSiteRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig globalNetworkID := d.Get("global_network_id").(string) site, err := FindSiteByTwoPartKey(ctx, conn, globalNetworkID, d.Id()) @@ -171,16 +166,7 @@ func resourceSiteRead(ctx context.Context, d *schema.ResourceData, meta interfac d.Set("location", nil) } - tags := KeyValueTags(ctx, site.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("error setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("error setting tags_all: %s", err) - } + SetTagsOut(ctx, site.Tags) return nil } @@ -212,14 +198,6 @@ func resourceSiteUpdate(ctx context.Context, d *schema.ResourceData, meta interf } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("error updating Network Manager Site (%s) tags: %s", d.Id(), err) - } - } - return resourceSiteRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/site_to_site_vpn_attachment.go b/internal/service/networkmanager/site_to_site_vpn_attachment.go index 36076c5c9e5..f7d6fc84aea 100644 --- a/internal/service/networkmanager/site_to_site_vpn_attachment.go +++ b/internal/service/networkmanager/site_to_site_vpn_attachment.go @@ -19,9 +19,11 @@ import ( 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_networkmanager_site_to_site_vpn_attachment") +// @SDKResource("aws_networkmanager_site_to_site_vpn_attachment", name="Site To Site VPN Attachment") +// @Tags(identifierAttribute="arn") func ResourceSiteToSiteVPNAttachment() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceSiteToSiteVPNAttachmentCreate, @@ -83,8 +85,8 @@ func ResourceSiteToSiteVPNAttachment() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "vpn_connection_arn": { Type: schema.TypeString, Required: true, @@ -97,20 +99,15 @@ func ResourceSiteToSiteVPNAttachment() *schema.Resource { func resourceSiteToSiteVPNAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) coreNetworkID := d.Get("core_network_id").(string) vpnConnectionARN := d.Get("vpn_connection_arn").(string) input := &networkmanager.CreateSiteToSiteVpnAttachmentInput{ CoreNetworkId: aws.String(coreNetworkID), + Tags: GetTagsIn(ctx), VpnConnectionArn: aws.String(vpnConnectionARN), } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - output, err := conn.CreateSiteToSiteVpnAttachmentWithContext(ctx, input) if err != nil { @@ -128,8 +125,6 @@ func resourceSiteToSiteVPNAttachmentCreate(ctx context.Context, d *schema.Resour func resourceSiteToSiteVPNAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig vpnAttachment, err := FindSiteToSiteVPNAttachmentByID(ctx, conn, d.Id()) @@ -162,30 +157,13 @@ func resourceSiteToSiteVPNAttachmentRead(ctx context.Context, d *schema.Resource d.Set("state", a.State) d.Set("vpn_connection_arn", a.ResourceArn) - tags := KeyValueTags(ctx, a.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, a.Tags) return nil } func resourceSiteToSiteVPNAttachmentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).NetworkManagerConn() - - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.FromErr(fmt.Errorf("updating Network Manager Site To Site VPN Attachment (%s) tags: %s", d.Get("arn").(string), err)) - } - } - + // Tags only. return resourceSiteToSiteVPNAttachmentRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/transit_gateway_peering.go b/internal/service/networkmanager/transit_gateway_peering.go index 227e9da4fd3..b2c4b64b23e 100644 --- a/internal/service/networkmanager/transit_gateway_peering.go +++ b/internal/service/networkmanager/transit_gateway_peering.go @@ -17,9 +17,11 @@ import ( 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_networkmanager_transit_gateway_peering") +// @SDKResource("aws_networkmanager_transit_gateway_peering", name="Transit Gateway Peering") +// @Tags(identifierAttribute="arn") func ResourceTransitGatewayPeering() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceTransitGatewayPeeringCreate, @@ -68,8 +70,8 @@ func ResourceTransitGatewayPeering() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "transit_gateway_arn": { Type: schema.TypeString, Required: true, @@ -86,20 +88,15 @@ func ResourceTransitGatewayPeering() *schema.Resource { func resourceTransitGatewayPeeringCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) coreNetworkID := d.Get("core_network_id").(string) transitGatewayARN := d.Get("transit_gateway_arn").(string) input := &networkmanager.CreateTransitGatewayPeeringInput{ CoreNetworkId: aws.String(coreNetworkID), + Tags: GetTagsIn(ctx), TransitGatewayArn: aws.String(transitGatewayARN), } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - log.Printf("[DEBUG] Creating Network Manager Transit Gateway Peering: %s", input) output, err := conn.CreateTransitGatewayPeeringWithContext(ctx, input) @@ -118,8 +115,6 @@ func resourceTransitGatewayPeeringCreate(ctx context.Context, d *schema.Resource func resourceTransitGatewayPeeringRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig transitGatewayPeering, err := FindTransitGatewayPeeringByID(ctx, conn, d.Id()) @@ -150,31 +145,13 @@ func resourceTransitGatewayPeeringRead(ctx context.Context, d *schema.ResourceDa d.Set("transit_gateway_arn", transitGatewayPeering.TransitGatewayArn) d.Set("transit_gateway_peering_attachment_id", transitGatewayPeering.TransitGatewayPeeringAttachmentId) - tags := KeyValueTags(ctx, p.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("Setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, p.Tags) return nil } func resourceTransitGatewayPeeringUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).NetworkManagerConn() - - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("updating Network Manager Transit Gateway Peering (%s) tags: %s", d.Id(), err) - } - } - + // Tags only. return resourceTransitGatewayPeeringRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/transit_gateway_route_table_attachment.go b/internal/service/networkmanager/transit_gateway_route_table_attachment.go index 2323ebd9773..c7c09a16c93 100644 --- a/internal/service/networkmanager/transit_gateway_route_table_attachment.go +++ b/internal/service/networkmanager/transit_gateway_route_table_attachment.go @@ -17,9 +17,11 @@ import ( 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_networkmanager_transit_gateway_route_table_attachment") +// @SDKResource("aws_networkmanager_transit_gateway_route_table_attachment", name="Transit Gateway Route Table Attachment") +// @Tags(identifierAttribute="arn") func ResourceTransitGatewayRouteTableAttachment() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceTransitGatewayRouteTableAttachmentCreate, @@ -84,8 +86,8 @@ func ResourceTransitGatewayRouteTableAttachment() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "transit_gateway_route_table_arn": { Type: schema.TypeString, Required: true, @@ -98,20 +100,15 @@ func ResourceTransitGatewayRouteTableAttachment() *schema.Resource { func resourceTransitGatewayRouteTableAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) peeringID := d.Get("peering_id").(string) transitGatewayRouteTableARN := d.Get("transit_gateway_route_table_arn").(string) input := &networkmanager.CreateTransitGatewayRouteTableAttachmentInput{ PeeringId: aws.String(peeringID), + Tags: GetTagsIn(ctx), TransitGatewayRouteTableArn: aws.String(transitGatewayRouteTableARN), } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - log.Printf("[DEBUG] Creating Network Manager Transit Gateway Route Table Attachment: %s", input) output, err := conn.CreateTransitGatewayRouteTableAttachmentWithContext(ctx, input) @@ -130,8 +127,6 @@ func resourceTransitGatewayRouteTableAttachmentCreate(ctx context.Context, d *sc func resourceTransitGatewayRouteTableAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig transitGatewayRouteTableAttachment, err := FindTransitGatewayRouteTableAttachmentByID(ctx, conn, d.Id()) @@ -165,31 +160,13 @@ func resourceTransitGatewayRouteTableAttachmentRead(ctx context.Context, d *sche d.Set("state", a.State) d.Set("transit_gateway_route_table_arn", transitGatewayRouteTableAttachment.TransitGatewayRouteTableArn) - tags := KeyValueTags(ctx, a.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("Setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, a.Tags) return nil } func resourceTransitGatewayRouteTableAttachmentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).NetworkManagerConn() - - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("updating Network Manager Transit Gateway Route Table Attachment (%s) tags: %s", d.Id(), err) - } - } - + // Tags only. return resourceTransitGatewayRouteTableAttachmentRead(ctx, d, meta) } diff --git a/internal/service/networkmanager/vpc_attachment.go b/internal/service/networkmanager/vpc_attachment.go index dfaaa4199ac..937aa661e74 100644 --- a/internal/service/networkmanager/vpc_attachment.go +++ b/internal/service/networkmanager/vpc_attachment.go @@ -18,9 +18,11 @@ import ( 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_networkmanager_vpc_attachment") +// @SDKResource("aws_networkmanager_vpc_attachment", name="VPC Attachment") +// @Tags(identifierAttribute="arn") func ResourceVPCAttachment() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceVPCAttachmentCreate, @@ -108,8 +110,8 @@ func ResourceVPCAttachment() *schema.Resource { ValidateFunc: verify.ValidARN, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "vpc_arn": { Type: schema.TypeString, Required: true, @@ -122,14 +124,13 @@ func ResourceVPCAttachment() *schema.Resource { func resourceVPCAttachmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) coreNetworkID := d.Get("core_network_id").(string) vpcARN := d.Get("vpc_arn").(string) input := &networkmanager.CreateVpcAttachmentInput{ CoreNetworkId: aws.String(coreNetworkID), SubnetArns: flex.ExpandStringSet(d.Get("subnet_arns").(*schema.Set)), + Tags: GetTagsIn(ctx), VpcArn: aws.String(vpcARN), } @@ -137,10 +138,6 @@ func resourceVPCAttachmentCreate(ctx context.Context, d *schema.ResourceData, me input.Options = expandVpcOptions(v.([]interface{})[0].(map[string]interface{})) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - log.Printf("[DEBUG] Creating Network Manager VPC Attachment: %s", input) output, err := conn.CreateVpcAttachmentWithContext(ctx, input) @@ -159,8 +156,6 @@ func resourceVPCAttachmentCreate(ctx context.Context, d *schema.ResourceData, me func resourceVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).NetworkManagerConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig vpcAttachment, err := FindVPCAttachmentByID(ctx, conn, d.Id()) @@ -201,16 +196,7 @@ func resourceVPCAttachmentRead(ctx context.Context, d *schema.ResourceData, meta d.Set("subnet_arns", aws.StringValueSlice(vpcAttachment.SubnetArns)) d.Set("vpc_arn", a.ResourceArn) - tags := KeyValueTags(ctx, a.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("Setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) - } + SetTagsOut(ctx, a.Tags) return nil } @@ -260,14 +246,6 @@ func resourceVPCAttachmentUpdate(ctx context.Context, d *schema.ResourceData, me } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("updating Network Manager VPC Attachment (%s) tags: %s", d.Id(), err) - } - } - return resourceVPCAttachmentRead(ctx, d, meta) }