Merge pull request #7536 from hashicorp/import-aws-db_instance

provider/aws: Support Import of `aws_db_instance`
This commit is contained in:
James Nugent 2016-07-08 10:58:37 +01:00 committed by GitHub
commit dfe2ee5a30
2 changed files with 40 additions and 3 deletions

View File

@ -0,0 +1,30 @@
package aws
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSDBInstance_importBasic(t *testing.T) {
resourceName := "aws_db_instance.bar"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSDBInstanceConfig,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"password", "skip_final_snapshot"},
},
},
})
}

View File

@ -22,6 +22,9 @@ func resourceAwsDbInstance() *schema.Resource {
Read: resourceAwsDbInstanceRead,
Update: resourceAwsDbInstanceUpdate,
Delete: resourceAwsDbInstanceDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
@ -633,6 +636,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("name", v.DBName)
d.Set("identifier", v.DBInstanceIdentifier)
d.Set("username", v.MasterUsername)
d.Set("engine", v.Engine)
d.Set("engine_version", v.EngineVersion)
@ -753,10 +757,13 @@ func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error
opts := rds.DeleteDBInstanceInput{DBInstanceIdentifier: aws.String(d.Id())}
skipFinalSnapshot := d.Get("skip_final_snapshot").(bool)
opts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot)
skipFinalSnapshot, exists := d.GetOk("skip_final_snapshot")
if !exists {
skipFinalSnapshot = true
}
opts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot.(bool))
if !skipFinalSnapshot {
if skipFinalSnapshot == false {
if name, present := d.GetOk("final_snapshot_identifier"); present {
opts.FinalDBSnapshotIdentifier = aws.String(name.(string))
} else {