Skip to content

Commit

Permalink
Update RDS Option groups to allow version option
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Minton committed Nov 30, 2017
1 parent 7c14a34 commit 89c8a14
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
9 changes: 9 additions & 0 deletions aws/resource_aws_db_option_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func resourceAwsDbOptionGroup() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"version": {
Type: schema.TypeString,
Optional: true,
},
},
},
Set: resourceAwsDbOptionHash,
Expand Down Expand Up @@ -353,6 +357,11 @@ func resourceAwsDbOptionHash(v interface{}) int {
for _, sgRaw := range m["db_security_group_memberships"].(*schema.Set).List() {
buf.WriteString(fmt.Sprintf("%s-", sgRaw.(string)))
}

if _, ok := m["version"]; ok {
buf.WriteString(fmt.Sprintf("%s-", m["version"].(string)))
}

return hashcode.String(buf.String())
}

Expand Down
116 changes: 116 additions & 0 deletions aws/resource_aws_db_option_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,44 @@ func TestAccAWSDBOptionGroup_sqlServerOptionsUpdate(t *testing.T) {
})
}

func TestAccAWSDBOptionGroup_OracleOptionsUpdate(t *testing.T) {
var v rds.OptionGroup
rName := fmt.Sprintf("option-group-test-terraform-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBOptionGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDBOptionGroupOracleEEOptionSettings(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBOptionGroupExists("aws_db_option_group.bar", &v),
resource.TestCheckResourceAttr(
"aws_db_option_group.bar", "name", rName),
resource.TestCheckResourceAttr(
"aws_db_option_group.bar", "option.#", "1"),
resource.TestCheckResourceAttr(
"aws_db_option_group.bar", "option.0.version", "12.1.0.4.v1"),
),
},

{
Config: testAccAWSDBOptionGroupOracleEEOptionSettings_update(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBOptionGroupExists("aws_db_option_group.bar", &v),
resource.TestCheckResourceAttr(
"aws_db_option_group.bar", "name", rName),
resource.TestCheckResourceAttr(
"aws_db_option_group.bar", "option.#", "1"),
resource.TestCheckResourceAttr(
"aws_db_option_group.bar", "option.0.version", "12.1.0.5.v1"),
),
},
},
})
}

func TestAccAWSDBOptionGroup_multipleOptions(t *testing.T) {
var v rds.OptionGroup
rName := fmt.Sprintf("option-group-test-terraform-%s", acctest.RandString(5))
Expand Down Expand Up @@ -493,6 +531,84 @@ resource "aws_db_option_group" "bar" {
`, r)
}

func testAccAWSDBOptionGroupOracleEEOptionSettings(r string) string {
return fmt.Sprintf(`
resource "aws_security_group" "foo" {
name = "terraform-test-issue_748"
description = "SG for test of issue 748"
}
resource "aws_db_option_group" "bar" {
name = "%s"
option_group_description = "Test option group for terraform issue 748"
engine_name = "oracle-ee"
major_engine_version = "12.1"
option {
option_name = "OEM_AGENT"
port = "3872"
version = "12.1.0.4.v1"
vpc_security_group_memberships = ["${aws_security_group.foo.id}"]
option_settings {
name = "OMS_PORT"
value = "4903"
}
option_settings {
name = "OMS_HOST"
value = "oem.host.value"
}
option_settings {
name = "AGENT_REGISTRATION_PASSWORD"
value = "password"
}
}
}
`, r)
}

func testAccAWSDBOptionGroupOracleEEOptionSettings_update(r string) string {
return fmt.Sprintf(`
resource "aws_security_group" "foo" {
name = "terraform-test-issue_748"
description = "SG for test of issue 748"
}
resource "aws_db_option_group" "bar" {
name = "%s"
option_group_description = "Test option group for terraform issue 748"
engine_name = "oracle-ee"
major_engine_version = "12.1"
option {
option_name = "OEM_AGENT"
port = "3872"
version = "12.1.0.5.v1"
vpc_security_group_memberships = ["${aws_security_group.foo.id}"]
option_settings {
name = "OMS_PORT"
value = "4903"
}
option_settings {
name = "OMS_HOST"
value = "oem.host.value"
}
option_settings {
name = "AGENT_REGISTRATION_PASSWORD"
value = "password"
}
}
}
`, r)
}

func testAccAWSDBOptionGroupMultipleOptions(r string) string {
return fmt.Sprintf(`
resource "aws_db_option_group" "bar" {
Expand Down
8 changes: 8 additions & 0 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ func expandOptionConfiguration(configured []interface{}) ([]*rds.OptionConfigura
o.OptionSettings = expandOptionSetting(raw.(*schema.Set).List())
}

if raw, ok := data["version"]; ok && raw.(string) != "" {
o.OptionVersion = aws.String(raw.(string))
}

option = append(option, o)
}

Expand Down Expand Up @@ -635,6 +639,10 @@ func flattenOptions(list []*rds.Option) []map[string]interface{} {
if i.Port != nil {
r["port"] = int(*i.Port)
}
r["version"] = ""
if i.OptionVersion != nil {
r["version"] = strings.ToLower(*i.OptionVersion)
}
if i.VpcSecurityGroupMemberships != nil {
vpcs := make([]string, 0, len(i.VpcSecurityGroupMemberships))
for _, vpc := range i.VpcSecurityGroupMemberships {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/db_option_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Option blocks support the following:
* `option_name` - (Required) The Name of the Option (e.g. MEMCACHED).
* `option_settings` - (Optional) A list of option settings to apply.
* `port` - (Optional) The Port number when connecting to the Option (e.g. 11211).
* `version` - (Optional) The OptionVersion string when connecting to the Option (e.g. 13.1.0.0).
* `db_security_group_memberships` - (Optional) A list of DB Security Groups for which the option is enabled.
* `vpc_security_group_memberships` - (Optional) A list of VPC Security Groups for which the option is enabled.

Expand Down

0 comments on commit 89c8a14

Please sign in to comment.