Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Change Redshift Cluster cluster_type to be computed #5238

Merged
merged 1 commit into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions builtin/providers/aws/resource_aws_redshift_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func resourceAwsRedshiftCluster() *schema.Resource {
},
"cluster_type": &schema.Schema{
Type: schema.TypeString,
Required: true,
Optional: true,
Computed: true,
},

"node_type": &schema.Schema{
Expand Down Expand Up @@ -200,15 +201,19 @@ func resourceAwsRedshiftClusterCreate(d *schema.ResourceData, meta interface{})
Port: aws.Int64(int64(d.Get("port").(int))),
MasterUserPassword: aws.String(d.Get("master_password").(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)),
NodeType: aws.String(d.Get("node_type").(string)),
DBName: aws.String(d.Get("database_name").(string)),
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)))
} else {
createOpts.ClusterType = aws.String("single-node")
}

if v := d.Get("cluster_security_groups").(*schema.Set); v.Len() > 0 {
createOpts.ClusterSecurityGroups = expandStringList(v.List())
}
Expand Down Expand Up @@ -316,6 +321,11 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er
d.Set("preferred_maintenance_window", rsc.PreferredMaintenanceWindow)
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)
if len(rsc.ClusterNodes) > 1 {
d.Set("cluster_type", "multi-node")
} else {
d.Set("cluster_type", "single-node")
}

var vpcg []string
for _, g := range rsc.VpcSecurityGroups {
Expand Down Expand Up @@ -356,9 +366,12 @@ func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{})
}

if d.HasChange("number_of_nodes") {
log.Printf("[INFO] When changing the NumberOfNodes in a Redshift Cluster, NodeType is required")
req.NumberOfNodes = aws.Int64(int64(d.Get("number_of_nodes").(int)))
req.NodeType = aws.String(d.Get("node_type").(string))
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)))
} else {
req.ClusterType = aws.String("single-node")
}
}

if d.HasChange("cluster_security_groups") {
Expand Down
3 changes: 2 additions & 1 deletion builtin/providers/aws/resource_aws_redshift_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func TestAccAWSRedshiftCluster_basic(t *testing.T) {
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "cluster_type", "single-node"),
),
},
},
Expand Down Expand Up @@ -243,7 +245,6 @@ resource "aws_redshift_cluster" "default" {
master_username = "foo"
master_password = "Mustbe8characters"
node_type = "dc1.large"
cluster_type = "single-node"
automated_snapshot_retention_period = 7
allow_version_upgrade = false
}`
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ The following arguments are supported:
string.
* `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`.
* `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.
* `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
Expand Down