diff --git a/aws/resource_aws_rds_cluster_instance.go b/aws/resource_aws_rds_cluster_instance.go index 2c1e9d24a01..b94d644c276 100644 --- a/aws/resource_aws_rds_cluster_instance.go +++ b/aws/resource_aws_rds_cluster_instance.go @@ -434,15 +434,15 @@ func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{ requestUpdate = true } - if d.HasChange("performance_insights_enabled") { + if d.HasChange("performance_insights_enabled") || d.HasChange("performance_insights_kms_key_id") { d.SetPartial("performance_insights_enabled") req.EnablePerformanceInsights = aws.Bool(d.Get("performance_insights_enabled").(bool)) - requestUpdate = true - } - if d.HasChange("performance_insights_kms_key_id") { - d.SetPartial("performance_insights_kms_key_id") - req.PerformanceInsightsKMSKeyId = aws.String(d.Get("performance_insights_kms_key_id").(string)) + if v, ok := d.GetOk("performance_insights_kms_key_id"); ok { + d.SetPartial("performance_insights_kms_key_id") + req.PerformanceInsightsKMSKeyId = aws.String(v.(string)) + } + requestUpdate = true } diff --git a/aws/resource_aws_rds_cluster_instance_test.go b/aws/resource_aws_rds_cluster_instance_test.go index 481535cc564..3febb72b1fe 100644 --- a/aws/resource_aws_rds_cluster_instance_test.go +++ b/aws/resource_aws_rds_cluster_instance_test.go @@ -384,7 +384,6 @@ func TestAccAWSRDSClusterInstance_withInstanceEnhancedMonitor(t *testing.T) { func TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql1(t *testing.T) { var dbInstance rds.DBInstance - kmsKeyResourceName := "aws_kms_key.test" resourceName := "aws_rds_cluster_instance.test" rName := acctest.RandomWithPrefix("tf-acc-test") @@ -398,7 +397,6 @@ func TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql1(t *tes Check: resource.ComposeTestCheckFunc( testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"), - resource.TestCheckResourceAttrPair(resourceName, "performance_insights_kms_key_id", kmsKeyResourceName, "arn"), ), }, { @@ -416,7 +414,6 @@ func TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql1(t *tes func TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql2(t *testing.T) { var dbInstance rds.DBInstance - kmsKeyResourceName := "aws_kms_key.test" resourceName := "aws_rds_cluster_instance.test" rName := acctest.RandomWithPrefix("tf-acc-test") @@ -430,7 +427,6 @@ func TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql2(t *tes Check: resource.ComposeTestCheckFunc( testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"), - resource.TestCheckResourceAttrPair(resourceName, "performance_insights_kms_key_id", kmsKeyResourceName, "arn"), ), }, { @@ -448,7 +444,6 @@ func TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql2(t *tes func TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraPostgresql(t *testing.T) { var dbInstance rds.DBInstance - kmsKeyResourceName := "aws_kms_key.test" resourceName := "aws_rds_cluster_instance.test" rName := acctest.RandomWithPrefix("tf-acc-test") @@ -459,6 +454,169 @@ func TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraPostgresql(t Steps: []resource.TestStep{ { Config: testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraPostgresql(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "apply_immediately", + "identifier_prefix", + }, + }, + }, + }) +} + +func TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraMysql1(t *testing.T) { + var dbInstance rds.DBInstance + kmsKeyResourceName := "aws_kms_key.test" + resourceName := "aws_rds_cluster_instance.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSClusterInstanceConfigPerformanceInsightsKmsKeyIdAuroraMysql1(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"), + resource.TestCheckResourceAttrPair(resourceName, "performance_insights_kms_key_id", kmsKeyResourceName, "arn"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "apply_immediately", + "identifier_prefix", + }, + }, + }, + }) +} + +func TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraMysql1_DefaultKeyToCustomKey(t *testing.T) { + var dbInstance rds.DBInstance + resourceName := "aws_rds_cluster_instance.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraMysql1(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "apply_immediately", + "identifier_prefix", + }, + }, + { + Config: testAccAWSClusterInstanceConfigPerformanceInsightsKmsKeyIdAuroraMysql1(rName), + ExpectError: regexp.MustCompile(`InvalidParameterCombination: You cannot change your Performance Insights KMS key`), + }, + }, + }) +} + +func TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraMysql2(t *testing.T) { + var dbInstance rds.DBInstance + kmsKeyResourceName := "aws_kms_key.test" + resourceName := "aws_rds_cluster_instance.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSClusterInstanceConfigPerformanceInsightsKmsKeyIdAuroraMysql2(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"), + resource.TestCheckResourceAttrPair(resourceName, "performance_insights_kms_key_id", kmsKeyResourceName, "arn"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "apply_immediately", + "identifier_prefix", + }, + }, + }, + }) +} + +func TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraMysql2_DefaultKeyToCustomKey(t *testing.T) { + var dbInstance rds.DBInstance + resourceName := "aws_rds_cluster_instance.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraMysql2(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "apply_immediately", + "identifier_prefix", + }, + }, + { + Config: testAccAWSClusterInstanceConfigPerformanceInsightsKmsKeyIdAuroraMysql2(rName), + ExpectError: regexp.MustCompile(`InvalidParameterCombination: You cannot change your Performance Insights KMS key`), + }, + }, + }) +} + +func TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraPostgresql(t *testing.T) { + var dbInstance rds.DBInstance + kmsKeyResourceName := "aws_kms_key.test" + resourceName := "aws_rds_cluster_instance.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSClusterInstanceConfigPerformanceInsightsKmsKeyIdAuroraPostgresql(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"), @@ -478,6 +636,40 @@ func TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraPostgresql(t }) } +func TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraPostgresql_DefaultKeyToCustomKey(t *testing.T) { + var dbInstance rds.DBInstance + resourceName := "aws_rds_cluster_instance.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraPostgresql(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "apply_immediately", + "identifier_prefix", + }, + }, + { + Config: testAccAWSClusterInstanceConfigPerformanceInsightsKmsKeyIdAuroraPostgresql(rName), + ExpectError: regexp.MustCompile(`InvalidParameterCombination: You cannot change your Performance Insights KMS key`), + }, + }, + }) +} + // Add some random to the name, to avoid collision func testAccAWSClusterInstanceConfig(n int) string { return fmt.Sprintf(` @@ -486,7 +678,7 @@ resource "aws_rds_cluster" "default" { availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] database_name = "mydb" master_username = "foo" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" skip_final_snapshot = true } @@ -522,7 +714,7 @@ resource "aws_rds_cluster" "default" { availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] database_name = "mydb" master_username = "foo" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" skip_final_snapshot = true } @@ -561,7 +753,7 @@ resource "aws_rds_cluster" "default" { availability_zones = ["${data.aws_availability_zones.available.names[0]}", "${data.aws_availability_zones.available.names[1]}", "${data.aws_availability_zones.available.names[2]}"] database_name = "mydb" master_username = "foo" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" skip_final_snapshot = true } @@ -721,7 +913,7 @@ resource "aws_rds_cluster" "default" { availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] database_name = "mydb" master_username = "foo" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" storage_encrypted = true kms_key_id = "${aws_kms_key.foo.arn}" skip_final_snapshot = true @@ -758,7 +950,7 @@ resource "aws_rds_cluster" "default" { availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] database_name = "mydb" master_username = "foo" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" skip_final_snapshot = true } @@ -852,6 +1044,71 @@ resource "aws_db_parameter_group" "bar" { func testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraMysql1(rName string) string { return fmt.Sprintf(` +resource "aws_rds_cluster" "test" { + cluster_identifier = %[1]q + database_name = "mydb" + engine = "aurora" + master_password = "mustbeeightcharacters" + master_username = "foo" + skip_final_snapshot = true +} + +resource "aws_rds_cluster_instance" "test" { + cluster_identifier = "${aws_rds_cluster.test.id}" + engine = "${aws_rds_cluster.test.engine}" + identifier = %[1]q + instance_class = "db.r4.large" + performance_insights_enabled = true +} +`, rName) +} + +func testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraMysql2(rName string) string { + return fmt.Sprintf(` +resource "aws_rds_cluster" "test" { + cluster_identifier = %[1]q + database_name = "mydb" + engine = "aurora-mysql" + engine_version = "5.7.mysql_aurora.2.04.2" + master_password = "mustbeeightcharacters" + master_username = "foo" + skip_final_snapshot = true +} + +resource "aws_rds_cluster_instance" "test" { + cluster_identifier = "${aws_rds_cluster.test.id}" + engine = "${aws_rds_cluster.test.engine}" + engine_version = "${aws_rds_cluster.test.engine_version}" + identifier = %[1]q + instance_class = "db.r4.large" + performance_insights_enabled = true +} +`, rName) +} + +func testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraPostgresql(rName string) string { + return fmt.Sprintf(` +resource "aws_rds_cluster" "test" { + cluster_identifier = %[1]q + database_name = "mydb" + engine = "aurora-postgresql" + master_password = "mustbeeightcharacters" + master_username = "foo" + skip_final_snapshot = true +} + +resource "aws_rds_cluster_instance" "test" { + cluster_identifier = "${aws_rds_cluster.test.id}" + engine = "${aws_rds_cluster.test.engine}" + identifier = %[1]q + instance_class = "db.r4.large" + performance_insights_enabled = true +} +`, rName) +} + +func testAccAWSClusterInstanceConfigPerformanceInsightsKmsKeyIdAuroraMysql1(rName string) string { + return fmt.Sprintf(` resource "aws_kms_key" "test" { deletion_window_in_days = 7 } @@ -860,7 +1117,7 @@ resource "aws_rds_cluster" "test" { cluster_identifier = %[1]q database_name = "mydb" engine = "aurora" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" master_username = "foo" skip_final_snapshot = true } @@ -876,7 +1133,7 @@ resource "aws_rds_cluster_instance" "test" { `, rName) } -func testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraMysql2(rName string) string { +func testAccAWSClusterInstanceConfigPerformanceInsightsKmsKeyIdAuroraMysql2(rName string) string { return fmt.Sprintf(` resource "aws_kms_key" "test" { deletion_window_in_days = 7 @@ -887,7 +1144,7 @@ resource "aws_rds_cluster" "test" { database_name = "mydb" engine = "aurora-mysql" engine_version = "5.7.mysql_aurora.2.04.2" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" master_username = "foo" skip_final_snapshot = true } @@ -904,7 +1161,7 @@ resource "aws_rds_cluster_instance" "test" { `, rName) } -func testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraPostgresql(rName string) string { +func testAccAWSClusterInstanceConfigPerformanceInsightsKmsKeyIdAuroraPostgresql(rName string) string { return fmt.Sprintf(` resource "aws_kms_key" "test" { deletion_window_in_days = 7 @@ -914,7 +1171,7 @@ resource "aws_rds_cluster" "test" { cluster_identifier = %[1]q database_name = "mydb" engine = "aurora-postgresql" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" master_username = "foo" skip_final_snapshot = true } @@ -935,7 +1192,7 @@ func testAccAWSRDSClusterInstanceConfig_PubliclyAccessible(rName string, publicl resource "aws_rds_cluster" "test" { cluster_identifier = %q master_username = "foo" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" skip_final_snapshot = true } @@ -956,7 +1213,7 @@ resource "aws_rds_cluster" "default" { availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] database_name = "mydb" master_username = "foo" - master_password = "mustbeeightcharaters" + master_password = "mustbeeightcharacters" skip_final_snapshot = true }