From 3592346ba0ed0e239871849f9f3c4804f1df8f9f Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Fri, 18 May 2018 00:43:42 +0400 Subject: [PATCH 1/6] issue #4566 add new attribute dns_name in aws_redshift_cluster --- aws/resource_aws_redshift_cluster.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aws/resource_aws_redshift_cluster.go b/aws/resource_aws_redshift_cluster.go index 1a28ca15a10..cec15b8b381 100644 --- a/aws/resource_aws_redshift_cluster.go +++ b/aws/resource_aws_redshift_cluster.go @@ -193,6 +193,12 @@ func resourceAwsRedshiftCluster() *schema.Resource { Computed: true, }, + "dns_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "cluster_public_key": { Type: schema.TypeString, Optional: true, @@ -567,6 +573,7 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er if rsc.Endpoint.Port != nil { endpoint = fmt.Sprintf("%s:%d", endpoint, *rsc.Endpoint.Port) } + d.Set("dns_name", rsc.Endpoint.Address) d.Set("port", rsc.Endpoint.Port) d.Set("endpoint", endpoint) } From 5d988fa6b578cf6b1fcb18024bcd385d48d7fb76 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Fri, 18 May 2018 11:17:48 +0400 Subject: [PATCH 2/6] issue #4566 add acceptance tests --- aws/resource_aws_redshift_cluster_test.go | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/aws/resource_aws_redshift_cluster_test.go b/aws/resource_aws_redshift_cluster_test.go index f7db0b5c4d1..99b86693ecf 100644 --- a/aws/resource_aws_redshift_cluster_test.go +++ b/aws/resource_aws_redshift_cluster_test.go @@ -126,6 +126,32 @@ func TestAccAWSRedshiftCluster_basic(t *testing.T) { }) } +func TestAccAWSRedshiftCluster_dnsName(t *testing.T) { + var v redshift.Cluster + + ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int() + config := testAccAWSRedshiftClusterConfig_basic(ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSRedshiftClusterDestroy, + Steps: []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", "publicly_accessible", "true"), + testAccCheckAWSRedshiftClusterDNSName(&v, ri), + ), + }, + }, + }) +} + func TestAccAWSRedshiftCluster_withFinalSnapshot(t *testing.T) { var v redshift.Cluster @@ -630,6 +656,23 @@ func testAccCheckAWSRedshiftClusterMasterUsername(c *redshift.Cluster, value str } } +func testAccCheckAWSRedshiftClusterDNSName(c *redshift.Cluster, rInt int) resource.TestCheckFunc { + return func(s *terraform.State) error { + if c.Endpoint == nil { + return fmt.Errorf("Expected cluster Endpoint to be set, got nil") + } + + //validate the cluster address + str := fmt.Sprintf("tf-redshift-cluster-%d.?[a-zA-Z0-9].*?.us-west-2.redshift.amazonaws.com", rInt) + re := regexp.MustCompile(str) + if !re.MatchString(*c.Endpoint.Address) { + return fmt.Errorf("Expected cluster DNS name, got %s", *c.Endpoint.Address) + } + + return nil + } +} + func TestResourceAWSRedshiftClusterIdentifierValidation(t *testing.T) { cases := []struct { Value string From 304aaa230464d1be94c6ef379e7815cb443b3945 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Fri, 18 May 2018 11:21:24 +0400 Subject: [PATCH 3/6] issue #4566 update document --- website/docs/r/redshift_cluster.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/redshift_cluster.html.markdown b/website/docs/r/redshift_cluster.html.markdown index 71c9da2879c..026c1675fde 100644 --- a/website/docs/r/redshift_cluster.html.markdown +++ b/website/docs/r/redshift_cluster.html.markdown @@ -104,6 +104,7 @@ The following attributes are exported: * `encrypted` - Whether the data in the cluster is encrypted * `cluster_security_groups` - The security groups associated with the cluster * `vpc_security_group_ids` - The VPC security group Ids associated with the cluster +* `dns_name` - The DNS name of the cluster * `port` - The Port the cluster responds on * `cluster_version` - The version of Redshift engine software * `cluster_parameter_group_name` - The name of the parameter group to be associated with this cluster From 0de7d9f290d9c244df4b69d6d16eb7a7930d5ad4 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Wed, 23 May 2018 23:09:26 +0400 Subject: [PATCH 4/6] issue #4566 update corrections --- aws/resource_aws_redshift_cluster.go | 1 - aws/resource_aws_redshift_cluster_test.go | 46 +---------------------- 2 files changed, 2 insertions(+), 45 deletions(-) diff --git a/aws/resource_aws_redshift_cluster.go b/aws/resource_aws_redshift_cluster.go index cec15b8b381..6cde16cef90 100644 --- a/aws/resource_aws_redshift_cluster.go +++ b/aws/resource_aws_redshift_cluster.go @@ -195,7 +195,6 @@ func resourceAwsRedshiftCluster() *schema.Resource { "dns_name": { Type: schema.TypeString, - Optional: true, Computed: true, }, diff --git a/aws/resource_aws_redshift_cluster_test.go b/aws/resource_aws_redshift_cluster_test.go index 99b86693ecf..b97562633b7 100644 --- a/aws/resource_aws_redshift_cluster_test.go +++ b/aws/resource_aws_redshift_cluster_test.go @@ -104,32 +104,7 @@ func TestValidateRedshiftClusterDbName(t *testing.T) { func TestAccAWSRedshiftCluster_basic(t *testing.T) { var v redshift.Cluster - ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int() - config := testAccAWSRedshiftClusterConfig_basic(ri) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSRedshiftClusterDestroy, - Steps: []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", "publicly_accessible", "true"), - ), - }, - }, - }) -} - -func TestAccAWSRedshiftCluster_dnsName(t *testing.T) { - var v redshift.Cluster - - ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int() + ri := acctest.RandInt() config := testAccAWSRedshiftClusterConfig_basic(ri) resource.Test(t, resource.TestCase{ @@ -145,7 +120,7 @@ func TestAccAWSRedshiftCluster_dnsName(t *testing.T) { "aws_redshift_cluster.default", "cluster_type", "single-node"), resource.TestCheckResourceAttr( "aws_redshift_cluster.default", "publicly_accessible", "true"), - testAccCheckAWSRedshiftClusterDNSName(&v, ri), + resource.TestMatchResourceAttr("aws_redshift_cluster.default", "address", regexp.MustCompile(fmt.Sprintf("^tf-redshift-cluster-%d.*\\.redshift\\..*", ri))), ), }, }, @@ -656,23 +631,6 @@ func testAccCheckAWSRedshiftClusterMasterUsername(c *redshift.Cluster, value str } } -func testAccCheckAWSRedshiftClusterDNSName(c *redshift.Cluster, rInt int) resource.TestCheckFunc { - return func(s *terraform.State) error { - if c.Endpoint == nil { - return fmt.Errorf("Expected cluster Endpoint to be set, got nil") - } - - //validate the cluster address - str := fmt.Sprintf("tf-redshift-cluster-%d.?[a-zA-Z0-9].*?.us-west-2.redshift.amazonaws.com", rInt) - re := regexp.MustCompile(str) - if !re.MatchString(*c.Endpoint.Address) { - return fmt.Errorf("Expected cluster DNS name, got %s", *c.Endpoint.Address) - } - - return nil - } -} - func TestResourceAWSRedshiftClusterIdentifierValidation(t *testing.T) { cases := []struct { Value string From 1898b3209eeec5272a79b29356ac8499dd59c388 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Wed, 23 May 2018 23:18:34 +0400 Subject: [PATCH 5/6] issue #4566 revert a change to avoid conflicts --- aws/resource_aws_redshift_cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_redshift_cluster_test.go b/aws/resource_aws_redshift_cluster_test.go index b97562633b7..c9abea6f983 100644 --- a/aws/resource_aws_redshift_cluster_test.go +++ b/aws/resource_aws_redshift_cluster_test.go @@ -104,7 +104,7 @@ func TestValidateRedshiftClusterDbName(t *testing.T) { func TestAccAWSRedshiftCluster_basic(t *testing.T) { var v redshift.Cluster - ri := acctest.RandInt() + ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int() config := testAccAWSRedshiftClusterConfig_basic(ri) resource.Test(t, resource.TestCase{ From 1b6476361f550ccaf85fb84f4e5acbc65ff77e20 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Thu, 24 May 2018 00:04:21 +0400 Subject: [PATCH 6/6] issue #4566 fix the issue in acceptance test --- aws/resource_aws_redshift_cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_redshift_cluster_test.go b/aws/resource_aws_redshift_cluster_test.go index c9abea6f983..fea151fa276 100644 --- a/aws/resource_aws_redshift_cluster_test.go +++ b/aws/resource_aws_redshift_cluster_test.go @@ -120,7 +120,7 @@ func TestAccAWSRedshiftCluster_basic(t *testing.T) { "aws_redshift_cluster.default", "cluster_type", "single-node"), resource.TestCheckResourceAttr( "aws_redshift_cluster.default", "publicly_accessible", "true"), - resource.TestMatchResourceAttr("aws_redshift_cluster.default", "address", regexp.MustCompile(fmt.Sprintf("^tf-redshift-cluster-%d.*\\.redshift\\..*", ri))), + resource.TestMatchResourceAttr("aws_redshift_cluster.default", "dns_name", regexp.MustCompile(fmt.Sprintf("^tf-redshift-cluster-%d.*\\.redshift\\..*", ri))), ), }, },