diff --git a/internal/service/waf/rate_based_rule.go b/internal/service/waf/rate_based_rule.go index 42b5f01322b..c47958da0a4 100644 --- a/internal/service/waf/rate_based_rule.go +++ b/internal/service/waf/rate_based_rule.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_waf_rate_based_rule") +// @SDKResource("aws_waf_rate_based_rule", name="Rate Based Rule") +// @Tags(identifierAttribute="arn") func ResourceRateBasedRule() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRateBasedRuleCreate, @@ -79,8 +81,8 @@ func ResourceRateBasedRule() *schema.Resource { Required: true, ValidateFunc: validation.IntAtLeast(100), }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -90,8 +92,6 @@ func ResourceRateBasedRule() *schema.Resource { func resourceRateBasedRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &waf.CreateRateBasedRuleInput{ @@ -99,16 +99,13 @@ func resourceRateBasedRuleCreate(ctx context.Context, d *schema.ResourceData, me Name: aws.String(name), RateKey: aws.String(d.Get("rate_key").(string)), RateLimit: aws.Int64(int64(d.Get("rate_limit").(int))), + Tags: GetTagsIn(ctx), } wr := NewRetryer(conn) outputRaw, err := wr.RetryWithToken(ctx, func(token *string) (interface{}, error) { input.ChangeToken = token - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - return conn.CreateRateBasedRuleWithContext(ctx, input) }) @@ -135,8 +132,6 @@ func resourceRateBasedRuleCreate(ctx context.Context, d *schema.ResourceData, me func resourceRateBasedRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig rule, err := FindRateBasedRuleByID(ctx, conn, d.Id()) @@ -177,23 +172,6 @@ func resourceRateBasedRuleRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "setting predicates: %s", err) } - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for WAF Rate Based Rule (%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 } @@ -213,14 +191,6 @@ func resourceRateBasedRuleUpdate(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 sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceRateBasedRuleRead(ctx, d, meta)...) } diff --git a/internal/service/waf/rule.go b/internal/service/waf/rule.go index fd5ed204226..f814aa26426 100644 --- a/internal/service/waf/rule.go +++ b/internal/service/waf/rule.go @@ -20,13 +20,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" ) const ( RuleDeleteTimeout = 5 * time.Minute ) -// @SDKResource("aws_waf_rule") +// @SDKResource("aws_waf_rule", name="Rule") +// @Tags(identifierAttribute="arn") func ResourceRule() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRuleCreate, @@ -71,8 +73,8 @@ func ResourceRule() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "arn": { Type: schema.TypeString, Computed: true, @@ -86,22 +88,17 @@ func ResourceRule() *schema.Resource { func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) wr := NewRetryer(conn) out, err := wr.RetryWithToken(ctx, func(token *string) (interface{}, error) { - params := &waf.CreateRuleInput{ + input := &waf.CreateRuleInput{ ChangeToken: token, MetricName: aws.String(d.Get("metric_name").(string)), Name: aws.String(d.Get("name").(string)), + Tags: GetTagsIn(ctx), } - if len(tags) > 0 { - params.Tags = Tags(tags.IgnoreAWS()) - } - - return conn.CreateRuleWithContext(ctx, params) + return conn.CreateRuleWithContext(ctx, input) }) if err != nil { @@ -126,8 +123,6 @@ func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interf func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig params := &waf.GetRuleInput{ RuleId: aws.String(d.Id()), @@ -172,24 +167,6 @@ func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interfac Resource: fmt.Sprintf("rule/%s", d.Id()), }.String() d.Set("arn", arn) - - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for WAF Rule (%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) - } - d.Set("predicates", predicates) d.Set("name", resp.Rule.Name) d.Set("metric_name", resp.Rule.MetricName) @@ -211,14 +188,6 @@ func resourceRuleUpdate(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 sdkdiag.AppendErrorf(diags, "updating WAF Rule (%s) tags: %s", d.Id(), err) - } - } - return append(diags, resourceRuleRead(ctx, d, meta)...) } diff --git a/internal/service/waf/rule_group.go b/internal/service/waf/rule_group.go index 8f47a64a4e1..1c2e4d5ca67 100644 --- a/internal/service/waf/rule_group.go +++ b/internal/service/waf/rule_group.go @@ -15,9 +15,11 @@ 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" ) -// @SDKResource("aws_waf_rule_group") +// @SDKResource("aws_waf_rule_group", name="Rule Group") +// @Tags(identifierAttribute="arn") func ResourceRuleGroup() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRuleGroupCreate, @@ -74,8 +76,8 @@ func ResourceRuleGroup() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "arn": { Type: schema.TypeString, Computed: true, @@ -89,22 +91,17 @@ func ResourceRuleGroup() *schema.Resource { func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) wr := NewRetryer(conn) out, err := wr.RetryWithToken(ctx, func(token *string) (interface{}, error) { - params := &waf.CreateRuleGroupInput{ + input := &waf.CreateRuleGroupInput{ ChangeToken: token, MetricName: aws.String(d.Get("metric_name").(string)), Name: aws.String(d.Get("name").(string)), + Tags: GetTagsIn(ctx), } - if len(tags) > 0 { - params.Tags = Tags(tags.IgnoreAWS()) - } - - return conn.CreateRuleGroupWithContext(ctx, params) + return conn.CreateRuleGroupWithContext(ctx, input) }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating WAF Rule Group (%s): %s", d.Get("name").(string), err) @@ -128,8 +125,6 @@ func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta i func resourceRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig params := &waf.GetRuleGroupInput{ RuleGroupId: aws.String(d.Id()), @@ -160,23 +155,6 @@ func resourceRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta int Resource: fmt.Sprintf("rulegroup/%s", d.Id()), }.String() d.Set("arn", arn) - - tags, err := ListTags(ctx, conn, arn) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for WAF Rule 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) - } - d.Set("activated_rule", FlattenActivatedRules(rResp.ActivatedRules)) d.Set("name", resp.RuleGroup.Name) d.Set("metric_name", resp.RuleGroup.MetricName) @@ -198,14 +176,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.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceRuleGroupRead(ctx, d, meta)...) } diff --git a/internal/service/waf/service_package_gen.go b/internal/service/waf/service_package_gen.go index a259b2e571a..1f1edab6e31 100644 --- a/internal/service/waf/service_package_gen.go +++ b/internal/service/waf/service_package_gen.go @@ -61,6 +61,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceRateBasedRule, TypeName: "aws_waf_rate_based_rule", + Name: "Rate Based Rule", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceRegexMatchSet, @@ -73,10 +77,18 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceRule, TypeName: "aws_waf_rule", + Name: "Rule", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceRuleGroup, TypeName: "aws_waf_rule_group", + Name: "Rule Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceSizeConstraintSet, @@ -89,6 +101,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceWebACL, TypeName: "aws_waf_web_acl", + Name: "Web ACL", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceXSSMatchSet, diff --git a/internal/service/waf/web_acl.go b/internal/service/waf/web_acl.go index a75c285fb3d..9e27b42fac3 100644 --- a/internal/service/waf/web_acl.go +++ b/internal/service/waf/web_acl.go @@ -17,9 +17,11 @@ 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" ) -// @SDKResource("aws_waf_web_acl") +// @SDKResource("aws_waf_web_acl", name="Web ACL") +// @Tags(identifierAttribute="arn") func ResourceWebACL() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceWebACLCreate, @@ -145,8 +147,8 @@ func ResourceWebACL() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -156,23 +158,18 @@ func ResourceWebACL() *schema.Resource { func resourceWebACLCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) wr := NewRetryer(conn) out, err := wr.RetryWithToken(ctx, func(token *string) (interface{}, error) { - params := &waf.CreateWebACLInput{ + input := &waf.CreateWebACLInput{ ChangeToken: token, DefaultAction: ExpandAction(d.Get("default_action").([]interface{})), MetricName: aws.String(d.Get("metric_name").(string)), Name: aws.String(d.Get("name").(string)), + Tags: GetTagsIn(ctx), } - if len(tags) > 0 { - params.Tags = Tags(tags.IgnoreAWS()) - } - - return conn.CreateWebACLWithContext(ctx, params) + return conn.CreateWebACLWithContext(ctx, input) }) if err != nil { @@ -224,8 +221,6 @@ func resourceWebACLCreate(ctx context.Context, d *schema.ResourceData, meta inte func resourceWebACLRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig params := &waf.GetWebACLInput{ WebACLId: aws.String(d.Id()), @@ -260,23 +255,6 @@ func resourceWebACLRead(ctx context.Context, d *schema.ResourceData, meta interf } d.Set("name", resp.WebACL.Name) d.Set("metric_name", resp.WebACL.MetricName) - - tags, err := ListTags(ctx, conn, arn) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for WAF Web ACL (%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) - } - if err := d.Set("rules", FlattenWebACLRules(resp.WebACL.Rules)); err != nil { return sdkdiag.AppendErrorf(diags, "setting rules: %s", err) } @@ -348,14 +326,6 @@ func resourceWebACLUpdate(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 sdkdiag.AppendErrorf(diags, "updating WAF Web ACL (%s) tags: %s", d.Id(), err) - } - } - return append(diags, resourceWebACLRead(ctx, d, meta)...) } diff --git a/internal/service/wafregional/rate_based_rule.go b/internal/service/wafregional/rate_based_rule.go index 31698ca16a9..efe199b2b96 100644 --- a/internal/service/wafregional/rate_based_rule.go +++ b/internal/service/wafregional/rate_based_rule.go @@ -18,9 +18,11 @@ import ( tfwaf "github.com/hashicorp/terraform-provider-aws/internal/service/waf" 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_wafregional_rate_based_rule") +// @SDKResource("aws_wafregional_rate_based_rule", name="Rate Based Rule") +// @Tags(identifierAttribute="arn") func ResourceRateBasedRule() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRateBasedRuleCreate, @@ -74,8 +76,8 @@ func ResourceRateBasedRule() *schema.Resource { Required: true, ValidateFunc: validation.IntAtLeast(100), }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "arn": { Type: schema.TypeString, Computed: true, @@ -89,25 +91,20 @@ func ResourceRateBasedRule() *schema.Resource { func resourceRateBasedRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFRegionalConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) region := meta.(*conns.AWSClient).Region wr := NewRetryer(conn, region) out, err := wr.RetryWithToken(ctx, func(token *string) (interface{}, error) { - params := &waf.CreateRateBasedRuleInput{ + input := &waf.CreateRateBasedRuleInput{ ChangeToken: token, MetricName: aws.String(d.Get("metric_name").(string)), Name: aws.String(d.Get("name").(string)), RateKey: aws.String(d.Get("rate_key").(string)), RateLimit: aws.Int64(int64(d.Get("rate_limit").(int))), + Tags: GetTagsIn(ctx), } - if len(tags) > 0 { - params.Tags = Tags(tags.IgnoreAWS()) - } - - return conn.CreateRateBasedRuleWithContext(ctx, params) + return conn.CreateRateBasedRuleWithContext(ctx, input) }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating WAF Regional Rate Based Rule (%s): %s", d.Get("name").(string), err) @@ -130,8 +127,6 @@ func resourceRateBasedRuleCreate(ctx context.Context, d *schema.ResourceData, me func resourceRateBasedRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFRegionalConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig params := &waf.GetRateBasedRuleInput{ RuleId: aws.String(d.Id()), @@ -165,23 +160,6 @@ func resourceRateBasedRuleRead(ctx context.Context, d *schema.ResourceData, meta Service: "waf-regional", }.String() d.Set("arn", arn) - - tagList, err := ListTags(ctx, conn, arn) - if err != nil { - return sdkdiag.AppendErrorf(diags, "to get WAF Regional Rated Based Rule parameter tags for %s: %s", d.Get("name"), err) - } - - tags := tagList.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) - } - d.Set("predicate", predicates) d.Set("name", resp.Rule.Name) d.Set("metric_name", resp.Rule.MetricName) @@ -207,14 +185,6 @@ func resourceRateBasedRuleUpdate(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 sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceRateBasedRuleRead(ctx, d, meta)...) } diff --git a/internal/service/wafregional/rule.go b/internal/service/wafregional/rule.go index 82518411875..b2d9a7f372a 100644 --- a/internal/service/wafregional/rule.go +++ b/internal/service/wafregional/rule.go @@ -18,9 +18,11 @@ import ( tfwaf "github.com/hashicorp/terraform-provider-aws/internal/service/waf" 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_wafregional_rule") +// @SDKResource("aws_wafregional_rule", name="Rule") +// @Tags(identifierAttribute="arn") func ResourceRule() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRuleCreate, @@ -64,8 +66,8 @@ func ResourceRule() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "arn": { Type: schema.TypeString, Computed: true, @@ -79,23 +81,18 @@ func ResourceRule() *schema.Resource { func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFRegionalConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) region := meta.(*conns.AWSClient).Region wr := NewRetryer(conn, region) out, err := wr.RetryWithToken(ctx, func(token *string) (interface{}, error) { - params := &waf.CreateRuleInput{ + input := &waf.CreateRuleInput{ ChangeToken: token, MetricName: aws.String(d.Get("metric_name").(string)), Name: aws.String(d.Get("name").(string)), + Tags: GetTagsIn(ctx), } - if len(tags) > 0 { - params.Tags = Tags(tags.IgnoreAWS()) - } - - return conn.CreateRuleWithContext(ctx, params) + return conn.CreateRuleWithContext(ctx, input) }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating WAF Regional Rule (%s): %s", d.Get("name").(string), err) @@ -117,8 +114,6 @@ func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interf func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFRegionalConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig params := &waf.GetRuleInput{ RuleId: aws.String(d.Id()), @@ -143,24 +138,6 @@ func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interfac Service: "waf-regional", }.String() d.Set("arn", arn) - - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for WAF Regional Rule (%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) - } - d.Set("predicate", flattenPredicates(resp.Rule.Predicates)) d.Set("name", resp.Rule.Name) d.Set("metric_name", resp.Rule.MetricName) @@ -170,7 +147,6 @@ func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interfac func resourceRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).WAFRegionalConn() if d.HasChange("predicate") { o, n := d.GetChange("predicate") @@ -182,14 +158,6 @@ func resourceRuleUpdate(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 sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceRuleRead(ctx, d, meta)...) } diff --git a/internal/service/wafregional/rule_group.go b/internal/service/wafregional/rule_group.go index 22674ae0d71..4cef341aeb2 100644 --- a/internal/service/wafregional/rule_group.go +++ b/internal/service/wafregional/rule_group.go @@ -17,9 +17,11 @@ import ( tfwaf "github.com/hashicorp/terraform-provider-aws/internal/service/waf" 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_wafregional_rule_group") +// @SDKResource("aws_wafregional_rule_group", name="Rule Group") +// @Tags(identifierAttribute="arn") func ResourceRuleGroup() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRuleGroupCreate, @@ -76,8 +78,8 @@ func ResourceRuleGroup() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "arn": { Type: schema.TypeString, Computed: true, @@ -91,23 +93,18 @@ func ResourceRuleGroup() *schema.Resource { func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFRegionalConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) region := meta.(*conns.AWSClient).Region wr := NewRetryer(conn, region) out, err := wr.RetryWithToken(ctx, func(token *string) (interface{}, error) { - params := &waf.CreateRuleGroupInput{ + input := &waf.CreateRuleGroupInput{ ChangeToken: token, MetricName: aws.String(d.Get("metric_name").(string)), Name: aws.String(d.Get("name").(string)), + Tags: GetTagsIn(ctx), } - if len(tags) > 0 { - params.Tags = Tags(tags.IgnoreAWS()) - } - - return conn.CreateRuleGroupWithContext(ctx, params) + return conn.CreateRuleGroupWithContext(ctx, input) }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating WAF Regional Rule Group (%s): %s", d.Get("name").(string), err) @@ -131,8 +128,6 @@ func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta i func resourceRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFRegionalConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig params := &waf.GetRuleGroupInput{ RuleGroupId: aws.String(d.Id()), @@ -164,22 +159,6 @@ func resourceRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta int Service: "waf-regional", }.String() d.Set("arn", arn) - - tags, err := ListTags(ctx, conn, arn) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for WAF Regional Rule 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) - } - d.Set("activated_rule", tfwaf.FlattenActivatedRules(rResp.ActivatedRules)) d.Set("name", resp.RuleGroup.Name) d.Set("metric_name", resp.RuleGroup.MetricName) @@ -202,14 +181,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.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceRuleGroupRead(ctx, d, meta)...) } diff --git a/internal/service/wafregional/service_package_gen.go b/internal/service/wafregional/service_package_gen.go index c9c51aafb48..4b56a51f731 100644 --- a/internal/service/wafregional/service_package_gen.go +++ b/internal/service/wafregional/service_package_gen.go @@ -61,6 +61,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceRateBasedRule, TypeName: "aws_wafregional_rate_based_rule", + Name: "Rate Based Rule", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceRegexMatchSet, @@ -73,10 +77,18 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceRule, TypeName: "aws_wafregional_rule", + Name: "Rule", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceRuleGroup, TypeName: "aws_wafregional_rule_group", + Name: "Rule Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceSizeConstraintSet, @@ -89,6 +101,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceWebACL, TypeName: "aws_wafregional_web_acl", + Name: "Web ACL", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceWebACLAssociation, diff --git a/internal/service/wafregional/web_acl.go b/internal/service/wafregional/web_acl.go index 18a95727000..fe33c96d504 100644 --- a/internal/service/wafregional/web_acl.go +++ b/internal/service/wafregional/web_acl.go @@ -18,9 +18,11 @@ import ( tfwaf "github.com/hashicorp/terraform-provider-aws/internal/service/waf" 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_wafregional_web_acl") +// @SDKResource("aws_wafregional_web_acl", name="Web ACL") +// @Tags(identifierAttribute="arn") func ResourceWebACL() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceWebACLCreate, @@ -165,8 +167,8 @@ func ResourceWebACL() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -176,24 +178,19 @@ func ResourceWebACL() *schema.Resource { func resourceWebACLCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFRegionalConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) region := meta.(*conns.AWSClient).Region wr := NewRetryer(conn, region) out, err := wr.RetryWithToken(ctx, func(token *string) (interface{}, error) { - params := &waf.CreateWebACLInput{ + input := &waf.CreateWebACLInput{ ChangeToken: token, DefaultAction: tfwaf.ExpandAction(d.Get("default_action").([]interface{})), MetricName: aws.String(d.Get("metric_name").(string)), Name: aws.String(d.Get("name").(string)), + Tags: GetTagsIn(ctx), } - if len(tags) > 0 { - params.Tags = Tags(tags.IgnoreAWS()) - } - - return conn.CreateWebACLWithContext(ctx, params) + return conn.CreateWebACLWithContext(ctx, input) }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating WAF Regional Web ACL (%s): %s", d.Get("name").(string), err) @@ -249,8 +246,6 @@ func resourceWebACLCreate(ctx context.Context, d *schema.ResourceData, meta inte func resourceWebACLRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WAFRegionalConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig params := &waf.GetWebACLInput{ WebACLId: aws.String(d.Id()), @@ -295,22 +290,6 @@ func resourceWebACLRead(ctx context.Context, d *schema.ResourceData, meta interf return sdkdiag.AppendErrorf(diags, "setting rule: %s", err) } - tags, err := ListTags(ctx, conn, webACLARN) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for WAF Regional ACL (%s): %s", webACLARN, 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) - } - getLoggingConfigurationInput := &waf.GetLoggingConfigurationInput{ ResourceArn: aws.String(d.Get("arn").(string)), } diff --git a/internal/service/wafv2/ip_set.go b/internal/service/wafv2/ip_set.go index 8b965a777bf..a873d1485f7 100644 --- a/internal/service/wafv2/ip_set.go +++ b/internal/service/wafv2/ip_set.go @@ -19,13 +19,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" ) const ( ipSetDeleteTimeout = 5 * time.Minute ) -// @SDKResource("aws_wafv2_ip_set") +// @SDKResource("aws_wafv2_ip_set", name="IP Set") +// @Tags(identifierAttribute="arn") func ResourceIPSet() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceIPSetCreate, @@ -110,8 +112,8 @@ func ResourceIPSet() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false), }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -120,8 +122,6 @@ func ResourceIPSet() *schema.Resource { func resourceIPSetCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).WAFV2Conn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &wafv2.CreateIPSetInput{ @@ -129,6 +129,7 @@ func resourceIPSetCreate(ctx context.Context, d *schema.ResourceData, meta inter IPAddressVersion: aws.String(d.Get("ip_address_version").(string)), Name: aws.String(name), Scope: aws.String(d.Get("scope").(string)), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("addresses"); ok && v.(*schema.Set).Len() > 0 { @@ -139,11 +140,6 @@ func resourceIPSetCreate(ctx context.Context, d *schema.ResourceData, meta inter input.Description = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - - log.Printf("[INFO] Creating WAFv2 IPSet: %s", input) output, err := conn.CreateIPSetWithContext(ctx, input) if err != nil { @@ -157,8 +153,6 @@ func resourceIPSetCreate(ctx context.Context, d *schema.ResourceData, meta inter func resourceIPSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).WAFV2Conn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig output, err := FindIPSetByThreePartKey(ctx, conn, d.Id(), d.Get("name").(string), d.Get("scope").(string)) @@ -181,23 +175,6 @@ func resourceIPSetRead(ctx context.Context, d *schema.ResourceData, meta interfa d.Set("lock_token", output.LockToken) d.Set("name", ipSet.Name) - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return diag.Errorf("listing tags for WAFv2 IPSet (%s): %s", arn, err) - } - - tags = 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) - } - return nil } @@ -229,15 +206,6 @@ func resourceIPSetUpdate(ctx context.Context, d *schema.ResourceData, meta inter } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - arn := d.Get("arn").(string) - - if err := UpdateTags(ctx, conn, arn, o, n); err != nil { - return diag.Errorf("updating tags for WAFv2 IPSet (%s): %s", arn, err) - } - } - return resourceIPSetRead(ctx, d, meta) } diff --git a/internal/service/wafv2/regex_pattern_set.go b/internal/service/wafv2/regex_pattern_set.go index ef10e4d435e..9e4a4544160 100644 --- a/internal/service/wafv2/regex_pattern_set.go +++ b/internal/service/wafv2/regex_pattern_set.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" ) const ( regexPatternSetDeleteTimeout = 5 * time.Minute ) -// @SDKResource("aws_wafv2_regex_pattern_set") +// @SDKResource("aws_wafv2_regex_pattern_set", name="Regex Pattern Set") +// @Tags(identifierAttribute="arn") func ResourceRegexPatternSet() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRegexPatternSetCreate, @@ -91,8 +93,8 @@ func ResourceRegexPatternSet() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false), }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -101,14 +103,13 @@ func ResourceRegexPatternSet() *schema.Resource { func resourceRegexPatternSetCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).WAFV2Conn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &wafv2.CreateRegexPatternSetInput{ Name: aws.String(name), RegularExpressionList: []*wafv2.Regex{}, Scope: aws.String(d.Get("scope").(string)), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("description"); ok { @@ -119,11 +120,6 @@ func resourceRegexPatternSetCreate(ctx context.Context, d *schema.ResourceData, input.RegularExpressionList = expandRegexPatternSet(v.(*schema.Set).List()) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - - log.Printf("[INFO] Creating WAFv2 RegexPatternSet: %s", input) output, err := conn.CreateRegexPatternSetWithContext(ctx, input) if err != nil { @@ -137,8 +133,6 @@ func resourceRegexPatternSetCreate(ctx context.Context, d *schema.ResourceData, func resourceRegexPatternSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).WAFV2Conn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig output, err := FindRegexPatternSetByThreePartKey(ctx, conn, d.Id(), d.Get("name").(string), d.Get("scope").(string)) @@ -162,23 +156,6 @@ func resourceRegexPatternSetRead(ctx context.Context, d *schema.ResourceData, me return diag.Errorf("setting regular_expression: %s", err) } - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return diag.Errorf("listing tags for WAFv2 RegexPatternSet (%s): %s", arn, err) - } - - tags = 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) - } - return nil } @@ -210,15 +187,6 @@ func resourceRegexPatternSetUpdate(ctx context.Context, d *schema.ResourceData, } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - arn := d.Get("arn").(string) - - if err := UpdateTags(ctx, conn, arn, o, n); err != nil { - return diag.Errorf("updating tags for WAFv2 RegexPatternSet (%s): %s", arn, err) - } - } - return resourceRegexPatternSetRead(ctx, d, meta) } diff --git a/internal/service/wafv2/rule_group.go b/internal/service/wafv2/rule_group.go index e0310de9108..edd90ce69d9 100644 --- a/internal/service/wafv2/rule_group.go +++ b/internal/service/wafv2/rule_group.go @@ -19,6 +19,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 ( @@ -27,7 +28,8 @@ const ( ruleGroupDeleteTimeout = 5 * time.Minute ) -// @SDKResource("aws_wafv2_rule_group") +// @SDKResource("aws_wafv2_rule_group", name="Rule Group") +// @Tags(identifierAttribute="arn") func ResourceRuleGroup() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRuleGroupCreate, @@ -120,8 +122,8 @@ func ResourceRuleGroup() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false), }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "visibility_config": visibilityConfigSchema(), }, @@ -131,8 +133,6 @@ func ResourceRuleGroup() *schema.Resource { func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).WAFV2Conn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &wafv2.CreateRuleGroupInput{ @@ -140,6 +140,7 @@ func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta i Name: aws.String(name), Rules: expandRules(d.Get("rule").(*schema.Set).List()), Scope: aws.String(d.Get("scope").(string)), + Tags: GetTagsIn(ctx), VisibilityConfig: expandVisibilityConfig(d.Get("visibility_config").([]interface{})), } @@ -151,11 +152,6 @@ func resourceRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta i input.Description = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - - log.Printf("[INFO] Creating WAFv2 RuleGroup: %s", input) outputRaw, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, ruleGroupCreateTimeout, func() (interface{}, error) { return conn.CreateRuleGroupWithContext(ctx, input) }, wafv2.ErrCodeWAFUnavailableEntityException) @@ -173,8 +169,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).WAFV2Conn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig output, err := FindRuleGroupByThreePartKey(ctx, conn, d.Id(), d.Get("name").(string), d.Get("scope").(string)) @@ -189,7 +183,6 @@ func resourceRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta int } ruleGroup := output.RuleGroup - arn := aws.StringValue(ruleGroup.ARN) d.Set("arn", ruleGroup.ARN) d.Set("capacity", ruleGroup.Capacity) if err := d.Set("custom_response_body", flattenCustomResponseBodies(ruleGroup.CustomResponseBodies)); err != nil { @@ -205,23 +198,6 @@ func resourceRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta int return diag.Errorf("setting visibility_config: %s", err) } - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return diag.Errorf("listing tags for WAFv2 RuleGroup (%s): %s", arn, err) - } - - tags = 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) - } - return nil } @@ -256,15 +232,6 @@ func resourceRuleGroupUpdate(ctx context.Context, d *schema.ResourceData, meta i } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - arn := d.Get("arn").(string) - - if err := UpdateTags(ctx, conn, arn, o, n); err != nil { - return diag.Errorf("updating tags for WAFv2 RuleGroup (%s): %s", arn, err) - } - } - return resourceRuleGroupRead(ctx, d, meta) } diff --git a/internal/service/wafv2/service_package_gen.go b/internal/service/wafv2/service_package_gen.go index fef8613eff2..3f1beb5df66 100644 --- a/internal/service/wafv2/service_package_gen.go +++ b/internal/service/wafv2/service_package_gen.go @@ -45,18 +45,34 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceIPSet, TypeName: "aws_wafv2_ip_set", + Name: "IP Set", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceRegexPatternSet, TypeName: "aws_wafv2_regex_pattern_set", + Name: "Regex Pattern Set", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceRuleGroup, TypeName: "aws_wafv2_rule_group", + Name: "Rule Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceWebACL, TypeName: "aws_wafv2_web_acl", + Name: "Web ACL", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceWebACLAssociation, diff --git a/internal/service/wafv2/web_acl.go b/internal/service/wafv2/web_acl.go index 01e2d2db4ee..6daf3703bb4 100644 --- a/internal/service/wafv2/web_acl.go +++ b/internal/service/wafv2/web_acl.go @@ -19,6 +19,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 ( @@ -27,7 +28,8 @@ const ( webACLDeleteTimeout = 5 * time.Minute ) -// @SDKResource("aws_wafv2_web_acl") +// @SDKResource("aws_wafv2_web_acl", name="Web ACL") +// @Tags(identifierAttribute="arn") func ResourceWebACL() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceWebACLCreate, @@ -141,8 +143,8 @@ func ResourceWebACL() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false), }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "visibility_config": visibilityConfigSchema(), }, @@ -152,8 +154,6 @@ func ResourceWebACL() *schema.Resource { func resourceWebACLCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).WAFV2Conn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &wafv2.CreateWebACLInput{ @@ -161,6 +161,7 @@ func resourceWebACLCreate(ctx context.Context, d *schema.ResourceData, meta inte Name: aws.String(name), Rules: expandWebACLRules(d.Get("rule").(*schema.Set).List()), Scope: aws.String(d.Get("scope").(string)), + Tags: GetTagsIn(ctx), VisibilityConfig: expandVisibilityConfig(d.Get("visibility_config").([]interface{})), } @@ -172,10 +173,6 @@ func resourceWebACLCreate(ctx context.Context, d *schema.ResourceData, meta inte input.Description = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - outputRaw, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, webACLCreateTimeout, func() (interface{}, error) { return conn.CreateWebACLWithContext(ctx, input) }, wafv2.ErrCodeWAFUnavailableEntityException) @@ -193,8 +190,6 @@ func resourceWebACLCreate(ctx context.Context, d *schema.ResourceData, meta inte func resourceWebACLRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).WAFV2Conn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig output, err := FindWebACLByThreePartKey(ctx, conn, d.Id(), d.Get("name").(string), d.Get("scope").(string)) @@ -229,23 +224,6 @@ func resourceWebACLRead(ctx context.Context, d *schema.ResourceData, meta interf return diag.Errorf("setting visibility_config: %s", err) } - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return diag.Errorf("listing tags for WAFv2 WebACL (%s): %s", arn, err) - } - - tags = 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) - } - return nil } @@ -284,15 +262,6 @@ func resourceWebACLUpdate(ctx context.Context, d *schema.ResourceData, meta inte } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - arn := d.Get("arn").(string) - - if err := UpdateTags(ctx, conn, arn, o, n); err != nil { - return diag.Errorf("updating tags for WAFv2 WebACL (%s): %s", arn, err) - } - } - return resourceWebACLRead(ctx, d, meta) } diff --git a/internal/service/workspaces/directory.go b/internal/service/workspaces/directory.go index a64297cd5ef..ea51475eccd 100644 --- a/internal/service/workspaces/directory.go +++ b/internal/service/workspaces/directory.go @@ -16,18 +16,22 @@ 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_workspaces_directory") +// @SDKResource("aws_workspaces_directory", name="Directory") +// @Tags(identifierAttribute="id") func ResourceDirectory() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceDirectoryCreate, ReadWithoutTimeout: resourceDirectoryRead, UpdateWithoutTimeout: resourceDirectoryUpdate, DeleteWithoutTimeout: resourceDirectoryDelete, + Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, + Schema: map[string]*schema.Schema{ "alias": { Type: schema.TypeString, @@ -111,8 +115,8 @@ func ResourceDirectory() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "workspace_access_properties": { Type: schema.TypeList, Computed: true, @@ -209,16 +213,14 @@ func ResourceDirectory() *schema.Resource { func resourceDirectoryCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WorkSpacesConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) - directoryID := d.Get("directory_id").(string) + directoryID := d.Get("directory_id").(string) input := &workspaces.RegisterWorkspaceDirectoryInput{ DirectoryId: aws.String(directoryID), EnableSelfService: aws.Bool(false), // this is handled separately below EnableWorkDocs: aws.Bool(false), Tenancy: aws.String(workspaces.TenancyShared), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("subnet_ids"); ok { @@ -301,8 +303,6 @@ func resourceDirectoryCreate(ctx context.Context, d *schema.ResourceData, meta i func resourceDirectoryRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WorkSpacesConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig directory, err := FindDirectoryByID(ctx, conn, d.Id()) @@ -347,22 +347,6 @@ func resourceDirectoryRead(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendErrorf(diags, "setting dns_ip_addresses: %s", err) } - tags, err := ListTags(ctx, conn, d.Id()) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags: %s", 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 } @@ -440,13 +424,6 @@ func resourceDirectoryUpdate(ctx context.Context, d *schema.ResourceData, meta i log.Printf("[INFO] Updated WorkSpaces Directory (%s) IP Groups", d.Id()) } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - if err := UpdateTags(ctx, conn, d.Id(), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceDirectoryRead(ctx, d, meta)...) } diff --git a/internal/service/workspaces/ip_group.go b/internal/service/workspaces/ip_group.go index 30fa6553c66..b66064b7b60 100644 --- a/internal/service/workspaces/ip_group.go +++ b/internal/service/workspaces/ip_group.go @@ -13,9 +13,11 @@ 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" ) -// @SDKResource("aws_workspaces_ip_group") +// @SDKResource("aws_workspaces_ip_group", name="IP Group") +// @Tags(identifierAttribute="id") func ResourceIPGroup() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceIPGroupCreate, @@ -54,8 +56,8 @@ func ResourceIPGroup() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -65,17 +67,15 @@ func ResourceIPGroup() *schema.Resource { func resourceIPGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WorkSpacesConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) rules := d.Get("rules").(*schema.Set).List() - resp, err := conn.CreateIpGroupWithContext(ctx, &workspaces.CreateIpGroupInput{ GroupName: aws.String(d.Get("name").(string)), GroupDesc: aws.String(d.Get("description").(string)), UserRules: expandIPGroupRules(rules), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), }) + if err != nil { return sdkdiag.AppendErrorf(diags, "creating WorkSpaces IP Group: %s", err) } @@ -88,8 +88,6 @@ func resourceIPGroupCreate(ctx context.Context, d *schema.ResourceData, meta int func resourceIPGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WorkSpacesConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig resp, err := conn.DescribeIpGroupsWithContext(ctx, &workspaces.DescribeIpGroupsInput{ GroupIds: []*string{aws.String(d.Id())}, @@ -118,22 +116,6 @@ func resourceIPGroupRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("description", ipGroup.GroupDesc) d.Set("rules", flattenIPGroupRules(ipGroup.UserRules)) - tags, err := ListTags(ctx, conn, d.Id()) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for WorkSpaces IP 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 } @@ -153,13 +135,6 @@ func resourceIPGroupUpdate(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.Id(), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceIPGroupRead(ctx, d, meta)...) } diff --git a/internal/service/workspaces/service_package_gen.go b/internal/service/workspaces/service_package_gen.go index 9b901b243af..feca2acf6c2 100644 --- a/internal/service/workspaces/service_package_gen.go +++ b/internal/service/workspaces/service_package_gen.go @@ -45,14 +45,26 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceDirectory, TypeName: "aws_workspaces_directory", + Name: "Directory", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "id", + }, }, { Factory: ResourceIPGroup, TypeName: "aws_workspaces_ip_group", + Name: "IP Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "id", + }, }, { Factory: ResourceWorkspace, TypeName: "aws_workspaces_workspace", + Name: "Workspace", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "id", + }, }, } } diff --git a/internal/service/workspaces/workspace.go b/internal/service/workspaces/workspace.go index 27a71be827b..772b1e041e1 100644 --- a/internal/service/workspaces/workspace.go +++ b/internal/service/workspaces/workspace.go @@ -15,9 +15,11 @@ 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" ) -// @SDKResource("aws_workspaces_workspace") +// @SDKResource("aws_workspaces_workspace", name="Workspace") +// @Tags(identifierAttribute="id") func ResourceWorkspace() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceWorkspaceCreate, @@ -128,8 +130,8 @@ func ResourceWorkspace() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(WorkspaceAvailableTimeout), @@ -144,8 +146,6 @@ func ResourceWorkspace() *schema.Resource { func resourceWorkspaceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WorkSpacesConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) input := &workspaces.WorkspaceRequest{ BundleId: aws.String(d.Get("bundle_id").(string)), @@ -153,7 +153,7 @@ func resourceWorkspaceCreate(ctx context.Context, d *schema.ResourceData, meta i UserName: aws.String(d.Get("user_name").(string)), RootVolumeEncryptionEnabled: aws.Bool(d.Get("root_volume_encryption_enabled").(bool)), UserVolumeEncryptionEnabled: aws.Bool(d.Get("user_volume_encryption_enabled").(bool)), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("volume_encryption_key"); ok { @@ -188,8 +188,6 @@ func resourceWorkspaceCreate(ctx context.Context, d *schema.ResourceData, meta i func resourceWorkspaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).WorkSpacesConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig rawOutput, state, err := StatusWorkspaceState(ctx, conn, d.Id())() if err != nil { @@ -215,22 +213,6 @@ func resourceWorkspaceRead(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendErrorf(diags, "setting workspace properties: %s", err) } - tags, err := ListTags(ctx, conn, d.Id()) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags: %s", 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 } @@ -272,13 +254,6 @@ func resourceWorkspaceUpdate(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 sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceWorkspaceRead(ctx, d, meta)...) } diff --git a/internal/service/xray/group.go b/internal/service/xray/group.go index 092dfd98100..b6f0c96ff46 100644 --- a/internal/service/xray/group.go +++ b/internal/service/xray/group.go @@ -13,9 +13,11 @@ 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" ) -// @SDKResource("aws_xray_group") +// @SDKResource("aws_xray_group", name="Group") +// @Tags(identifierAttribute="arn") func ResourceGroup() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceGroupCreate, @@ -62,8 +64,8 @@ func ResourceGroup() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, } } @@ -71,14 +73,12 @@ func ResourceGroup() *schema.Resource { func resourceGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).XRayConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("group_name").(string) input := &xray.CreateGroupInput{ GroupName: aws.String(name), FilterExpression: aws.String(d.Get("filter_expression").(string)), - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("insights_configuration"); ok { @@ -99,8 +99,6 @@ func resourceGroupCreate(ctx context.Context, d *schema.ResourceData, meta inter func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).XRayConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig input := &xray.GetGroupInput{ GroupARN: aws.String(d.Id()), @@ -126,23 +124,6 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa return sdkdiag.AppendErrorf(diags, "setting insights_configuration: %s", err) } - tags, err := ListTags(ctx, conn, arn) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Xray Group (%q): %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 } @@ -168,14 +149,6 @@ func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, meta inter } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceGroupRead(ctx, d, meta)...) } diff --git a/internal/service/xray/sampling_rule.go b/internal/service/xray/sampling_rule.go index 31883dc0550..c272d3e11ed 100644 --- a/internal/service/xray/sampling_rule.go +++ b/internal/service/xray/sampling_rule.go @@ -6,6 +6,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/xray" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -14,9 +15,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_xray_sampling_rule") +// @SDKResource("aws_xray_sampling_rule", name="Sampling Rule") +// @Tags(identifierAttribute="arn") func ResourceSamplingRule() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceSamplingRuleCreate, @@ -98,8 +101,8 @@ func ResourceSamplingRule() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, } } @@ -107,8 +110,6 @@ func ResourceSamplingRule() *schema.Resource { func resourceSamplingRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).XRayConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) samplingRule := &xray.SamplingRule{ RuleName: aws.String(d.Get("rule_name").(string)), @@ -130,7 +131,7 @@ func resourceSamplingRuleCreate(ctx context.Context, d *schema.ResourceData, met params := &xray.CreateSamplingRuleInput{ SamplingRule: samplingRule, - Tags: Tags(tags.IgnoreAWS()), + Tags: GetTagsIn(ctx), } out, err := conn.CreateSamplingRuleWithContext(ctx, params) @@ -146,8 +147,6 @@ func resourceSamplingRuleCreate(ctx context.Context, d *schema.ResourceData, met func resourceSamplingRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).XRayConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig samplingRule, err := GetSamplingRule(ctx, conn, d.Id()) @@ -176,22 +175,6 @@ func resourceSamplingRuleRead(ctx context.Context, d *schema.ResourceData, meta d.Set("attributes", aws.StringValueMap(samplingRule.Attributes)) d.Set("arn", arn) - tags, err := ListTags(ctx, conn, arn) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Xray Sampling group (%q): %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 } @@ -199,13 +182,6 @@ func resourceSamplingRuleUpdate(ctx context.Context, d *schema.ResourceData, met var diags diag.Diagnostics conn := meta.(*conns.AWSClient).XRayConn() - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - if d.HasChanges("attributes", "priority", "fixed_rate", "reservoir_size", "service_name", "service_type", "host", "http_method", "url_path", "resource_arn") { samplingRuleUpdate := &xray.SamplingRuleUpdate{ @@ -249,11 +225,14 @@ func resourceSamplingRuleDelete(ctx context.Context, d *schema.ResourceData, met conn := meta.(*conns.AWSClient).XRayConn() log.Printf("[INFO] Deleting XRay Sampling Rule: %s", d.Id()) - - params := &xray.DeleteSamplingRuleInput{ + _, err := conn.DeleteSamplingRuleWithContext(ctx, &xray.DeleteSamplingRuleInput{ RuleName: aws.String(d.Id()), + }) + + if tfawserr.ErrMessageContains(err, xray.ErrCodeInvalidRequestException, "Sampling rule does not exist") { + return diags } - _, err := conn.DeleteSamplingRuleWithContext(ctx, params) + if err != nil { return sdkdiag.AppendErrorf(diags, "deleting XRay Sampling Rule: %s", d.Id()) } diff --git a/internal/service/xray/service_package_gen.go b/internal/service/xray/service_package_gen.go index 894406268ba..e3df7b361c3 100644 --- a/internal/service/xray/service_package_gen.go +++ b/internal/service/xray/service_package_gen.go @@ -32,10 +32,18 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceGroup, TypeName: "aws_xray_group", + Name: "Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceSamplingRule, TypeName: "aws_xray_sampling_rule", + Name: "Sampling Rule", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, } }