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

provider: Support default tags (resources aws_r*) #18726

Merged
merged 2 commits into from
Apr 21, 2021
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
27 changes: 20 additions & 7 deletions aws/resource_aws_ram_resource_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,26 @@ func resourceAwsRamResourceShare() *schema.Resource {
Default: false,
},

"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
},

CustomizeDiff: SetTagsDiff,
}
}

func resourceAwsRamResourceShareCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ramconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))

request := &ram.CreateResourceShareInput{
Name: aws.String(d.Get("name").(string)),
AllowExternalPrincipals: aws.Bool(d.Get("allow_external_principals").(bool)),
}

if v := d.Get("tags").(map[string]interface{}); len(v) > 0 {
request.Tags = keyvaluetags.New(v).IgnoreAws().RamTags()
if len(tags) > 0 {
request.Tags = tags.IgnoreAws().RamTags()
}

log.Println("[DEBUG] Create RAM resource share request:", request)
Expand Down Expand Up @@ -87,6 +92,7 @@ func resourceAwsRamResourceShareCreate(d *schema.ResourceData, meta interface{})

func resourceAwsRamResourceShareRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ramconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

request := &ram.GetResourceSharesInput{
Expand Down Expand Up @@ -122,8 +128,15 @@ func resourceAwsRamResourceShareRead(d *schema.ResourceData, meta interface{}) e
d.Set("name", resourceShare.Name)
d.Set("allow_external_principals", resourceShare.AllowExternalPrincipals)

if err := d.Set("tags", keyvaluetags.RamKeyValueTags(resourceShare.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
tags := keyvaluetags.RamKeyValueTags(resourceShare.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

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

return nil
Expand Down Expand Up @@ -151,8 +164,8 @@ func resourceAwsRamResourceShareUpdate(d *schema.ResourceData, meta interface{})
}
}

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.RamUpdateTags(conn, d.Id(), o, n); err != nil {
return fmt.Errorf("error updating RAM resource share (%s) tags: %s", d.Id(), err)
Expand Down
32 changes: 22 additions & 10 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,11 @@ func resourceAwsRDSCluster() *schema.Resource {
Default: false,
},

"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
},

CustomizeDiff: SetTagsDiff,
}
}

Expand All @@ -472,7 +475,8 @@ func resourceAwsRdsClusterImport(

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

// 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 @@ -502,7 +506,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
EngineMode: aws.String(d.Get("engine_mode").(string)),
ScalingConfiguration: expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{})),
SnapshotIdentifier: aws.String(d.Get("snapshot_identifier").(string)),
Tags: tags,
Tags: tags.IgnoreAws().RdsTags(),
}

if attr := d.Get("availability_zones").(*schema.Set); attr.Len() > 0 {
Expand Down Expand Up @@ -606,7 +610,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
S3Prefix: aws.String(s3_bucket["bucket_prefix"].(string)),
SourceEngine: aws.String(s3_bucket["source_engine"].(string)),
SourceEngineVersion: aws.String(s3_bucket["source_engine_version"].(string)),
Tags: tags,
Tags: tags.IgnoreAws().RdsTags(),
}

if v, ok := d.GetOk("backtrack_window"); ok {
Expand Down Expand Up @@ -707,7 +711,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
DBClusterIdentifier: aws.String(identifier),
DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)),
SourceDBClusterIdentifier: aws.String(pointInTime["source_cluster_identifier"].(string)),
Tags: tags,
Tags: tags.IgnoreAws().RdsTags(),
}

if v, ok := pointInTime["restore_to_time"].(string); ok && v != "" {
Expand Down Expand Up @@ -807,7 +811,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
Engine: aws.String(d.Get("engine").(string)),
EngineMode: aws.String(d.Get("engine_mode").(string)),
ScalingConfiguration: expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{})),
Tags: tags,
Tags: tags.IgnoreAws().RdsTags(),
}

// Note: Username and password credentials are required and valid
Expand Down Expand Up @@ -973,6 +977,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error

func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

input := &rds.DescribeDBClustersInput{
Expand Down Expand Up @@ -1088,8 +1093,15 @@ func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error {
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().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

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

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

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.RdsUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating tags: %s", err)
Expand Down
25 changes: 19 additions & 6 deletions aws/resource_aws_rds_cluster_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ func resourceAwsRDSClusterEndpoint() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
},

CustomizeDiff: SetTagsDiff,
}
}

func resourceAwsRDSClusterEndpointCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))

