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

data/aws_rds_cluster: Refactor tagging to use keyvaluetags library #10724

Merged
merged 4 commits into from
Nov 4, 2019
Merged
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
15 changes: 11 additions & 4 deletions aws/data_source_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func dataSourceAwsRdsCluster() *schema.Resource {
Expand Down Expand Up @@ -201,7 +202,8 @@ func dataSourceAwsRdsClusterRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("error setting availability_zones: %s", err)
}

d.Set("arn", dbc.DBClusterArn)
arn := dbc.DBClusterArn
d.Set("arn", arn)
d.Set("backtrack_window", int(aws.Int64Value(dbc.BacktrackWindow)))
d.Set("backup_retention_period", dbc.BackupRetentionPeriod)
d.Set("cluster_identifier", dbc.DBClusterIdentifier)
Expand Down Expand Up @@ -263,9 +265,14 @@ func dataSourceAwsRdsClusterRead(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)
tags, err := keyvaluetags.RdsListTags(conn, *arn)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: To prevent potential panics, we generally recommend using the AWS Go SDK provided conversion functions to dereference pointers, e.g. aws.StringValue(dbc.DBClusterArn) above


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

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

return nil
Expand Down