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

Acceptance test import refactor for rds cluster resources #10008

Merged
merged 1 commit into from
Sep 24, 2019
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
179 changes: 99 additions & 80 deletions aws/resource_aws_rds_cluster_parameter_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,9 @@ func testSweepRdsClusterParameterGroups(region string) error {
return nil
}

func TestAccAWSDBClusterParameterGroup_importBasic(t *testing.T) {
resourceName := "aws_rds_cluster_parameter_group.bar"

parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDBClusterParameterGroupConfig(parameterGroupName),
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) {
var v rds.DBClusterParameterGroup

resourceName := "aws_rds_cluster_parameter_group.test"
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -119,64 +96,69 @@ func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) {
{
Config: testAccAWSDBClusterParameterGroupConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupExists(resourceName, &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v, parameterGroupName),
resource.TestMatchResourceAttr("aws_rds_cluster_parameter_group.bar", "arn", regexp.MustCompile(`^arn:[^:]+:rds:[^:]+:\d{12}:cluster-pg:.+`)),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(`^arn:[^:]+:rds:[^:]+:\d{12}:cluster-pg:.+`)),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resourceName, "name", parameterGroupName),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resourceName, "family", "aurora5.6"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "description", "Test cluster parameter group for terraform"),
resourceName, "description", "Test cluster parameter group for terraform"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.1708034931.name", "character_set_results"),
resourceName, "parameter.1708034931.name", "character_set_results"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.1708034931.value", "utf8"),
resourceName, "parameter.1708034931.value", "utf8"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2421266705.name", "character_set_server"),
resourceName, "parameter.2421266705.name", "character_set_server"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2421266705.value", "utf8"),
resourceName, "parameter.2421266705.value", "utf8"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2478663599.name", "character_set_client"),
resourceName, "parameter.2478663599.name", "character_set_client"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2478663599.value", "utf8"),
resourceName, "parameter.2478663599.value", "utf8"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "tags.%", "1"),
resourceName, "tags.%", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSDBClusterParameterGroupAddParametersConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupExists(resourceName, &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v, parameterGroupName),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resourceName, "name", parameterGroupName),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resourceName, "family", "aurora5.6"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "description", "Test cluster parameter group for terraform"),
resourceName, "description", "Test cluster parameter group for terraform"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.1706463059.name", "collation_connection"),
resourceName, "parameter.1706463059.name", "collation_connection"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.1706463059.value", "utf8_unicode_ci"),
resourceName, "parameter.1706463059.value", "utf8_unicode_ci"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.1708034931.name", "character_set_results"),
resourceName, "parameter.1708034931.name", "character_set_results"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.1708034931.value", "utf8"),
resourceName, "parameter.1708034931.value", "utf8"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2421266705.name", "character_set_server"),
resourceName, "parameter.2421266705.name", "character_set_server"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2421266705.value", "utf8"),
resourceName, "parameter.2421266705.value", "utf8"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2475805061.name", "collation_server"),
resourceName, "parameter.2475805061.name", "collation_server"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2475805061.value", "utf8_unicode_ci"),
resourceName, "parameter.2475805061.value", "utf8_unicode_ci"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2478663599.name", "character_set_client"),
resourceName, "parameter.2478663599.name", "character_set_client"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2478663599.value", "utf8"),
resourceName, "parameter.2478663599.value", "utf8"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "tags.%", "2"),
resourceName, "tags.%", "2"),
),
},
},
Expand All @@ -186,6 +168,7 @@ func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) {
func TestAccAWSDBClusterParameterGroup_withApplyMethod(t *testing.T) {
var v rds.DBClusterParameterGroup
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())
resourceName := "aws_rds_cluster_parameter_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -195,36 +178,42 @@ func TestAccAWSDBClusterParameterGroup_withApplyMethod(t *testing.T) {
{
Config: testAccAWSDBClusterParameterGroupConfigWithApplyMethod(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupExists(resourceName, &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v, parameterGroupName),
resource.TestMatchResourceAttr(
"aws_rds_cluster_parameter_group.bar", "arn", regexp.MustCompile(`^arn:[^:]+:rds:[^:]+:\d{12}:cluster-pg:.+`)),
resourceName, "arn", regexp.MustCompile(`^arn:[^:]+:rds:[^:]+:\d{12}:cluster-pg:.+`)),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resourceName, "name", parameterGroupName),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resourceName, "family", "aurora5.6"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "description", "Test cluster parameter group for terraform"),
resourceName, "description", "Test cluster parameter group for terraform"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2421266705.name", "character_set_server"),
resourceName, "parameter.2421266705.name", "character_set_server"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2421266705.value", "utf8"),
resourceName, "parameter.2421266705.value", "utf8"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2421266705.apply_method", "immediate"),
resourceName, "parameter.2421266705.apply_method", "immediate"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2478663599.name", "character_set_client"),
resourceName, "parameter.2478663599.name", "character_set_client"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2478663599.value", "utf8"),
resourceName, "parameter.2478663599.value", "utf8"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "parameter.2478663599.apply_method", "pending-reboot"),
resourceName, "parameter.2478663599.apply_method", "pending-reboot"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSDBClusterParameterGroup_namePrefix(t *testing.T) {
var v rds.DBClusterParameterGroup
resourceName := "aws_rds_cluster_parameter_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -234,17 +223,24 @@ func TestAccAWSDBClusterParameterGroup_namePrefix(t *testing.T) {
{
Config: testAccAWSDBClusterParameterGroupConfig_namePrefix,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.test", &v),
testAccCheckAWSDBClusterParameterGroupExists(resourceName, &v),
resource.TestMatchResourceAttr(
"aws_rds_cluster_parameter_group.test", "name", regexp.MustCompile("^tf-test-")),
resourceName, "name", regexp.MustCompile("^tf-test-")),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name_prefix"},
},
},
})
}

