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

aws_rds_cluster: Add arn attribute #5221

Merged
merged 1 commit into from
Jul 26, 2018
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
5 changes: 5 additions & 0 deletions aws/data_source_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func dataSourceAwsRdsCluster() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsRdsClusterRead,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},

"cluster_identifier": {
Type: schema.TypeString,
Required: true,
Expand Down
25 changes: 14 additions & 11 deletions aws/data_source_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceAwsRdsCluster_basic(t *testing.T) {
func TestAccDataSourceAWSRDSCluster_basic(t *testing.T) {
clusterName := fmt.Sprintf("testaccawsrdscluster-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
dataSourceName := "data.aws_rds_cluster.test"
resourceName := "aws_rds_cluster.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -18,21 +20,22 @@ func TestAccDataSourceAwsRdsCluster_basic(t *testing.T) {
{
Config: testAccDataSourceAwsRdsClusterConfigBasic(clusterName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.aws_rds_cluster.rds_cluster_test", "cluster_identifier", clusterName),
resource.TestCheckResourceAttr("data.aws_rds_cluster.rds_cluster_test", "database_name", "mydb"),
resource.TestCheckResourceAttr("data.aws_rds_cluster.rds_cluster_test", "db_cluster_parameter_group_name", "default.aurora5.6"),
resource.TestCheckResourceAttr("data.aws_rds_cluster.rds_cluster_test", "db_subnet_group_name", clusterName),
resource.TestCheckResourceAttr("data.aws_rds_cluster.rds_cluster_test", "master_username", "foo"),
resource.TestCheckResourceAttr("data.aws_rds_cluster.rds_cluster_test", "tags.%", "1"),
resource.TestCheckResourceAttr("data.aws_rds_cluster.rds_cluster_test", "tags.Environment", "test"),
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "cluster_identifier", resourceName, "cluster_identifier"),
resource.TestCheckResourceAttrPair(dataSourceName, "database_name", resourceName, "database_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "db_cluster_parameter_group_name", resourceName, "db_cluster_parameter_group_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "db_subnet_group_name", resourceName, "db_subnet_group_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "master_username", resourceName, "master_username"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.Environment", resourceName, "tags.Environment"),
),
},
},
})
}

func testAccDataSourceAwsRdsClusterConfigBasic(clusterName string) string {
return fmt.Sprintf(`resource "aws_rds_cluster" "rds_cluster_test" {
return fmt.Sprintf(`resource "aws_rds_cluster" "test" {
cluster_identifier = "%s"
database_name = "mydb"
db_cluster_parameter_group_name = "default.aurora5.6"
Expand Down Expand Up @@ -74,7 +77,7 @@ resource "aws_db_subnet_group" "test" {
subnet_ids = ["${aws_subnet.a.id}", "${aws_subnet.b.id}"]
}

data "aws_rds_cluster" "rds_cluster_test" {
cluster_identifier = "${aws_rds_cluster.rds_cluster_test.cluster_identifier}"
data "aws_rds_cluster" "test" {
cluster_identifier = "${aws_rds_cluster.test.cluster_identifier}"
}`, clusterName, clusterName)
}
38 changes: 14 additions & 24 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform/helper/resource"
Expand All @@ -33,6 +32,10 @@ func resourceAwsRDSCluster() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},

"availability_zones": {
Type: schema.TypeSet,
Expand Down Expand Up @@ -819,25 +822,26 @@ func flattenAwsRdsClusterResource(d *schema.ResourceData, meta interface{}, dbc
d.Set("database_name", dbc.DatabaseName)
}

d.Set("arn", dbc.DBClusterArn)
d.Set("backtrack_window", int(aws.Int64Value(dbc.BacktrackWindow)))
d.Set("backup_retention_period", dbc.BackupRetentionPeriod)
d.Set("cluster_identifier", dbc.DBClusterIdentifier)
d.Set("cluster_resource_id", dbc.DbClusterResourceId)
d.Set("db_subnet_group_name", dbc.DBSubnetGroup)
d.Set("db_cluster_parameter_group_name", dbc.DBClusterParameterGroup)
d.Set("db_subnet_group_name", dbc.DBSubnetGroup)
d.Set("endpoint", dbc.Endpoint)
d.Set("engine", dbc.Engine)
d.Set("engine_version", dbc.EngineVersion)
d.Set("engine", dbc.Engine)
d.Set("hosted_zone_id", dbc.HostedZoneId)
d.Set("iam_database_authentication_enabled", dbc.IAMDatabaseAuthenticationEnabled)
d.Set("kms_key_id", dbc.KmsKeyId)
d.Set("master_username", dbc.MasterUsername)
d.Set("port", dbc.Port)
d.Set("storage_encrypted", dbc.StorageEncrypted)
d.Set("backup_retention_period", dbc.BackupRetentionPeriod)
d.Set("preferred_backup_window", dbc.PreferredBackupWindow)
d.Set("preferred_maintenance_window", dbc.PreferredMaintenanceWindow)
d.Set("kms_key_id", dbc.KmsKeyId)
d.Set("reader_endpoint", dbc.ReaderEndpoint)
d.Set("replication_source_identifier", dbc.ReplicationSourceIdentifier)
d.Set("iam_database_authentication_enabled", dbc.IAMDatabaseAuthenticationEnabled)
d.Set("hosted_zone_id", dbc.HostedZoneId)
d.Set("storage_encrypted", dbc.StorageEncrypted)

if err := d.Set("enabled_cloudwatch_logs_exports", flattenStringList(dbc.EnabledCloudwatchLogsExports)); err != nil {
return fmt.Errorf("error setting enabled_cloudwatch_logs_exports: %s", err)
Expand Down Expand Up @@ -869,14 +873,7 @@ func flattenAwsRdsClusterResource(d *schema.ResourceData, meta interface{}, dbc
}

// Fetch and save tags
arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "rds",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("cluster:%s", d.Id()),
}.String()
if err := saveTagsRDS(conn, d, arn); err != nil {
if err := saveTagsRDS(conn, d, aws.StringValue(dbc.DBClusterArn)); err != nil {
log.Printf("[WARN] Failed to save tags for RDS Cluster (%s): %s", *dbc.DBClusterIdentifier, err)
}

Expand Down Expand Up @@ -1006,14 +1003,7 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
}
}

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "rds",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("cluster:%s", d.Id()),
}.String()
if err := setTagsRDS(conn, d, arn); err != nil {
if err := setTagsRDS(conn, d, d.Get("arn").(string)); err != nil {
return err
} else {
d.SetPartial("tags")
Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccAWSRDSCluster_basic(t *testing.T) {
Config: testAccAWSClusterConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(`^arn:[^:]+:rds:[^:]+:\d{12}:cluster:.+`)),
resource.TestCheckResourceAttr(resourceName, "backtrack_window", "0"),
resource.TestCheckResourceAttr(resourceName, "storage_encrypted", "false"),
resource.TestCheckResourceAttr(resourceName, "db_cluster_parameter_group_name", "default.aurora5.6"),
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/rds_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ This will not recreate the resource if the S3 object changes in some way. It's o

In addition to all arguments above, the following attributes are exported:

* `arn` - Amazon Resource Name (ARN) of cluster
* `id` - The RDS Cluster Identifier
* `cluster_identifier` - The RDS Cluster Identifier
* `cluster_resource_id` - The RDS Cluster Resource ID
Expand Down