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
```
This commit is contained in:
stack72 2016-07-07 18:27:13 +01:00
parent 21e2173e0a
commit a746b28fc1
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
2 changed files with 50 additions and 3 deletions

View File

@ -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"},
},
},
})
}

View File

@ -20,6 +20,9 @@ func resourceAwsRedshiftCluster() *schema.Resource {
Read: resourceAwsRedshiftClusterRead, Read: resourceAwsRedshiftClusterRead,
Update: resourceAwsRedshiftClusterUpdate, Update: resourceAwsRedshiftClusterUpdate,
Delete: resourceAwsRedshiftClusterDelete, Delete: resourceAwsRedshiftClusterDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"database_name": &schema.Schema{ "database_name": &schema.Schema{
@ -334,7 +337,13 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er
return nil 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("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("cluster_subnet_group_name", rsc.ClusterSubnetGroupName)
d.Set("availability_zone", rsc.AvailabilityZone) d.Set("availability_zone", rsc.AvailabilityZone)
d.Set("encrypted", rsc.Encrypted) d.Set("encrypted", rsc.Encrypted)
@ -346,6 +355,7 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er
if rsc.Endpoint.Port != nil { if rsc.Endpoint.Port != nil {
endpoint = fmt.Sprintf("%s:%d", endpoint, *rsc.Endpoint.Port) endpoint = fmt.Sprintf("%s:%d", endpoint, *rsc.Endpoint.Port)
} }
d.Set("port", rsc.Endpoint.Port)
d.Set("endpoint", endpoint) d.Set("endpoint", endpoint)
} }
d.Set("cluster_parameter_group_name", rsc.ClusterParameterGroups[0].ParameterGroupName) d.Set("cluster_parameter_group_name", rsc.ClusterParameterGroups[0].ParameterGroupName)
@ -354,6 +364,8 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er
} else { } else {
d.Set("cluster_type", "single-node") d.Set("cluster_type", "single-node")
} }
d.Set("number_of_nodes", len(rsc.ClusterNodes))
d.Set("publicly_accessible", rsc.PubliclyAccessible)
var vpcg []string var vpcg []string
for _, g := range rsc.VpcSecurityGroups { for _, g := range rsc.VpcSecurityGroups {
@ -545,10 +557,13 @@ func resourceAwsRedshiftClusterDelete(d *schema.ResourceData, meta interface{})
ClusterIdentifier: aws.String(d.Id()), ClusterIdentifier: aws.String(d.Id()),
} }
skipFinalSnapshot := d.Get("skip_final_snapshot").(bool) skipFinalSnapshot, exists := d.GetOk("skip_final_snapshot")
deleteOpts.SkipFinalClusterSnapshot = aws.Bool(skipFinalSnapshot) if !exists {
skipFinalSnapshot = true
}
deleteOpts.SkipFinalClusterSnapshot = 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 {
deleteOpts.FinalClusterSnapshotIdentifier = aws.String(name.(string)) deleteOpts.FinalClusterSnapshotIdentifier = aws.String(name.(string))
} else { } else {