func TestAccAWSDBClusterParameterGroup_namePrefix_Parameter(t *testing.T) {
var v rds.DBClusterParameterGroup
resourceName := "aws_rds_cluster_parameter_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -254,17 +250,24 @@ func TestAccAWSDBClusterParameterGroup_namePrefix_Parameter(t *testing.T) {
{
Config: testAccAWSDBClusterParameterGroupConfig_namePrefix_Parameter,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.test", &v),
testAccCheckAWSDBClusterParameterGroupExists(resourceName, &v),
resource.TestMatchResourceAttr(
"aws_rds_cluster_parameter_group.test", "name", regexp.MustCompile("^tf-test-")),
resourceName, "name", regexp.MustCompile("^tf-test-")),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name_prefix"},
},
},
})
}

func TestAccAWSDBClusterParameterGroup_generatedName(t *testing.T) {
var v rds.DBClusterParameterGroup
resourceName := "aws_rds_cluster_parameter_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -274,15 +277,21 @@ func TestAccAWSDBClusterParameterGroup_generatedName(t *testing.T) {
{
Config: testAccAWSDBClusterParameterGroupConfig_generatedName,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.test", &v),
testAccCheckAWSDBClusterParameterGroupExists(resourceName, &v),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSDBClusterParameterGroup_generatedName_Parameter(t *testing.T) {
var v rds.DBClusterParameterGroup
resourceName := "aws_rds_cluster_parameter_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -292,16 +301,21 @@ func TestAccAWSDBClusterParameterGroup_generatedName_Parameter(t *testing.T) {
{
Config: testAccAWSDBClusterParameterGroupConfig_generatedName_Parameter,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.test", &v),
testAccCheckAWSDBClusterParameterGroupExists(resourceName, &v),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSDBClusterParameterGroup_disappears(t *testing.T) {
var v rds.DBClusterParameterGroup

resourceName := "aws_rds_cluster_parameter_group.test"
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -312,7 +326,7 @@ func TestAccAWSDBClusterParameterGroup_disappears(t *testing.T) {
{
Config: testAccAWSDBClusterParameterGroupConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupExists(resourceName, &v),
testAccAWSDBClusterParameterGroupDisappears(&v),
),
ExpectNonEmptyPlan: true,
Expand All @@ -321,9 +335,9 @@ func TestAccAWSDBClusterParameterGroup_disappears(t *testing.T) {
})
}

func TestAccAWSDBClusterParameterGroupOnly(t *testing.T) {
func TestAccAWSDBClusterParameterGroup_only(t *testing.T) {
var v rds.DBClusterParameterGroup

resourceName := "aws_rds_cluster_parameter_group.test"
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-tf-%d", acctest.RandInt())

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -334,16 +348,21 @@ func TestAccAWSDBClusterParameterGroupOnly(t *testing.T) {
{
Config: testAccAWSDBClusterParameterGroupOnlyConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupExists(resourceName, &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v, parameterGroupName),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resourceName, "name", parameterGroupName),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resourceName, "family", "aurora5.6"),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "description", "Managed by Terraform"),
resourceName, "description", "Managed by Terraform"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -461,7 +480,7 @@ func testAccCheckAWSDBClusterParameterGroupExists(n string, v *rds.DBClusterPara

func testAccAWSDBClusterParameterGroupConfig(name string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster_parameter_group" "bar" {
resource "aws_rds_cluster_parameter_group" "test" {
name = "%s"
family = "aurora5.6"
description = "Test cluster parameter group for terraform"
Expand Down Expand Up @@ -490,7 +509,7 @@ resource "aws_rds_cluster_parameter_group" "bar" {

func testAccAWSDBClusterParameterGroupConfigWithApplyMethod(name string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster_parameter_group" "bar" {
resource "aws_rds_cluster_parameter_group" "test" {
name = "%s"
family = "aurora5.6"
description = "Test cluster parameter group for terraform"
Expand All @@ -515,7 +534,7 @@ resource "aws_rds_cluster_parameter_group" "bar" {

func testAccAWSDBClusterParameterGroupAddParametersConfig(name string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster_parameter_group" "bar" {
resource "aws_rds_cluster_parameter_group" "test" {
name = "%s"
family = "aurora5.6"
description = "Test cluster parameter group for terraform"
Expand Down Expand Up @@ -555,7 +574,7 @@ resource "aws_rds_cluster_parameter_group" "bar" {

func testAccAWSDBClusterParameterGroupOnlyConfig(name string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster_parameter_group" "bar" {
resource "aws_rds_cluster_parameter_group" "test" {
name = "%s"
family = "aurora5.6"
}
Expand Down
Loading