diff --git a/aws/resource_aws_rds_cluster_instance.go b/aws/resource_aws_rds_cluster_instance.go index d39581effb9..5bd7c11aaaf 100644 --- a/aws/resource_aws_rds_cluster_instance.go +++ b/aws/resource_aws_rds_cluster_instance.go @@ -200,6 +200,12 @@ func resourceAwsRDSClusterInstance() *schema.Resource { ValidateFunc: validateArn, }, + "copy_tags_to_snapshot": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "tags": tagsSchema(), }, } @@ -211,6 +217,7 @@ func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{ createOpts := &rds.CreateDBInstanceInput{ DBInstanceClass: aws.String(d.Get("instance_class").(string)), + CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)), DBClusterIdentifier: aws.String(d.Get("cluster_identifier").(string)), Engine: aws.String(d.Get("engine").(string)), PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)), @@ -367,6 +374,7 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{}) d.Set("auto_minor_version_upgrade", db.AutoMinorVersionUpgrade) d.Set("availability_zone", db.AvailabilityZone) d.Set("cluster_identifier", db.DBClusterIdentifier) + d.Set("copy_tags_to_snapshot", db.CopyTagsToSnapshot) d.Set("dbi_resource_id", db.DbiResourceId) d.Set("engine_version", db.EngineVersion) d.Set("engine", db.Engine) @@ -461,6 +469,12 @@ func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{ requestUpdate = true } + if d.HasChange("copy_tags_to_snapshot") { + d.SetPartial("copy_tags_to_snapshot") + req.CopyTagsToSnapshot = aws.Bool(d.Get("copy_tags_to_snapshot").(bool)) + requestUpdate = true + } + if d.HasChange("promotion_tier") { d.SetPartial("promotion_tier") req.PromotionTier = aws.Int64(int64(d.Get("promotion_tier").(int))) diff --git a/aws/resource_aws_rds_cluster_instance_test.go b/aws/resource_aws_rds_cluster_instance_test.go index f4b3de67a66..96d3b1e031a 100644 --- a/aws/resource_aws_rds_cluster_instance_test.go +++ b/aws/resource_aws_rds_cluster_instance_test.go @@ -52,6 +52,7 @@ func TestAccAWSRDSClusterInstance_basic(t *testing.T) { 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.TestCheckResourceAttr("aws_rds_cluster_instance.cluster_instances", "copy_tags_to_snapshot", "false"), resource.TestCheckResourceAttrSet("aws_rds_cluster_instance.cluster_instances", "preferred_maintenance_window"), resource.TestCheckResourceAttrSet("aws_rds_cluster_instance.cluster_instances", "preferred_backup_window"), resource.TestCheckResourceAttrSet("aws_rds_cluster_instance.cluster_instances", "dbi_resource_id"), @@ -214,6 +215,35 @@ func TestAccAWSRDSClusterInstance_PubliclyAccessible(t *testing.T) { }) } +func TestAccAWSRDSClusterInstance_CopyTagsToSnapshot(t *testing.T) { + var dbInstance rds.DBInstance + rNameSuffix := acctest.RandInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSClusterInstanceConfig_CopyTagsToSnapshot(rNameSuffix, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &dbInstance), + resource.TestCheckResourceAttr( + "aws_rds_cluster_instance.cluster_instances", "copy_tags_to_snapshot", "true"), + ), + }, + { + Config: testAccAWSClusterInstanceConfig_CopyTagsToSnapshot(rNameSuffix, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &dbInstance), + resource.TestCheckResourceAttr( + "aws_rds_cluster_instance.cluster_instances", "copy_tags_to_snapshot", "false"), + ), + }, + }, + }) +} + func testAccCheckAWSDBClusterInstanceAttributes(v *rds.DBInstance) resource.TestCheckFunc { return func(s *terraform.State) error { @@ -774,3 +804,24 @@ resource "aws_rds_cluster_instance" "test" { } `, rName, rName, publiclyAccessible) } + +func testAccAWSClusterInstanceConfig_CopyTagsToSnapshot(n int, f bool) string { + return fmt.Sprintf(` +resource "aws_rds_cluster" "default" { + cluster_identifier = "tf-aurora-cluster-test-%d" + availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] + database_name = "mydb" + master_username = "foo" + master_password = "mustbeeightcharaters" + skip_final_snapshot = true +} + +resource "aws_rds_cluster_instance" "cluster_instances" { + identifier = "tf-cluster-instance-%d" + cluster_identifier = "${aws_rds_cluster.default.id}" + instance_class = "db.t2.small" + promotion_tier = "3" + copy_tags_to_snapshot = %t +} +`, n, n, f) +} diff --git a/website/docs/r/rds_cluster_instance.html.markdown b/website/docs/r/rds_cluster_instance.html.markdown index f87dacd355e..d3159dc57f2 100644 --- a/website/docs/r/rds_cluster_instance.html.markdown +++ b/website/docs/r/rds_cluster_instance.html.markdown @@ -93,6 +93,7 @@ what IAM permissions are needed to allow Enhanced Monitoring for RDS Instances. * `auto_minor_version_upgrade` - (Optional) Indicates that minor engine upgrades will be applied automatically to the DB instance during the maintenance window. Default `true`. * `performance_insights_enabled` - (Optional) Specifies whether Performance Insights is enabled or not. * `performance_insights_kms_key_id` - (Optional) The ARN for the KMS key to encrypt Performance Insights data. When specifying `performance_insights_kms_key_id`, `performance_insights_enabled` needs to be set to true. +* `copy_tags_to_snapshot` – (Optional, boolean) Indicates whether to copy all of the user-defined tags from the DB instance to snapshots of the DB instance. Default `false`. * `tags` - (Optional) A mapping of tags to assign to the instance. ## Attributes Reference