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

resource/aws_rds_cluster: Refactor tagging to use keyvaluetags library #10483

Merged
merged 5 commits into from
Nov 4, 2019
Merged
Changes from 4 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
20 changes: 14 additions & 6 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsRDSCluster() *schema.Resource {
Expand Down Expand Up @@ -419,7 +420,7 @@ func resourceAwsRdsClusterImport(

func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
tags := tagsFromMapRDS(d.Get("tags").(map[string]interface{}))
tags := keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().RdsTags()

// Some API calls (e.g. RestoreDBClusterFromSnapshot do not support all
// parameters to correctly apply all settings in one pass. For missing
Expand Down Expand Up @@ -1032,9 +1033,14 @@ func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error setting vpc_security_group_ids: %s", err)
}

// Fetch and save tags
if err := saveTagsRDS(conn, d, aws.StringValue(dbc.DBClusterArn)); err != nil {
log.Printf("[WARN] Failed to save tags for RDS Cluster (%s): %s", aws.StringValue(dbc.DBClusterIdentifier), err)
tagList, err := conn.ListTagsForResource(&rds.ListTagsForResourceInput{
ResourceName: aws.String(aws.StringValue(dbc.DBClusterArn)),
})
if err != nil {
return fmt.Errorf("Failed to get RDS Cluster parameter tags for %s: %s", aws.StringValue(dbc.DBClusterIdentifier), err)
}
if err := d.Set("tags", keyvaluetags.RdsKeyValueTags(tagList.TagList).IgnoreAws().Map()); err != nil {
return fmt.Errorf("[WARN] Failed to save tags for RDS Cluster (%s): %s", aws.StringValue(dbc.DBClusterIdentifier), err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please switch this to the keyvaluetags package function RdsListTags? Thanks!

tags, err := keyvaluetags.RdsListTags(conn, aws.StringValue(dbc.DBClusterArn))

if err != nil {
	return fmt.Errorf("error listing tags for RDS Cluster (%s): %s", aws.StringValue(dbc.DBClusterArn), err)
}

if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil {
	return fmt.Errorf("error setting tags: %s", err)
}

Copy link
Collaborator Author

@DrFaust92 DrFaust92 Nov 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed that one, done.

}

// Fetch and save Global Cluster if engine mode global
Expand Down Expand Up @@ -1223,8 +1229,10 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
}

if d.HasChange("tags") {
if err := setTagsRDS(conn, d, d.Get("arn").(string)); err != nil {
return err
o, n := d.GetChange("tags")

if err := keyvaluetags.RdsUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating tags: %s", err)
} else {
d.SetPartial("tags")
}
Expand Down