Merge pull request #7537 from hashicorp/import-aws-dboption

provider/aws: Support Import of `aws_db_option_group`
This commit is contained in:
James Nugent 2016-07-08 10:59:00 +01:00 committed by GitHub
commit a89fd9d0de
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)