Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech debt: Reduce tags boilerplate code - Plugin SDK resources route53domains (Phase 3c) #30595

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 7 additions & 33 deletions internal/service/route53domains/registered_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,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_route53domains_registered_domain")
// @SDKResource("aws_route53domains_registered_domain", name="Registered Domain")
// @Tags(identifierAttribute="id")
func ResourceRegisteredDomain() *schema.Resource {
contactSchema := &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -215,9 +217,9 @@ func ResourceRegisteredDomain() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
"tech_contact": contactSchema,
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"tech_contact": contactSchema,
"tech_privacy": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -314,9 +316,8 @@ func resourceRegisteredDomainCreate(ctx context.Context, d *schema.ResourceData,
return diag.Errorf("error listing tags for Route 53 Domains Domain (%s): %s", d.Id(), err)
}

defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig
newTags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))).IgnoreConfig(ignoreTagsConfig)
newTags := KeyValueTags(ctx, GetTagsIn(ctx))
oldTags := tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

if !oldTags.Equal(newTags) {
Expand All @@ -330,8 +331,6 @@ func resourceRegisteredDomainCreate(ctx context.Context, d *schema.ResourceData,

func resourceRegisteredDomainRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).Route53DomainsClient()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

domainDetail, err := findDomainDetailByName(ctx, conn, d.Id())

Expand Down Expand Up @@ -399,23 +398,6 @@ func resourceRegisteredDomainRead(ctx context.Context, d *schema.ResourceData, m
}
d.Set("whois_server", domainDetail.WhoIsServer)

tags, err := ListTags(ctx, conn, d.Id())

if err != nil {
return diag.Errorf("error listing tags for Route 53 Domains Domain (%s): %s", d.Id(), err)
}

tags = 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)
}

return nil
}

Expand Down Expand Up @@ -474,14 +456,6 @@ func resourceRegisteredDomainUpdate(ctx context.Context, d *schema.ResourceData,
}
}

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("error updating Route 53 Domains Domain (%s) tags: %s", d.Id(), err)
}
}

return resourceRegisteredDomainRead(ctx, d, meta)
}

Expand Down
4 changes: 4 additions & 0 deletions internal/service/route53domains/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.