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 Argument copy_tags_to_snapshot for aws_rds_cluster_instance #6582

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
14 changes: 14 additions & 0 deletions aws/resource_aws_rds_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func resourceAwsRDSClusterInstance() *schema.Resource {
ValidateFunc: validateArn,
},

"copy_tags_to_snapshot": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"tags": tagsSchema(),
},
}
Expand All @@ -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)),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
Expand Down
51 changes: 51 additions & 0 deletions aws/resource_aws_rds_cluster_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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 {

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