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 d* (Phase 3c) #30509

Merged
merged 17 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
eecf1df
Remove tagging boilerplate for Plugin SDK resources - dataexchange.
ewbankkit Apr 6, 2023
3c58ffd
Remove tagging boilerplate for Plugin SDK resources - datapipeline.
ewbankkit Apr 6, 2023
7cbecfb
Remove tagging boilerplate for Plugin SDK resources - datasync.
ewbankkit Apr 6, 2023
b03048c
Remove tagging boilerplate for Plugin SDK resources - dax.
ewbankkit Apr 6, 2023
a4f657f
Remove tagging boilerplate for Plugin SDK resources - deploy.
ewbankkit Apr 6, 2023
1afd0fd
Remove tagging boilerplate for Plugin SDK resources - detective.
ewbankkit Apr 6, 2023
7d96653
Remove tagging boilerplate for Plugin SDK resources - devicefarm.
ewbankkit Apr 6, 2023
56e6d0e
Remove tagging boilerplate for Plugin SDK resources - directconnect.
ewbankkit Apr 6, 2023
3011966
Remove tagging boilerplate for Plugin SDK resources - dlm.
ewbankkit Apr 6, 2023
491cd3a
Remove tagging boilerplate for Plugin SDK resources - dms.
ewbankkit Apr 6, 2023
1a8ae1a
Remove tagging boilerplate for Plugin SDK resources - docdb.
ewbankkit Apr 6, 2023
1f4477a
Remove tagging boilerplate for Plugin SDK resources - ds.
ewbankkit Apr 6, 2023
d60c2c4
Remove tagging boilerplate for Plugin SDK resources - dynamodb.
ewbankkit Apr 6, 2023
9504b4a
Revert "Remove tagging boilerplate for Plugin SDK resources - dynamodb."
ewbankkit Apr 6, 2023
4885dd9
Run 'make fmt'.
ewbankkit Apr 6, 2023
92a576d
Run 'make servicepackages'.
ewbankkit Apr 6, 2023
5a02f38
Fix semgrep 'dgryski.semgrep-go.oddifsequence.odd-sequence-ifs'.
ewbankkit Apr 6, 2023
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
35 changes: 7 additions & 28 deletions internal/service/dataexchange/data_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,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_dataexchange_data_set")
// @SDKResource("aws_dataexchange_data_set", name="Data Set")
// @Tags(identifierAttribute="arn")
func ResourceDataSet() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceDataSetCreate,
Expand Down Expand Up @@ -48,8 +50,8 @@ func ResourceDataSet() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},
CustomizeDiff: verify.SetTagsDiff,
}
Expand All @@ -58,17 +60,12 @@ func ResourceDataSet() *schema.Resource {
func resourceDataSetCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataExchangeConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{})))

input := &dataexchange.CreateDataSetInput{
Name: aws.String(d.Get("name").(string)),
AssetType: aws.String(d.Get("asset_type").(string)),
Description: aws.String(d.Get("description").(string)),
}

if len(tags) > 0 {
input.Tags = Tags(tags.IgnoreAWS())
Tags: GetTagsIn(ctx),
}

out, err := conn.CreateDataSetWithContext(ctx, input)
Expand All @@ -84,8 +81,6 @@ func resourceDataSetCreate(ctx context.Context, d *schema.ResourceData, meta int
func resourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataExchangeConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

dataSet, err := FindDataSetById(ctx, conn, d.Id())

Expand All @@ -104,15 +99,7 @@ func resourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta inter
d.Set("description", dataSet.Description)
d.Set("arn", dataSet.Arn)

tags := KeyValueTags(ctx, dataSet.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

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)
}
SetTagsOut(ctx, dataSet.Tags)

return diags
}
Expand Down Expand Up @@ -141,14 +128,6 @@ func resourceDataSetUpdate(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 DataExchange DataSet (%s) tags: %s", d.Get("arn").(string), err)
}
}

return append(diags, resourceDataSetRead(ctx, d, meta)...)
}

Expand Down
35 changes: 7 additions & 28 deletions internal/service/dataexchange/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_dataexchange_revision")
// @SDKResource("aws_dataexchange_revision", name="Revision")
// @Tags(identifierAttribute="arn")
func ResourceRevision() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceRevisionCreate,
Expand Down Expand Up @@ -49,8 +51,8 @@ func ResourceRevision() *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,
}
Expand All @@ -59,16 +61,11 @@ func ResourceRevision() *schema.Resource {
func resourceRevisionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataExchangeConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{})))

input := &dataexchange.CreateRevisionInput{
DataSetId: aws.String(d.Get("data_set_id").(string)),
Comment: aws.String(d.Get("comment").(string)),
}

if len(tags) > 0 {
input.Tags = Tags(tags.IgnoreAWS())
Tags: GetTagsIn(ctx),
}