clusterId := d.Get("cluster_identifier").(string)
endpointId := d.Get("cluster_endpoint_identifier").(string)
Expand All @@ -88,7 +93,7 @@ func resourceAwsRDSClusterEndpointCreate(d *schema.ResourceData, meta interface{
DBClusterIdentifier: aws.String(clusterId),
DBClusterEndpointIdentifier: aws.String(endpointId),
EndpointType: aws.String(endpointType),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().RdsTags(),
Tags: tags.IgnoreAws().RdsTags(),
}

if v := d.Get("static_members"); v != nil {
Expand All @@ -115,6 +120,7 @@ func resourceAwsRDSClusterEndpointCreate(d *schema.ResourceData, meta interface{

func resourceAwsRDSClusterEndpointRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

input := &rds.DescribeDBClusterEndpointsInput{
Expand Down Expand Up @@ -166,8 +172,15 @@ func resourceAwsRDSClusterEndpointRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("error listing tags for RDS Cluster Endpoint (%s): %s", *arn, err)
}

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

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

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

return nil
Expand All @@ -179,8 +192,8 @@ func resourceAwsRDSClusterEndpointUpdate(d *schema.ResourceData, meta interface{
DBClusterEndpointIdentifier: aws.String(d.Id()),
}

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.RdsUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating RDS Cluster Endpoint (%s) tags: %s", d.Get("arn").(string), err)
Expand Down
25 changes: 19 additions & 6 deletions aws/resource_aws_rds_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,18 @@ func resourceAwsRDSClusterInstance() *schema.Resource {
Computed: true,
},

"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
},

CustomizeDiff: SetTagsDiff,
}
}

func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))

createOpts := &rds.CreateDBInstanceInput{
DBInstanceClass: aws.String(d.Get("instance_class").(string)),
Expand All @@ -228,7 +233,7 @@ func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{
PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)),
PromotionTier: aws.Int64(int64(d.Get("promotion_tier").(int))),
AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().RdsTags(),
Tags: tags.IgnoreAws().RdsTags(),
}

if attr, ok := d.GetOk("availability_zone"); ok {
Expand Down Expand Up @@ -398,6 +403,7 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{})

// Retrieve DB Cluster information, to determine if this Instance is a writer
conn := meta.(*AWSClient).rdsconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

resp, err := conn.DescribeDBClusters(&rds.DescribeDBClustersInput{
Expand Down Expand Up @@ -465,8 +471,15 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{})
if err != nil {
return fmt.Errorf("error listing tags for RDS Cluster Instance (%s): %s", d.Id(), err)
}
if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

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

return nil
Expand Down Expand Up @@ -584,8 +597,8 @@ func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{

}

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.RdsUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating RDS Cluster Instance (%s) tags: %s", d.Id(), err)
Expand Down
25 changes: 19 additions & 6 deletions aws/resource_aws_rds_cluster_parameter_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,18 @@ func resourceAwsRDSClusterParameterGroup() *schema.Resource {
Set: resourceAwsDbParameterHash,
},

"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
},

CustomizeDiff: SetTagsDiff,
}
}

func resourceAwsRDSClusterParameterGroupCreate(d *schema.ResourceData, meta interface{}) error {
rdsconn := meta.(*AWSClient).rdsconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))

var groupName string
if v, ok := d.GetOk("name"); ok {
Expand All @@ -103,7 +108,7 @@ func resourceAwsRDSClusterParameterGroupCreate(d *schema.ResourceData, meta inte
DBClusterParameterGroupName: aws.String(groupName),
DBParameterGroupFamily: aws.String(d.Get("family").(string)),
Description: aws.String(d.Get("description").(string)),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().RdsTags(),
Tags: tags.IgnoreAws().RdsTags(),
}

log.Printf("[DEBUG] Create DB Cluster Parameter Group: %#v", createOpts)
Expand All @@ -123,6 +128,7 @@ func resourceAwsRDSClusterParameterGroupCreate(d *schema.ResourceData, meta inte

func resourceAwsRDSClusterParameterGroupRead(d *schema.ResourceData, meta interface{}) error {
rdsconn := meta.(*AWSClient).rdsconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

describeOpts := rds.DescribeDBClusterParameterGroupsInput{
Expand Down Expand Up @@ -173,8 +179,15 @@ func resourceAwsRDSClusterParameterGroupRead(d *schema.ResourceData, meta interf
log.Printf("[DEBUG] Error retrieving tags for ARN: %s", arn)
}

if err := d.Set("tags", keyvaluetags.RdsKeyValueTags(resp.TagList).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
tags := keyvaluetags.RdsKeyValueTags(resp.TagList).IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

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

return nil
Expand Down Expand Up @@ -279,8 +292,8 @@ func resourceAwsRDSClusterParameterGroupUpdate(d *schema.ResourceData, meta inte
}
}

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.RdsUpdateTags(rdsconn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating RDS Cluster Parameter Group (%s) tags: %s", d.Id(), err)
Expand Down
Loading