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

resource/aws_redshift_cluster: Send correct values when resizing #3127

Merged
merged 3 commits into from
May 7, 2018
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
14 changes: 3 additions & 11 deletions aws/resource_aws_redshift_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,25 +642,17 @@ func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{})
ClusterIdentifier: aws.String(d.Id()),
}

if d.HasChange("cluster_type") {
// If the cluster type, node type, or number of nodes changed, then the AWS API expects all three
// items to be sent over
if d.HasChange("cluster_type") || d.HasChange("node_type") || d.HasChange("number_of_nodes") {
req.ClusterType = aws.String(d.Get("cluster_type").(string))
requestUpdate = true
}

if d.HasChange("node_type") {
req.NodeType = aws.String(d.Get("node_type").(string))
requestUpdate = true
}

if d.HasChange("number_of_nodes") {
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")
}

req.NodeType = aws.String(d.Get("node_type").(string))
requestUpdate = true
}

Expand Down
58 changes: 58 additions & 0 deletions aws/resource_aws_redshift_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,47 @@ func TestAccAWSRedshiftCluster_updateNodeCount(t *testing.T) {
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "number_of_nodes", "2"),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "cluster_type", "multi-node"),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "node_type", "dc1.large"),
),
},
},
})
}

func TestAccAWSRedshiftCluster_updateNodeType(t *testing.T) {
var v redshift.Cluster

ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
preConfig := testAccAWSRedshiftClusterConfig_basic(ri)
postConfig := testAccAWSRedshiftClusterConfig_updateNodeType(ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "node_type", "dc1.large"),
),
},

{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "number_of_nodes", "1"),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "cluster_type", "single-node"),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "node_type", "dc2.large"),
),
},
},
Expand Down Expand Up @@ -738,6 +779,23 @@ resource "aws_redshift_cluster" "default" {
`, rInt)
}

func testAccAWSRedshiftClusterConfig_updateNodeType(rInt int) string {
return fmt.Sprintf(`
resource "aws_redshift_cluster" "default" {
cluster_identifier = "tf-redshift-cluster-%d"
availability_zone = "us-west-2a"
database_name = "mydb"
master_username = "foo_test"
master_password = "Mustbe8characters"
node_type = "dc2.large"
automated_snapshot_retention_period = 0
allow_version_upgrade = false
number_of_nodes = 1
skip_final_snapshot = true
}
`, rInt)
}

func testAccAWSRedshiftClusterConfig_basic(rInt int) string {
return fmt.Sprintf(`
resource "aws_redshift_cluster" "default" {
Expand Down