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

add tags to aws_db_instance data source #10550

Merged
merged 1 commit into from
Nov 2, 2019
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
7 changes: 7 additions & 0 deletions aws/data_source_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func dataSourceAwsDbInstance() *schema.Resource {
ForceNew: true,
},

"tags": tagsSchemaComputed(),

"address": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -313,5 +315,10 @@ func dataSourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Error setting vpc_security_groups attribute: %#v, error: %#v", vpcSecurityGroups, err)
}

// Fetch and save tags
if err := saveTagsRDS(conn, d, aws.StringValue(dbInstance.DBInstanceArn)); err != nil {
log.Printf("[WARN] Failed to save tags for RDS Instance (%s): %s", aws.StringValue(dbInstance.DBInstanceArn), err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: In the future we will be requiring returning an error instead of just logging these 👍

}

return nil
}
6 changes: 6 additions & 0 deletions aws/data_source_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func TestAccAWSDbInstanceDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "enabled_cloudwatch_logs_exports.0"),
resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "enabled_cloudwatch_logs_exports.1"),
resource.TestCheckResourceAttrPair("data.aws_db_instance.bar", "resource_id", "aws_db_instance.bar", "resource_id"),
resource.TestCheckResourceAttrPair("data.aws_db_instance.bar", "tags.%", "aws_db_instance.bar", "tags.%"),
resource.TestCheckResourceAttrPair("data.aws_db_instance.bar", "tags.Environment", "aws_db_instance.bar", "tags.Environment"),
),
},
},
Expand Down Expand Up @@ -77,6 +79,10 @@ resource "aws_db_instance" "bar" {
"audit",
"error",
]

tags = {
Environment = "test"
}
}

data "aws_db_instance" "bar" {
Expand Down