From 1030cc134441b172aa751fea9cd6d3d0ee17bf2f Mon Sep 17 00:00:00 2001 From: Anshul Sharma Date: Tue, 8 Nov 2016 17:36:29 +0530 Subject: [PATCH 1/2] Added AWS Redshift Enhanced VPC Routing --- .../aws/resource_aws_redshift_cluster.go | 14 +++++++ .../aws/resource_aws_redshift_cluster_test.go | 39 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/builtin/providers/aws/resource_aws_redshift_cluster.go b/builtin/providers/aws/resource_aws_redshift_cluster.go index 587b38e5f..f49f3f885 100644 --- a/builtin/providers/aws/resource_aws_redshift_cluster.go +++ b/builtin/providers/aws/resource_aws_redshift_cluster.go @@ -159,6 +159,12 @@ func resourceAwsRedshiftCluster() *schema.Resource { Computed: true, }, + "enhanced_vpc_routing": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "kms_key_id": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -302,6 +308,10 @@ func resourceAwsRedshiftClusterCreate(d *schema.ResourceData, meta interface{}) restoreOpts.ElasticIp = aws.String(v.(string)) } + if v, ok := d.GetOk("enhanced_vpc_routing"); ok { + restoreOpts.EnhancedVpcRouting = aws.Bool(v.(bool)) + } + if v, ok := d.GetOk("iam_roles"); ok { restoreOpts.IamRoles = expandStringList(v.(*schema.Set).List()) } @@ -366,6 +376,10 @@ func resourceAwsRedshiftClusterCreate(d *schema.ResourceData, meta interface{}) createOpts.Encrypted = aws.Bool(v.(bool)) } + if v, ok := d.GetOk("enhanced_vpc_routing"); ok { + createOpts.EnhancedVpcRouting = aws.Bool(v.(bool)) + } + if v, ok := d.GetOk("kms_key_id"); ok { createOpts.KmsKeyId = aws.String(v.(string)) } diff --git a/builtin/providers/aws/resource_aws_redshift_cluster_test.go b/builtin/providers/aws/resource_aws_redshift_cluster_test.go index 5cdbb5749..7ad30eea8 100644 --- a/builtin/providers/aws/resource_aws_redshift_cluster_test.go +++ b/builtin/providers/aws/resource_aws_redshift_cluster_test.go @@ -38,6 +38,31 @@ func TestAccAWSRedshiftCluster_basic(t *testing.T) { }) } +func TestAccAWSRedshiftCluster_enhancedVpcRoutingEnabled(t *testing.T) { + var v redshift.Cluster + + ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int() + config := fmt.Sprintf(testAccAWSRedshiftClusterConfig_enhancedVpcRoutingEnabled, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSRedshiftClusterDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v), + resource.TestCheckResourceAttr( + "aws_redshift_cluster.default", "cluster_type", "single-node"), + resource.TestCheckResourceAttr( + "aws_redshift_cluster.default", "enhanced_vpc_routing", "true"), + ), + }, + }, + }) +} + func TestAccAWSRedshiftCluster_loggingEnabled(t *testing.T) { var v redshift.Cluster @@ -470,6 +495,20 @@ resource "aws_redshift_cluster" "default" { allow_version_upgrade = false }` +var testAccAWSRedshiftClusterConfig_enhancedVpcRoutingEnabled = ` +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 = "dc1.large" + automated_snapshot_retention_period = 0 + allow_version_upgrade = false + enhanced_vpc_routing = true +} +` + var testAccAWSRedshiftClusterConfig_loggingDisabled = ` resource "aws_redshift_cluster" "default" { cluster_identifier = "tf-redshift-cluster-%d" From e9821eaced95387060e3b7b8e7409d2a2d6f3df1 Mon Sep 17 00:00:00 2001 From: Anshul Sharma Date: Tue, 8 Nov 2016 18:13:10 +0530 Subject: [PATCH 2/2] Updated Redshift Documentation and Added Test Cases for Redshift Enchaned VPC routing --- .../aws/resource_aws_redshift_cluster.go | 6 ++++ .../aws/resource_aws_redshift_cluster_test.go | 29 ++++++++++++++++--- .../aws/r/redshift_cluster.html.markdown | 1 + 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_redshift_cluster.go b/builtin/providers/aws/resource_aws_redshift_cluster.go index f49f3f885..a1603d957 100644 --- a/builtin/providers/aws/resource_aws_redshift_cluster.go +++ b/builtin/providers/aws/resource_aws_redshift_cluster.go @@ -481,6 +481,7 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er d.Set("cluster_subnet_group_name", rsc.ClusterSubnetGroupName) d.Set("availability_zone", rsc.AvailabilityZone) d.Set("encrypted", rsc.Encrypted) + d.Set("enhanced_vpc_routing", rsc.EnhancedVpcRouting) d.Set("kms_key_id", rsc.KmsKeyId) d.Set("automated_snapshot_retention_period", rsc.AutomatedSnapshotRetentionPeriod) d.Set("preferred_maintenance_window", rsc.PreferredMaintenanceWindow) @@ -624,6 +625,11 @@ func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{}) requestUpdate = true } + if d.HasChange("enhanced_vpc_routing") { + req.EnhancedVpcRouting = aws.Bool(d.Get("enhanced_vpc_routing").(bool)) + requestUpdate = true + } + if requestUpdate { log.Printf("[INFO] Modifying Redshift Cluster: %s", d.Id()) log.Printf("[DEBUG] Redshift Cluster Modify options: %s", req) diff --git a/builtin/providers/aws/resource_aws_redshift_cluster_test.go b/builtin/providers/aws/resource_aws_redshift_cluster_test.go index 7ad30eea8..9ef6ffcb1 100644 --- a/builtin/providers/aws/resource_aws_redshift_cluster_test.go +++ b/builtin/providers/aws/resource_aws_redshift_cluster_test.go @@ -42,7 +42,8 @@ func TestAccAWSRedshiftCluster_enhancedVpcRoutingEnabled(t *testing.T) { var v redshift.Cluster ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int() - config := fmt.Sprintf(testAccAWSRedshiftClusterConfig_enhancedVpcRoutingEnabled, ri) + preConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_enhancedVpcRoutingEnabled, ri) + postConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_enhancedVpcRoutingDisabled, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -50,15 +51,21 @@ func TestAccAWSRedshiftCluster_enhancedVpcRoutingEnabled(t *testing.T) { CheckDestroy: testAccCheckAWSRedshiftClusterDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: config, + Config: preConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v), - resource.TestCheckResourceAttr( - "aws_redshift_cluster.default", "cluster_type", "single-node"), resource.TestCheckResourceAttr( "aws_redshift_cluster.default", "enhanced_vpc_routing", "true"), ), }, + resource.TestStep{ + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v), + resource.TestCheckResourceAttr( + "aws_redshift_cluster.default", "enhanced_vpc_routing", "false"), + ), + }, }, }) } @@ -509,6 +516,20 @@ resource "aws_redshift_cluster" "default" { } ` +var testAccAWSRedshiftClusterConfig_enhancedVpcRoutingDisabled = ` +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 = "dc1.large" + automated_snapshot_retention_period = 0 + allow_version_upgrade = false + enhanced_vpc_routing = false +} +` + var testAccAWSRedshiftClusterConfig_loggingDisabled = ` resource "aws_redshift_cluster" "default" { cluster_identifier = "tf-redshift-cluster-%d" diff --git a/website/source/docs/providers/aws/r/redshift_cluster.html.markdown b/website/source/docs/providers/aws/r/redshift_cluster.html.markdown index 0af15a54a..33504d929 100644 --- a/website/source/docs/providers/aws/r/redshift_cluster.html.markdown +++ b/website/source/docs/providers/aws/r/redshift_cluster.html.markdown @@ -54,6 +54,7 @@ string. * `number_of_nodes` - (Optional) The number of compute nodes in the cluster. This parameter is required when the ClusterType parameter is specified as multi-node. Default is 1. * `publicly_accessible` - (Optional) If true, the cluster can be accessed from a public network. Default is `true`. * `encrypted` - (Optional) If true , the data in the cluster is encrypted at rest. +* `enhanced_vpc_routing` - (Optional) If true , enhanced VPC routing is enabled. * `kms_key_id` - (Optional) The ARN for the KMS encryption key. When specifying `kms_key_id`, `encrypted` needs to be set to true * `elastic_ip` - (Optional) The Elastic IP (EIP) address for the cluster. * `skip_final_snapshot` - (Optional) Determines whether a final snapshot of the cluster is created before Amazon Redshift deletes the cluster. If true , a final cluster snapshot is not created. If false , a final cluster snapshot is created before the cluster is deleted. Default is true.