From e3100b5c21e29cce2a06f512c49e4ee4be6e48b9 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Mon, 26 Nov 2018 16:24:26 +0900 Subject: [PATCH 1/3] Add Argument copy_tags_to_snapshot for aws_rds_cluster_instance --- aws/resource_aws_rds_cluster_instance.go | 14 ++++ aws/resource_aws_rds_cluster_instance_test.go | 67 +++++++++++++++++++ .../docs/r/rds_cluster_instance.html.markdown | 1 + 3 files changed, 82 insertions(+) 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..1ae32f459ee 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", "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,40 @@ 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" + db_parameter_group_name = "${aws_db_parameter_group.bar.name}" + promotion_tier = "3" + copy_tags_to_snapshot = %t +} + +resource "aws_db_parameter_group" "bar" { + name = "tfcluster-test-group-%d" + family = "aurora5.6" + + parameter { + name = "back_log" + value = "32767" + apply_method = "pending-reboot" + } + + tags { + foo = "bar" + } +} +`, n, n, f, n) +} 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 From 2eaa8326815897ef0155e65730c9002c8ad536e6 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Tue, 4 Dec 2018 10:29:25 +0900 Subject: [PATCH 2/3] Fix resource name --- aws/resource_aws_rds_cluster_instance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_rds_cluster_instance_test.go b/aws/resource_aws_rds_cluster_instance_test.go index 1ae32f459ee..2d46b906b30 100644 --- a/aws/resource_aws_rds_cluster_instance_test.go +++ b/aws/resource_aws_rds_cluster_instance_test.go @@ -52,7 +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", "copy_tags_to_snapshot", "false"), + 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"), From 3faadc0cfda246e1b9b81b3aaa703fb1afed6292 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Tue, 4 Dec 2018 10:32:08 +0900 Subject: [PATCH 3/3] awRemove aws_db_parameter_group resource --- aws/resource_aws_rds_cluster_instance_test.go | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/aws/resource_aws_rds_cluster_instance_test.go b/aws/resource_aws_rds_cluster_instance_test.go index 2d46b906b30..96d3b1e031a 100644 --- a/aws/resource_aws_rds_cluster_instance_test.go +++ b/aws/resource_aws_rds_cluster_instance_test.go @@ -820,24 +820,8 @@ resource "aws_rds_cluster_instance" "cluster_instances" { identifier = "tf-cluster-instance-%d" cluster_identifier = "${aws_rds_cluster.default.id}" instance_class = "db.t2.small" - db_parameter_group_name = "${aws_db_parameter_group.bar.name}" - promotion_tier = "3" - copy_tags_to_snapshot = %t -} - -resource "aws_db_parameter_group" "bar" { - name = "tfcluster-test-group-%d" - family = "aurora5.6" - - parameter { - name = "back_log" - value = "32767" - apply_method = "pending-reboot" - } - - tags { - foo = "bar" - } + promotion_tier = "3" + copy_tags_to_snapshot = %t } -`, n, n, f, n) +`, n, n, f) }