provider/aws: Support Import of `aws_db_instance`
JUst needed some rejigging of the skip_final_snapshot work as that isn't returned by the API and skipping it means the destroy fails due to missing final_snapshot_identifier ``` % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSDBInstance_' ✹ ✭ ==> Checking that code complies with gofmt requirements... /Users/stacko/Code/go/bin/stringer go generate $(go list ./... | grep -v /vendor/) 2016/07/07 15:28:31 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSDBInstance_ -timeout 120m === RUN TestAccAWSDBInstance_importBasic --- PASS: TestAccAWSDBInstance_importBasic (588.70s) === RUN TestAccAWSDBInstance_basic --- PASS: TestAccAWSDBInstance_basic (595.71s) === RUN TestAccAWSDBInstance_kmsKey --- PASS: TestAccAWSDBInstance_kmsKey (726.46s) === RUN TestAccAWSDBInstance_optionGroup --- PASS: TestAccAWSDBInstance_optionGroup (681.78s) === RUN TestAccAWSDBInstance_iops_update --- PASS: TestAccAWSDBInstance_iops_update (590.81s) ``` Please note that I cannot run the enhanced monitoring test in my environment as I have already got it attached to an IAM role. Running that test gives me this result: ``` ```
This commit is contained in:
parent
21e2173e0a
commit
80aeabec83
|
@ -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"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -22,6 +22,9 @@ func resourceAwsDbInstance() *schema.Resource {
|
||||||
Read: resourceAwsDbInstanceRead,
|
Read: resourceAwsDbInstanceRead,
|
||||||
Update: resourceAwsDbInstanceUpdate,
|
Update: resourceAwsDbInstanceUpdate,
|
||||||
Delete: resourceAwsDbInstanceDelete,
|
Delete: resourceAwsDbInstanceDelete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
|
@ -633,6 +636,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("name", v.DBName)
|
d.Set("name", v.DBName)
|
||||||
|
d.Set("identifier", v.DBInstanceIdentifier)
|
||||||
d.Set("username", v.MasterUsername)
|
d.Set("username", v.MasterUsername)
|
||||||
d.Set("engine", v.Engine)
|
d.Set("engine", v.Engine)
|
||||||
d.Set("engine_version", v.EngineVersion)
|
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())}
|
opts := rds.DeleteDBInstanceInput{DBInstanceIdentifier: aws.String(d.Id())}
|
||||||
|
|
||||||
skipFinalSnapshot := d.Get("skip_final_snapshot").(bool)
|
skipFinalSnapshot, exists := d.GetOk("skip_final_snapshot")
|
||||||
opts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot)
|
if !exists {
|
||||||
|
skipFinalSnapshot = true
|
||||||
|
}
|
||||||
|
opts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot.(bool))
|
||||||
|
|
||||||
if !skipFinalSnapshot {
|
if skipFinalSnapshot == false {
|
||||||
if name, present := d.GetOk("final_snapshot_identifier"); present {
|
if name, present := d.GetOk("final_snapshot_identifier"); present {
|
||||||
opts.FinalDBSnapshotIdentifier = aws.String(name.(string))
|
opts.FinalDBSnapshotIdentifier = aws.String(name.(string))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue