Skip to content

Commit

Permalink
Remove tagging boilerplate for Plugin SDK resources - dynamodb.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Apr 6, 2023
1 parent 1f4477a commit d60c2c4
Showing 1 changed file with 3 additions and 36 deletions.
39 changes: 3 additions & 36 deletions internal/service/dynamodb/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const (
ResNameTable = "Table"
)

// @SDKResource("aws_dynamodb_table")
// @SDKResource("aws_dynamodb_table", name="Table")
// @Tags(identifierAttribute="arn")
func ResourceTable() *schema.Resource {
//lintignore:R011
return &schema.Resource{
Expand Down Expand Up @@ -402,8 +403,6 @@ func ResourceTable() *schema.Resource {
func resourceTableCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DynamoDBConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get(names.AttrTags).(map[string]interface{})))

tableName := d.Get(names.AttrName).(string)
keySchemaMap := map[string]interface{}{
Expand Down Expand Up @@ -489,10 +488,7 @@ func resourceTableCreate(ctx context.Context, d *schema.ResourceData, meta inter
BillingMode: aws.String(d.Get("billing_mode").(string)),
KeySchema: expandKeySchema(keySchemaMap),
TableName: aws.String(tableName),
}

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

billingMode := d.Get("billing_mode").(string)
Expand Down Expand Up @@ -734,26 +730,6 @@ func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta interfa
return create.DiagSettingError(names.DynamoDB, ResNameTable, d.Id(), "ttl", err)
}

defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

tags, err := ListTags(ctx, conn, d.Get(names.AttrARN).(string))
// When a Table is `ARCHIVED`, ListTags returns `ResourceNotFoundException`
if err != nil && !(tfawserr.ErrMessageContains(err, "UnknownOperationException", "Tagging is not currently supported in DynamoDB Local.") || tfresource.NotFound(err)) {
return create.DiagError(names.DynamoDB, create.ErrActionReading, ResNameTable, d.Id(), fmt.Errorf("tags: %w", err))
}

tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set(names.AttrTags, tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return create.DiagSettingError(names.DynamoDB, ResNameTable, d.Id(), names.AttrTags, err)
}

if err := d.Set(names.AttrTagsAll, tags.Map()); err != nil {
return create.DiagSettingError(names.DynamoDB, ResNameTable, d.Id(), names.AttrTagsAll, err)
}

return diags
}

Expand Down Expand Up @@ -1009,15 +985,6 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter
}
}

if d.HasChange(names.AttrTagsAll) {
replicaTagsChange = true

o, n := d.GetChange(names.AttrTagsAll)
if err := UpdateTags(ctx, conn, d.Get(names.AttrARN).(string), o, n); err != nil {
return create.DiagError(names.DynamoDB, create.ErrActionUpdating, ResNameTable, d.Id(), err)
}
}

if replicaTagsChange {
if v, ok := d.Get("replica").(*schema.Set); ok && v.Len() > 0 {
if err := updateReplicaTags(ctx, conn, d.Get(names.AttrARN).(string), v.List(), d.Get(names.AttrTagsAll), meta.(*conns.AWSClient).TerraformVersion); err != nil {
Expand Down

0 comments on commit d60c2c4

Please sign in to comment.