provider/aws: Support Import of `aws_db_option_group`

```
make testacc TEST=./builtin/providers/aws
TESTARGS='-run=TestAccAWSDBOptionGroup_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /vendor/)
TF_ACC=1 go test ./builtin/providers/aws -v
-run=TestAccAWSDBOptionGroup_ -timeout 120m
=== RUN   TestAccAWSDBOptionGroup_importBasic
--- PASS: TestAccAWSDBOptionGroup_importBasic (22.98s)
=== RUN   TestAccAWSDBOptionGroup_basic
--- PASS: TestAccAWSDBOptionGroup_basic (22.54s)
=== RUN   TestAccAWSDBOptionGroup_OptionSettings
--- PASS: TestAccAWSDBOptionGroup_OptionSettings (38.62s)
=== RUN   TestAccAWSDBOptionGroup_sqlServerOptionsUpdate
--- PASS: TestAccAWSDBOptionGroup_sqlServerOptionsUpdate (37.64s)
=== RUN   TestAccAWSDBOptionGroup_multipleOptions
--- PASS: TestAccAWSDBOptionGroup_multipleOptions (24.32s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    146.123s
```
This commit is contained in:
stack72 2016-07-07 16:45:56 +01:00
parent 21e2173e0a
commit 6f122c3f05
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
2 changed files with 37 additions and 2 deletions

View File

@ -0,0 +1,31 @@
package aws
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSDBOptionGroup_importBasic(t *testing.T) {
resourceName := "aws_db_option_group.bar"
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{
resource.TestStep{
Config: testAccAWSDBOptionGroupBasicConfig(rName),
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

View File

@ -19,6 +19,9 @@ func resourceAwsDbOptionGroup() *schema.Resource {
Read: resourceAwsDbOptionGroupRead,
Update: resourceAwsDbOptionGroupUpdate,
Delete: resourceAwsDbOptionGroupDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"arn": &schema.Schema{
@ -125,7 +128,7 @@ func resourceAwsDbOptionGroupCreate(d *schema.ResourceData, meta interface{}) er
func resourceAwsDbOptionGroupRead(d *schema.ResourceData, meta interface{}) error {
rdsconn := meta.(*AWSClient).rdsconn
params := &rds.DescribeOptionGroupsInput{
OptionGroupName: aws.String(d.Get("name").(string)),
OptionGroupName: aws.String(d.Id()),
}
log.Printf("[DEBUG] Describe DB Option Group: %#v", params)
@ -143,7 +146,7 @@ func resourceAwsDbOptionGroupRead(d *schema.ResourceData, meta interface{}) erro
var option *rds.OptionGroup
for _, ogl := range options.OptionGroupsList {
if *ogl.OptionGroupName == d.Get("name").(string) {
if *ogl.OptionGroupName == d.Id() {
option = ogl
break
}
@ -153,6 +156,7 @@ func resourceAwsDbOptionGroupRead(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Unable to find Option Group: %#v", options.OptionGroupsList)
}
d.Set("name", option.OptionGroupName)
d.Set("major_engine_version", option.MajorEngineVersion)
d.Set("engine_name", option.EngineName)
d.Set("option_group_description", option.OptionGroupDescription)