From 67a9bd461154a82ffad91409632552ea506fc10a Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 17 Jul 2018 12:50:31 -0400 Subject: [PATCH] resource/aws_rds_cluster_instance: Add arn attribute --- aws/resource_aws_rds_cluster_instance.go | 46 ++++++++----------- aws/resource_aws_rds_cluster_instance_test.go | 1 + .../docs/r/rds_cluster_instance.html.markdown | 1 + 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/aws/resource_aws_rds_cluster_instance.go b/aws/resource_aws_rds_cluster_instance.go index d3a4465963d..b13c2b908d7 100644 --- a/aws/resource_aws_rds_cluster_instance.go +++ b/aws/resource_aws_rds_cluster_instance.go @@ -7,7 +7,6 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/rds" "github.com/hashicorp/terraform/helper/resource" @@ -31,6 +30,11 @@ func resourceAwsRDSClusterInstance() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "identifier": { Type: schema.TypeString, Optional: true, @@ -359,22 +363,23 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{}) d.Set("db_subnet_group_name", db.DBSubnetGroup.DBSubnetGroupName) } - d.Set("publicly_accessible", db.PubliclyAccessible) + d.Set("arn", db.DBInstanceArn) + d.Set("auto_minor_version_upgrade", db.AutoMinorVersionUpgrade) + d.Set("availability_zone", db.AvailabilityZone) d.Set("cluster_identifier", db.DBClusterIdentifier) - d.Set("engine", db.Engine) + d.Set("dbi_resource_id", db.DbiResourceId) d.Set("engine_version", db.EngineVersion) - d.Set("instance_class", db.DBInstanceClass) + d.Set("engine", db.Engine) d.Set("identifier", db.DBInstanceIdentifier) - d.Set("dbi_resource_id", db.DbiResourceId) - d.Set("storage_encrypted", db.StorageEncrypted) + d.Set("instance_class", db.DBInstanceClass) d.Set("kms_key_id", db.KmsKeyId) - d.Set("auto_minor_version_upgrade", db.AutoMinorVersionUpgrade) - d.Set("promotion_tier", db.PromotionTier) - d.Set("preferred_backup_window", db.PreferredBackupWindow) - d.Set("preferred_maintenance_window", db.PreferredMaintenanceWindow) - d.Set("availability_zone", db.AvailabilityZone) d.Set("performance_insights_enabled", db.PerformanceInsightsEnabled) d.Set("performance_insights_kms_key_id", db.PerformanceInsightsKMSKeyId) + d.Set("preferred_backup_window", db.PreferredBackupWindow) + d.Set("preferred_maintenance_window", db.PreferredMaintenanceWindow) + d.Set("promotion_tier", db.PromotionTier) + d.Set("publicly_accessible", db.PubliclyAccessible) + d.Set("storage_encrypted", db.StorageEncrypted) if db.MonitoringInterval != nil { d.Set("monitoring_interval", db.MonitoringInterval) @@ -388,15 +393,7 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{}) d.Set("db_parameter_group_name", db.DBParameterGroups[0].DBParameterGroupName) } - // Fetch and save tags - arn := arn.ARN{ - Partition: meta.(*AWSClient).partition, - Service: "rds", - Region: meta.(*AWSClient).region, - AccountID: meta.(*AWSClient).accountid, - Resource: fmt.Sprintf("db:%s", d.Id()), - }.String() - if err := saveTagsRDS(conn, d, arn); err != nil { + if err := saveTagsRDS(conn, d, aws.StringValue(db.DBInstanceArn)); err != nil { log.Printf("[WARN] Failed to save tags for RDS Cluster Instance (%s): %s", *db.DBClusterIdentifier, err) } @@ -505,14 +502,7 @@ func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{ } - arn := arn.ARN{ - Partition: meta.(*AWSClient).partition, - Service: "rds", - Region: meta.(*AWSClient).region, - AccountID: meta.(*AWSClient).accountid, - Resource: fmt.Sprintf("db:%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 } diff --git a/aws/resource_aws_rds_cluster_instance_test.go b/aws/resource_aws_rds_cluster_instance_test.go index 03e76454d25..dfb23443bbc 100644 --- a/aws/resource_aws_rds_cluster_instance_test.go +++ b/aws/resource_aws_rds_cluster_instance_test.go @@ -29,6 +29,7 @@ func TestAccAWSRDSClusterInstance_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v), testAccCheckAWSDBClusterInstanceAttributes(&v), + resource.TestMatchResourceAttr("aws_rds_cluster_instance.cluster_instances", "arn", regexp.MustCompile(`^arn:[^:]+:rds:[^:]+:[^:]+:db:.+`)), resource.TestCheckResourceAttr("aws_rds_cluster_instance.cluster_instances", "auto_minor_version_upgrade", "true"), resource.TestCheckResourceAttrSet("aws_rds_cluster_instance.cluster_instances", "preferred_maintenance_window"), resource.TestCheckResourceAttrSet("aws_rds_cluster_instance.cluster_instances", "preferred_backup_window"), diff --git a/website/docs/r/rds_cluster_instance.html.markdown b/website/docs/r/rds_cluster_instance.html.markdown index 368a2bc154c..73998c8e266 100644 --- a/website/docs/r/rds_cluster_instance.html.markdown +++ b/website/docs/r/rds_cluster_instance.html.markdown @@ -97,6 +97,7 @@ what IAM permissions are needed to allow Enhanced Monitoring for RDS Instances. In addition to all arguments above, the following attributes are exported: +* `arn` - Amazon Resource Name (ARN) of cluster instance * `cluster_identifier` - The RDS Cluster Identifier * `identifier` - The Instance identifier * `id` - The Instance identifier