out, err := conn.CreateRevisionWithContext(ctx, input)
Expand All @@ -84,8 +81,6 @@ func resourceRevisionCreate(ctx context.Context, d *schema.ResourceData, meta in
func resourceRevisionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataExchangeConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

dataSetId, revisionId, err := RevisionParseResourceID(d.Id())
if err != nil {
Expand All @@ -109,15 +104,7 @@ func resourceRevisionRead(ctx context.Context, d *schema.ResourceData, meta inte
d.Set("arn", revision.Arn)
d.Set("revision_id", revision.Id)

tags := KeyValueTags(ctx, revision.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

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)
}
SetTagsOut(ctx, revision.Tags)

return diags
}
Expand All @@ -143,14 +130,6 @@ func resourceRevisionUpdate(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.Get("arn").(string), o, n); err != nil {
return sdkdiag.AppendErrorf(diags, "updating DataExchange Revision (%s) tags: %s", d.Get("arn").(string), err)
}
}

return append(diags, resourceRevisionRead(ctx, d, meta)...)
}

Expand Down
8 changes: 8 additions & 0 deletions internal/service/dataexchange/service_package_gen.go

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

34 changes: 8 additions & 26 deletions internal/service/datapipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_datapipeline_pipeline")
// @SDKResource("aws_datapipeline_pipeline", name="Pipeline")
// @Tags(identifierAttribute="id")
func ResourcePipeline() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourcePipelineCreate,
Expand All @@ -43,8 +45,8 @@ func ResourcePipeline() *schema.Resource {
ForceNew: true,
},

"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},

CustomizeDiff: verify.SetTagsDiff,
Expand All @@ -54,15 +56,12 @@ func ResourcePipeline() *schema.Resource {
func resourcePipelineCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataPipelineConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{})))

uniqueID := id.UniqueId()

input := datapipeline.CreatePipelineInput{
Name: aws.String(d.Get("name").(string)),
UniqueId: aws.String(uniqueID),
Tags: Tags(tags.IgnoreAWS()),
Tags: GetTagsIn(ctx),
}

if v, ok := d.GetOk("description"); ok {
Expand All @@ -83,8 +82,6 @@ func resourcePipelineCreate(ctx context.Context, d *schema.ResourceData, meta in
func resourcePipelineRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataPipelineConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

v, err := PipelineRetrieve(ctx, d.Id(), conn)
if tfawserr.ErrCodeEquals(err, datapipeline.ErrCodePipelineNotFoundException) || tfawserr.ErrCodeEquals(err, datapipeline.ErrCodePipelineDeletedException) || v == nil {
Expand All @@ -98,31 +95,16 @@ func resourcePipelineRead(ctx context.Context, d *schema.ResourceData, meta inte

d.Set("name", v.Name)
d.Set("description", v.Description)
tags := KeyValueTags(ctx, v.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)
}
SetTagsOut(ctx, v.Tags)

return diags
}

func resourcePipelineUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataPipelineConn()

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 Datapipeline Pipeline (%s) tags: %s", d.Id(), err)
}
}
// Tags only.

return append(diags, resourcePipelineRead(ctx, d, meta)...)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/service/datapipeline/service_package_gen.go

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

39 changes: 6 additions & 33 deletions internal/service/datasync/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,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_datasync_agent")
// @SDKResource("aws_datasync_agent", name="Agent")
// @Tags(identifierAttribute="id")
func ResourceAgent() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceAgentCreate,
Expand Down Expand Up @@ -79,8 +81,8 @@ func ResourceAgent() *schema.Resource {
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"vpc_endpoint_id": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -95,8 +97,6 @@ func ResourceAgent() *schema.Resource {
func resourceAgentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataSyncConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{})))

activationKey := d.Get("activation_key").(string)
agentIpAddress := d.Get("ip_address").(string)
Expand Down Expand Up @@ -174,7 +174,7 @@ func resourceAgentCreate(ctx context.Context, d *schema.ResourceData, meta inter

input := &datasync.CreateAgentInput{
ActivationKey: aws.String(activationKey),
Tags: Tags(tags.IgnoreAWS()),
Tags: GetTagsIn(ctx),
}

if v, ok := d.GetOk("name"); ok {
Expand Down Expand Up @@ -214,8 +214,6 @@ func resourceAgentCreate(ctx context.Context, d *schema.ResourceData, meta inter
func resourceAgentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataSyncConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

output, err := FindAgentByARN(ctx, conn, d.Id())

Expand Down Expand Up @@ -243,23 +241,6 @@ func resourceAgentRead(ctx context.Context, d *schema.ResourceData, meta interfa
d.Set("vpc_endpoint_id", "")
}

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

if err != nil {
return sdkdiag.AppendErrorf(diags, "listing tags for DataSync Agent (%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
}

Expand All @@ -280,14 +261,6 @@ func resourceAgentUpdate(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.Id(), o, n); err != nil {
return sdkdiag.AppendErrorf(diags, "updating DataSync Agent (%s) tags: %s", d.Id(), err)
}
}

return append(diags, resourceAgentRead(ctx, d, meta)...)
}

Expand Down
Loading