Skip to content

Commit

Permalink
tests/resource/aws_rds_cluster_instance: Ensure covering acceptance t…
Browse files Browse the repository at this point in the history
…ests for performance_insights_enabled on Aurora MySQL 1/2 and Postgresql

Reference: #9227
Reference: #9635

Output from acceptance testing:

```
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql1 (629.12s)
--- PASS: TestAccAWSRDSClusterInstance_namePrefix (677.80s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql2 (679.39s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraPostgresql (680.27s)
--- PASS: TestAccAWSRDSClusterInstance_CopyTagsToSnapshot (699.01s)
--- PASS: TestAccAWSRDSClusterInstance_generatedName (712.49s)
--- PASS: TestAccAWSRDSClusterInstance_az (722.51s)
--- PASS: TestAccAWSRDSClusterInstance_disappears (763.18s)
--- PASS: TestAccAWSRDSClusterInstance_withInstanceEnhancedMonitor (873.08s)
--- PASS: TestAccAWSRDSClusterInstance_kmsKey (1062.91s)
--- PASS: TestAccAWSRDSClusterInstance_PubliclyAccessible (1247.95s)
--- PASS: TestAccAWSRDSClusterInstance_basic (1423.02s)
```
  • Loading branch information
bflad committed Aug 13, 2019
1 parent cc059c5 commit 7567639
Showing 1 changed file with 135 additions and 53 deletions.
188 changes: 135 additions & 53 deletions aws/resource_aws_rds_cluster_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,28 +382,91 @@ func TestAccAWSRDSClusterInstance_withInstanceEnhancedMonitor(t *testing.T) {
})
}

func TestAccAWSRDSClusterInstance_withInstancePerformanceInsights(t *testing.T) {
var v rds.DBInstance
keyRegex := regexp.MustCompile("^arn:aws:kms:")
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")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterInstancePerformanceInsights(acctest.RandInt()),
Config: testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraMysql1(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v),
testAccCheckAWSDBClusterInstanceAttributes(&v),
resource.TestCheckResourceAttr(
"aws_rds_cluster_instance.cluster_instances", "performance_insights_enabled", "true"),
resource.TestMatchResourceAttr(
"aws_rds_cluster_instance.cluster_instances", "performance_insights_kms_key_id", keyRegex),
testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"),
resource.TestCheckResourceAttrPair(resourceName, "performance_insights_kms_key_id", kmsKeyResourceName, "arn"),
),
},
{
ResourceName: "aws_rds_cluster_instance.cluster_instances",
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"identifier_prefix",
},
},
},
})
}

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")

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"),
resource.TestCheckResourceAttrPair(resourceName, "performance_insights_kms_key_id", kmsKeyResourceName, "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"identifier_prefix",
},
},
},
})
}

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")

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"),
resource.TestCheckResourceAttrPair(resourceName, "performance_insights_kms_key_id", kmsKeyResourceName, "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
Expand Down Expand Up @@ -787,65 +850,84 @@ resource "aws_db_parameter_group" "bar" {
`, n, n, n, n, n, n)
}

func testAccAWSClusterInstancePerformanceInsights(n int) string {
func testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraMysql1(rName string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "foo" {
description = "Terraform acc test %d"
resource "aws_kms_key" "test" {
deletion_window_in_days = 7
}
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "kms-tf-1",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "kms:*",
"Resource": "*"
}
]
resource "aws_rds_cluster" "test" {
cluster_identifier = %[1]q
database_name = "mydb"
engine = "aurora"
master_password = "mustbeeightcharaters"
master_username = "foo"
skip_final_snapshot = true
}
POLICY
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
performance_insights_kms_key_id = "${aws_kms_key.test.arn}"
}
`, rName)
}

resource "aws_rds_cluster" "default" {
engine = "aurora-postgresql"
cluster_identifier = "tf-aurora-cluster-test-%d"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
func testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraMysql2(rName string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "test" {
deletion_window_in_days = 7
}
resource "aws_rds_cluster" "test" {
cluster_identifier = %[1]q
database_name = "mydb"
master_username = "foo"
engine = "aurora-mysql"
engine_version = "5.7.mysql_aurora.2.04.2"
master_password = "mustbeeightcharaters"
storage_encrypted = true
master_username = "foo"
skip_final_snapshot = true
}
resource "aws_rds_cluster_instance" "cluster_instances" {
engine = "aurora-postgresql"
identifier = "tf-cluster-instance-%d"
cluster_identifier = "${aws_rds_cluster.default.id}"
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"
db_parameter_group_name = "${aws_db_parameter_group.bar.name}"
performance_insights_enabled = true
performance_insights_kms_key_id = "${aws_kms_key.foo.arn}"
performance_insights_kms_key_id = "${aws_kms_key.test.arn}"
}
`, rName)
}

resource "aws_db_parameter_group" "bar" {
name = "tfcluster-test-group-%d"
family = "aurora-postgresql10"
func testAccAWSClusterInstanceConfigPerformanceInsightsEnabledAuroraPostgresql(rName string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "test" {
deletion_window_in_days = 7
}
parameter {
name = "authentication_timeout"
value = "10"
}
resource "aws_rds_cluster" "test" {
cluster_identifier = %[1]q
database_name = "mydb"
engine = "aurora-postgresql"
master_password = "mustbeeightcharaters"
master_username = "foo"
skip_final_snapshot = true
}
tags = {
foo = "bar"
}
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
performance_insights_kms_key_id = "${aws_kms_key.test.arn}"
}
`, n, n, n, n)
`, rName)
}

func testAccAWSRDSClusterInstanceConfig_PubliclyAccessible(rName string, publiclyAccessible bool) string {
Expand Down

0 comments on commit 7567639

Please sign in to comment.