From a746b28fc1afb0b292ac83824f9a443a59a60ced Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 7 Jul 2016 18:27:13 +0100 Subject: [PATCH] provider/aws: Support Import of `aws_redshift_cluster` ``` make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSRedshiftCluster_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=TestAccAWSRedshiftCluster_importBasic -timeout 120m === RUN TestAccAWSRedshiftCluster_importBasic --- PASS: TestAccAWSRedshiftCluster_importBasic (623.52s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 623.546s ``` --- .../aws/import_aws_redshift_cluster_test.go | 32 +++++++++++++++++++ .../aws/resource_aws_redshift_cluster.go | 21 ++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 builtin/providers/aws/import_aws_redshift_cluster_test.go diff --git a/builtin/providers/aws/import_aws_redshift_cluster_test.go b/builtin/providers/aws/import_aws_redshift_cluster_test.go new file mode 100644 index 000000000..b6cea1896 --- /dev/null +++ b/builtin/providers/aws/import_aws_redshift_cluster_test.go @@ -0,0 +1,32 @@ +package aws + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSRedshiftCluster_importBasic(t *testing.T) { + resourceName := "aws_redshift_cluster.default" + config := fmt.Sprintf(testAccAWSRedshiftClusterConfig_basic, acctest.RandInt()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSRedshiftClusterDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"master_password", "skip_final_snapshot"}, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_redshift_cluster.go b/builtin/providers/aws/resource_aws_redshift_cluster.go index 7f056aa00..7f03eb5b9 100644 --- a/builtin/providers/aws/resource_aws_redshift_cluster.go +++ b/builtin/providers/aws/resource_aws_redshift_cluster.go @@ -20,6 +20,9 @@ func resourceAwsRedshiftCluster() *schema.Resource { Read: resourceAwsRedshiftClusterRead, Update: resourceAwsRedshiftClusterUpdate, Delete: resourceAwsRedshiftClusterDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "database_name": &schema.Schema{ @@ -334,7 +337,13 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er return nil } + d.Set("master_username", rsc.MasterUsername) + d.Set("node_type", rsc.NodeType) + d.Set("allow_version_upgrade", rsc.AllowVersionUpgrade) d.Set("database_name", rsc.DBName) + d.Set("cluster_identifier", rsc.ClusterIdentifier) + d.Set("cluster_version", rsc.ClusterVersion) + d.Set("cluster_subnet_group_name", rsc.ClusterSubnetGroupName) d.Set("availability_zone", rsc.AvailabilityZone) d.Set("encrypted", rsc.Encrypted) @@ -346,6 +355,7 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er if rsc.Endpoint.Port != nil { endpoint = fmt.Sprintf("%s:%d", endpoint, *rsc.Endpoint.Port) } + d.Set("port", rsc.Endpoint.Port) d.Set("endpoint", endpoint) } d.Set("cluster_parameter_group_name", rsc.ClusterParameterGroups[0].ParameterGroupName) @@ -354,6 +364,8 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er } else { d.Set("cluster_type", "single-node") } + d.Set("number_of_nodes", len(rsc.ClusterNodes)) + d.Set("publicly_accessible", rsc.PubliclyAccessible) var vpcg []string for _, g := range rsc.VpcSecurityGroups { @@ -545,10 +557,13 @@ func resourceAwsRedshiftClusterDelete(d *schema.ResourceData, meta interface{}) ClusterIdentifier: aws.String(d.Id()), } - skipFinalSnapshot := d.Get("skip_final_snapshot").(bool) - deleteOpts.SkipFinalClusterSnapshot = aws.Bool(skipFinalSnapshot) + skipFinalSnapshot, exists := d.GetOk("skip_final_snapshot") + if !exists { + skipFinalSnapshot = true + } + deleteOpts.SkipFinalClusterSnapshot = aws.Bool(skipFinalSnapshot.(bool)) - if !skipFinalSnapshot { + if skipFinalSnapshot == false { if name, present := d.GetOk("final_snapshot_identifier"); present { deleteOpts.FinalClusterSnapshotIdentifier = aws.String(name.(string)) } else {