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

resource/aws_db_option_group: Add version field #2590

Merged
merged 1 commit into from
Apr 12, 2018
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
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,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this attribute be retrieved by the AWS API without a user setting it?
If so, this should also have a Computed: true, option

},
},
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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As option is of type TypeSet (https://github.com/terraform-providers/terraform-provider-aws/pull/2590/files#diff-e61872fad819968684cae97c19506df5R70), a given entry can be retrieved with a hash, as in: https://github.com/chrisminton/terraform-provider-aws/blob/89c8a140afce2bc728b7e3e07c526f961c02f875/aws/resource_aws_db_option_group_test.go#L226

What I usually do is get the hash from the logs, using TF_LOG=DEBUG with TF_LOG_PATH=terraform.log as in:

TF_LOG=DEBUG make testacc TEST=./aws TESTARGS='-run= TestAccAWSDBOptionGroup_multipleOptions'

This will put multiple log lines in the aws/terraform.log file, making it easier for you to debug :)

Note that the hash will change if parts of the option change.

),
},

{
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