provider/aws: Change Redshift Cluster cluster_type to be computed

It will be based off the number of nodes. Can only be multi-node (>1
node) or single-node (nodes=1)
This commit is contained in:
stack72 2016-02-21 19:42:02 +00:00
parent 938ab99d51
commit e6e18a4a9e
3 changed files with 21 additions and 8 deletions

View File

@ -37,7 +37,8 @@ func resourceAwsRedshiftCluster() *schema.Resource {
}, },
"cluster_type": &schema.Schema{ "cluster_type": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Optional: true,
Computed: true,
}, },
"node_type": &schema.Schema{ "node_type": &schema.Schema{
@ -200,15 +201,19 @@ func resourceAwsRedshiftClusterCreate(d *schema.ResourceData, meta interface{})
Port: aws.Int64(int64(d.Get("port").(int))), Port: aws.Int64(int64(d.Get("port").(int))),
MasterUserPassword: aws.String(d.Get("master_password").(string)), MasterUserPassword: aws.String(d.Get("master_password").(string)),
MasterUsername: aws.String(d.Get("master_username").(string)), MasterUsername: aws.String(d.Get("master_username").(string)),
ClusterType: aws.String(d.Get("cluster_type").(string)),
ClusterVersion: aws.String(d.Get("cluster_version").(string)), ClusterVersion: aws.String(d.Get("cluster_version").(string)),
NodeType: aws.String(d.Get("node_type").(string)), NodeType: aws.String(d.Get("node_type").(string)),
DBName: aws.String(d.Get("database_name").(string)), DBName: aws.String(d.Get("database_name").(string)),
AllowVersionUpgrade: aws.Bool(d.Get("allow_version_upgrade").(bool)), AllowVersionUpgrade: aws.Bool(d.Get("allow_version_upgrade").(bool)),
} }
if d.Get("cluster_type") == "multi-node" {
if v := d.Get("number_of_nodes").(int); v > 1 {
createOpts.ClusterType = aws.String("multi-node")
createOpts.NumberOfNodes = aws.Int64(int64(d.Get("number_of_nodes").(int))) createOpts.NumberOfNodes = aws.Int64(int64(d.Get("number_of_nodes").(int)))
} else {
createOpts.ClusterType = aws.String("single-node")
} }
if v := d.Get("cluster_security_groups").(*schema.Set); v.Len() > 0 { if v := d.Get("cluster_security_groups").(*schema.Set); v.Len() > 0 {
createOpts.ClusterSecurityGroups = expandStringList(v.List()) createOpts.ClusterSecurityGroups = expandStringList(v.List())
} }
@ -316,6 +321,11 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er
d.Set("preferred_maintenance_window", rsc.PreferredMaintenanceWindow) d.Set("preferred_maintenance_window", rsc.PreferredMaintenanceWindow)
d.Set("endpoint", aws.String(fmt.Sprintf("%s:%d", *rsc.Endpoint.Address, *rsc.Endpoint.Port))) d.Set("endpoint", aws.String(fmt.Sprintf("%s:%d", *rsc.Endpoint.Address, *rsc.Endpoint.Port)))
d.Set("cluster_parameter_group_name", rsc.ClusterParameterGroups[0].ParameterGroupName) d.Set("cluster_parameter_group_name", rsc.ClusterParameterGroups[0].ParameterGroupName)
if len(rsc.ClusterNodes) > 1 {
d.Set("cluster_type", "multi-node")
} else {
d.Set("cluster_type", "single-node")
}
var vpcg []string var vpcg []string
for _, g := range rsc.VpcSecurityGroups { for _, g := range rsc.VpcSecurityGroups {
@ -356,9 +366,12 @@ func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{})
} }
if d.HasChange("number_of_nodes") { if d.HasChange("number_of_nodes") {
log.Printf("[INFO] When changing the NumberOfNodes in a Redshift Cluster, NodeType is required") if v := d.Get("number_of_nodes").(int); v > 1 {
req.ClusterType = aws.String("multi-node")
req.NumberOfNodes = aws.Int64(int64(d.Get("number_of_nodes").(int))) req.NumberOfNodes = aws.Int64(int64(d.Get("number_of_nodes").(int)))
req.NodeType = aws.String(d.Get("node_type").(string)) } else {
req.ClusterType = aws.String("single-node")
}
} }
if d.HasChange("cluster_security_groups") { if d.HasChange("cluster_security_groups") {

View File

@ -28,6 +28,8 @@ func TestAccAWSRedshiftCluster_basic(t *testing.T) {
Config: config, Config: config,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v), testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "cluster_type", "single-node"),
), ),
}, },
}, },
@ -243,7 +245,6 @@ resource "aws_redshift_cluster" "default" {
master_username = "foo" master_username = "foo"
master_password = "Mustbe8characters" master_password = "Mustbe8characters"
node_type = "dc1.large" node_type = "dc1.large"
cluster_type = "single-node"
automated_snapshot_retention_period = 7 automated_snapshot_retention_period = 7
allow_version_upgrade = false allow_version_upgrade = false
}` }`

View File

@ -32,7 +32,6 @@ The following arguments are supported:
string. string.
* `database_name` - (Optional) The name of the first database to be created when the cluster is created. * `database_name` - (Optional) The name of the first database to be created when the cluster is created.
If you do not provide a name, Amazon Redshift will create a default database called `dev`. If you do not provide a name, Amazon Redshift will create a default database called `dev`.
* `cluster_type` - (Required) The type of the cluster. Valid values are `multi-node` and `single-node`
* `node_type` - (Required) The node type to be provisioned for the cluster. * `node_type` - (Required) The node type to be provisioned for the cluster.
* `master_password` - (Required) Password for the master DB user. Note that this may * `master_password` - (Required) Password for the master DB user. Note that this may
show up in logs, and it will be stored in the state file show up in logs, and it will be stored in the state file