From b4fa54e3c0590780851e6f73ef658432b1daddbf Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Wed, 20 Jul 2016 19:53:37 +0100 Subject: [PATCH] provider/aws: Support Import `aws_rds_cluster` (#7366) ``` make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSRDSCluster_importBasic' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /vendor/) TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSRDSCluster_importBasic -timeout 120m === RUN TestAccAWSRDSCluster_importBasic --- FAIL: TestAccAWSRDSCluster_importBasic (122.71s) testing.go:255: Step 1 error: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected. (map[string]string) { } (map[string]string) (len=1) { (string) (len=19) "skip_final_snapshot": (string) (len=4) "true" } FAIL exit status 1 FAIL github.com/hashicorp/terraform/builtin/providers/aws 122.733s make: *** [testacc] Error 1 ``` --- ....go => import_aws_db_subnet_group_test.go} | 0 .../aws/import_aws_rds_cluster_test.go | 32 +++++++++++++++++++ .../providers/aws/resource_aws_rds_cluster.go | 13 ++++++++ 3 files changed, 45 insertions(+) rename builtin/providers/aws/{import_aws_db_subnet_group_group_test.go => import_aws_db_subnet_group_test.go} (100%) create mode 100644 builtin/providers/aws/import_aws_rds_cluster_test.go diff --git a/builtin/providers/aws/import_aws_db_subnet_group_group_test.go b/builtin/providers/aws/import_aws_db_subnet_group_test.go similarity index 100% rename from builtin/providers/aws/import_aws_db_subnet_group_group_test.go rename to builtin/providers/aws/import_aws_db_subnet_group_test.go diff --git a/builtin/providers/aws/import_aws_rds_cluster_test.go b/builtin/providers/aws/import_aws_rds_cluster_test.go new file mode 100644 index 000000000..be7e8bea3 --- /dev/null +++ b/builtin/providers/aws/import_aws_rds_cluster_test.go @@ -0,0 +1,32 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSRDSCluster_importBasic(t *testing.T) { + resourceName := "aws_rds_cluster.default" + ri := acctest.RandInt() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSClusterDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSClusterConfig(ri), + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "master_password", "skip_final_snapshot"}, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_rds_cluster.go b/builtin/providers/aws/resource_aws_rds_cluster.go index 6cb76a7bb..60981c1ae 100644 --- a/builtin/providers/aws/resource_aws_rds_cluster.go +++ b/builtin/providers/aws/resource_aws_rds_cluster.go @@ -20,6 +20,9 @@ func resourceAwsRDSCluster() *schema.Resource { Read: resourceAwsRDSClusterRead, Update: resourceAwsRDSClusterUpdate, Delete: resourceAwsRDSClusterDelete, + Importer: &schema.ResourceImporter{ + State: resourceAwsRdsClusterImport, + }, Schema: map[string]*schema.Schema{ @@ -198,6 +201,15 @@ func resourceAwsRDSCluster() *schema.Resource { } } +func resourceAwsRdsClusterImport( + 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 resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).rdsconn tags := tagsFromMapRDS(d.Get("tags").(map[string]interface{})) @@ -407,6 +419,7 @@ func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error { d.Set("database_name", dbc.DatabaseName) } + d.Set("cluster_identifier", dbc.DBClusterIdentifier) d.Set("db_subnet_group_name", dbc.DBSubnetGroup) d.Set("parameter_group_name", dbc.DBClusterParameterGroup) d.Set("db_cluster_parameter_group_name", dbc.DBClusterParameterGroup)