From 93832527b1bfd673c35c152d7206df7060704b44 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Fri, 15 Jul 2016 11:24:58 -0600 Subject: [PATCH 1/2] provider/aws: Fixup skip_final_snapshot import Neither skip_final_snapshot nor final_snapshot_identifier can be fetched from any API call, so we need to default skip_final_snapshot to true during import so that final_snapshot_identifier is not required --- .../aws/import_aws_db_instance_test.go | 5 ++++- .../providers/aws/resource_aws_db_instance.go | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/builtin/providers/aws/import_aws_db_instance_test.go b/builtin/providers/aws/import_aws_db_instance_test.go index 8079d117b..7af427fd8 100644 --- a/builtin/providers/aws/import_aws_db_instance_test.go +++ b/builtin/providers/aws/import_aws_db_instance_test.go @@ -23,7 +23,10 @@ func TestAccAWSDBInstance_importBasic(t *testing.T) { ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ - "password", "skip_final_snapshot"}, + "password", + "skip_final_snapshot", + "final_snapshot_identifier", + }, }, }, }) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 8dc6f115b..c7615161b 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -23,7 +23,7 @@ func resourceAwsDbInstance() *schema.Resource { Update: resourceAwsDbInstanceUpdate, Delete: resourceAwsDbInstanceDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + State: resourceAwsDbInstanceImport, }, Schema: map[string]*schema.Schema{ @@ -757,11 +757,8 @@ func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error opts := rds.DeleteDBInstanceInput{DBInstanceIdentifier: aws.String(d.Id())} - skipFinalSnapshot, exists := d.GetOk("skip_final_snapshot") - if !exists { - skipFinalSnapshot = true - } - opts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot.(bool)) + skipFinalSnapshot := d.Get("skip_final_snapshot").(bool) + opts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot) if skipFinalSnapshot == false { if name, present := d.GetOk("final_snapshot_identifier"); present { @@ -1023,6 +1020,15 @@ func resourceAwsDbInstanceRetrieve( return resp.DBInstances[0], nil } +func resourceAwsDbInstanceImport( + d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + // Neither skip_final_snapshot nor final_snapshot_identifier can be fetched + // from any API call, so we need to default skip_final_snapshot to true so + // that final_snapshot_identifier is not required + d.Set("skip_final_snapshot", true) + return []*schema.ResourceData{d}, nil +} + func resourceAwsDbInstanceStateRefreshFunc( d *schema.ResourceData, meta interface{}) resource.StateRefreshFunc { return func() (interface{}, string, error) { From 614806d59f0bca7131ff0706ce927e6cf9ba3421 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Fri, 15 Jul 2016 13:15:47 -0600 Subject: [PATCH 2/2] helper/resource: Fix import test harness, which was modifying state Maps are reference types, it turns out :D --- helper/resource/testing_import_state.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/helper/resource/testing_import_state.go b/helper/resource/testing_import_state.go index f16f17130..00ec87324 100644 --- a/helper/resource/testing_import_state.go +++ b/helper/resource/testing_import_state.go @@ -90,8 +90,14 @@ func testStepImportState( } // Compare their attributes - actual := r.Primary.Attributes - expected := oldR.Primary.Attributes + actual := make(map[string]string) + for k, v := range r.Primary.Attributes { + actual[k] = v + } + expected := make(map[string]string) + for k, v := range oldR.Primary.Attributes { + expected[k] = v + } // Remove fields we're ignoring for _, v := range step.ImportStateVerifyIgnore {