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

resource/aws_rds_cluster_instance: Add arn attribute #5220

Merged
merged 1 commit into from
Jul 17, 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
46 changes: 18 additions & 28 deletions aws/resource_aws_rds_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_rds_cluster_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/rds_cluster_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down