Skip to content

Commit

Permalink
Add StateFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-rich committed Mar 4, 2021
1 parent 59c72cd commit a72bba1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/17909.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_db_parameter_group: Store all values in lowercase to prevent unexpected diffs
```
8 changes: 7 additions & 1 deletion aws/resource_aws_db_parameter_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ func resourceAwsDbParameterGroup() *schema.Resource {
"value": {
Type: schema.TypeString,
Required: true,
StateFunc: func(v interface{}) string {
return strings.ToLower(v.(string))
},
},
"apply_method": {
Type: schema.TypeString,
Optional: true,
Default: "immediate",
StateFunc: func(v interface{}) string {
return strings.ToLower(v.(string))
},
Default: "immediate",
},
},
},
Expand Down
73 changes: 67 additions & 6 deletions aws/resource_aws_db_parameter_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ func TestAccAWSDBParameterGroup_basic(t *testing.T) {
})
}

func TestAccAWSDBParameterGroup_caseWithMixedParameters(t *testing.T) {
groupName := fmt.Sprintf("parameter-group-test-terraform-%d", acctest.RandInt())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBParameterGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDBParameterGroupConfigCaseWithMixedParameters(groupName),
Check: resource.ComposeTestCheckFunc(),
},
},
})
}

func TestAccAWSDBParameterGroup_limit(t *testing.T) {
var v rds.DBParameterGroup
resourceName := "aws_db_parameter_group.test"
Expand Down Expand Up @@ -286,7 +302,7 @@ func TestAccAWSDBParameterGroup_limit(t *testing.T) {
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "event_scheduler",
"value": "ON",
"value": "on",
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "innodb_buffer_pool_dump_at_shutdown",
Expand Down Expand Up @@ -322,7 +338,7 @@ func TestAccAWSDBParameterGroup_limit(t *testing.T) {
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "log_output",
"value": "FILE",
"value": "file",
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "max_allowed_packet",
Expand All @@ -346,7 +362,7 @@ func TestAccAWSDBParameterGroup_limit(t *testing.T) {
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "tx_isolation",
"value": "REPEATABLE-READ",
"value": "repeatable-read",
}),
),
},
Expand Down Expand Up @@ -465,7 +481,7 @@ func TestAccAWSDBParameterGroup_limit(t *testing.T) {
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "event_scheduler",
"value": "ON",
"value": "on",
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "innodb_buffer_pool_dump_at_shutdown",
Expand Down Expand Up @@ -501,7 +517,7 @@ func TestAccAWSDBParameterGroup_limit(t *testing.T) {
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "log_output",
"value": "FILE",
"value": "file",
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "max_allowed_packet",
Expand All @@ -525,7 +541,7 @@ func TestAccAWSDBParameterGroup_limit(t *testing.T) {
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "parameter.*", map[string]string{
"name": "tx_isolation",
"value": "REPEATABLE-READ",
"value": "repeatable-read",
}),
),
},
Expand Down Expand Up @@ -907,6 +923,51 @@ resource "aws_db_parameter_group" "test" {
`, n)
}

func testAccAWSDBParameterGroupConfigCaseWithMixedParameters(n string) string {
return composeConfig(testAccAWSDBInstanceConfig_orderableClassMysql(), fmt.Sprintf(`
resource "aws_db_parameter_group" "test" {
name = %[1]q
family = "mysql5.6"
parameter {
name = "character_set_server"
value = "utf8mb4"
apply_method = "pending-reboot"
}
parameter {
name = "innodb_large_prefix"
value = 1
apply_method = "pending-reboot"
}
parameter {
name = "innodb_file_format"
value = "Barracuda"
apply_method = "pending-reboot"
}
parameter {
name = "innodb_log_file_size"
value = 2147483648
apply_method = "pending-reboot"
}
parameter {
name = "sql_mode"
value = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
apply_method = "pending-reboot"
}
parameter {
name = "innodb_log_buffer_size"
value = 268435456
apply_method = "pending-reboot"
}
parameter {
name = "max_allowed_packet"
value = 268435456
apply_method = "pending-reboot"
}
}
`, n))
}

func testAccAWSDBParameterGroupConfigWithApplyMethod(n string) string {
return fmt.Sprintf(`
resource "aws_db_parameter_group" "test" {
Expand Down

0 comments on commit a72bba1

Please sign in to comment.