From 2d0b050347b5afe043dd7a5d32575d5cccd2dad0 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Thu, 6 Jun 2019 23:59:33 +0900 Subject: [PATCH 1/9] Add tags attribute support for redshift parameter group --- aws/resource_aws_redshift_parameter_group.go | 18 +++++ ...ource_aws_redshift_parameter_group_test.go | 74 +++++++++++++++++++ .../r/redshift_parameter_group.html.markdown | 1 + 3 files changed, 93 insertions(+) diff --git a/aws/resource_aws_redshift_parameter_group.go b/aws/resource_aws_redshift_parameter_group.go index ae7778f54b9..a054a19ad6a 100644 --- a/aws/resource_aws_redshift_parameter_group.go +++ b/aws/resource_aws_redshift_parameter_group.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/redshift" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" @@ -62,6 +63,8 @@ func resourceAwsRedshiftParameterGroup() *schema.Resource { }, Set: resourceAwsRedshiftParameterHash, }, + + "tags": tagsSchema(), }, } } @@ -73,6 +76,7 @@ func resourceAwsRedshiftParameterGroupCreate(d *schema.ResourceData, meta interf ParameterGroupName: aws.String(d.Get("name").(string)), ParameterGroupFamily: aws.String(d.Get("family").(string)), Description: aws.String(d.Get("description").(string)), + Tags: tagsFromMapRedshift(d.Get("tags").(map[string]interface{})), } log.Printf("[DEBUG] Create Redshift Parameter Group: %#v", createOpts) @@ -108,6 +112,7 @@ func resourceAwsRedshiftParameterGroupRead(d *schema.ResourceData, meta interfac d.Set("name", describeResp.ParameterGroups[0].ParameterGroupName) d.Set("family", describeResp.ParameterGroups[0].ParameterGroupFamily) d.Set("description", describeResp.ParameterGroups[0].Description) + d.Set("tags", tagsToMapRedshift(describeResp.ParameterGroups[0].Tags)) describeParametersOpts := redshift.DescribeClusterParametersInput{ ParameterGroupName: aws.String(d.Id()), @@ -161,6 +166,19 @@ func resourceAwsRedshiftParameterGroupUpdate(d *schema.ResourceData, meta interf d.SetPartial("parameter") } + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Service: "redshift", + Region: meta.(*AWSClient).region, + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("parametergroup:%s", d.Id()), + }.String() + if tagErr := setTagsRedshift(conn, d, arn); tagErr != nil { + return tagErr + } else { + d.SetPartial("tags") + } + d.Partial(false) return resourceAwsRedshiftParameterGroupRead(d, meta) } diff --git a/aws/resource_aws_redshift_parameter_group_test.go b/aws/resource_aws_redshift_parameter_group_test.go index b1f3983303d..86badc69991 100644 --- a/aws/resource_aws_redshift_parameter_group_test.go +++ b/aws/resource_aws_redshift_parameter_group_test.go @@ -96,6 +96,50 @@ func TestAccAWSRedshiftParameterGroup_withoutParameters(t *testing.T) { }) } +func TestAccAWSRedshiftParameterGroup_withTags(t *testing.T) { + var v redshift.ClusterParameterGroup + + rInt := acctest.RandInt() + resourceName := "aws_redshift_parameter_group.default" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSRedshiftParameterGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSRedshiftParameterGroupConfigWithTags(rInt, "aaa"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftParameterGroupExists(resourceName, &v), + resource.TestCheckResourceAttr( + resourceName, "tags.%", "3"), + resource.TestCheckResourceAttr(resourceName, "tags.name", fmt.Sprintf("test-terraform-%d", rInt)), + resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(resourceName, "tags.description", fmt.Sprintf("Test parameter group for terraform %s", "aaa")), + ), + }, + { + Config: testAccAWSRedshiftParameterGroupConfigWithTags(rInt, "bbb"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftParameterGroupExists(resourceName, &v), + resource.TestCheckResourceAttr( + resourceName, "tags.%", "3"), + resource.TestCheckResourceAttr(resourceName, "tags.description", fmt.Sprintf("Test parameter group for terraform %s", "bbb")), + ), + }, + { + Config: testAccAWSRedshiftParameterGroupConfigWithTagsUpdate(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftParameterGroupExists(resourceName, &v), + resource.TestCheckResourceAttr( + resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.name", fmt.Sprintf("test-terraform-%d", rInt)), + ), + }, + }, + }) +} + func TestResourceAWSRedshiftParameterGroupNameValidation(t *testing.T) { cases := []struct { Value string @@ -237,3 +281,33 @@ resource "aws_redshift_parameter_group" "bar" { } `, rInt) } + +func testAccAWSRedshiftParameterGroupConfigWithTags(rInt int, rString string) string { + return fmt.Sprintf(` +resource "aws_redshift_parameter_group" "default" { + name = "test-terraform-%[1]d" + family = "redshift-1.0" + description = "Test parameter group for terraform" + + tags = { + environment = "Production" + name = "test-terraform-%[1]d" + description = "Test parameter group for terraform %[2]s" + } +} +`, rInt, rString) +} + +func testAccAWSRedshiftParameterGroupConfigWithTagsUpdate(rInt int) string { + return fmt.Sprintf(` +resource "aws_redshift_parameter_group" "default" { + name = "test-terraform-%[1]d" + family = "redshift-1.0" + description = "Test parameter group for terraform" + + tags = { + name = "test-terraform-%[1]d" + } +} +`, rInt) +} diff --git a/website/docs/r/redshift_parameter_group.html.markdown b/website/docs/r/redshift_parameter_group.html.markdown index e4e6e1bcfc5..e22233baade 100644 --- a/website/docs/r/redshift_parameter_group.html.markdown +++ b/website/docs/r/redshift_parameter_group.html.markdown @@ -47,6 +47,7 @@ Parameter blocks support the following: * `name` - (Required) The name of the Redshift parameter. * `value` - (Required) The value of the Redshift parameter. +* `tags` - (Optional) A mapping of tags to assign to the resource. You can read more about the parameters that Redshift supports in the [documentation](http://docs.aws.amazon.com/redshift/latest/mgmt/working-with-parameter-groups.html) From 5e498a501c3643e2dbae441cd5156ee7de125d48 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Fri, 7 Jun 2019 07:43:45 +0900 Subject: [PATCH 2/9] fmt test configuration for aws_redshift_parameter_group --- aws/resource_aws_redshift_parameter_group_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aws/resource_aws_redshift_parameter_group_test.go b/aws/resource_aws_redshift_parameter_group_test.go index 86badc69991..8b32f7f5a9b 100644 --- a/aws/resource_aws_redshift_parameter_group_test.go +++ b/aws/resource_aws_redshift_parameter_group_test.go @@ -290,9 +290,9 @@ resource "aws_redshift_parameter_group" "default" { description = "Test parameter group for terraform" tags = { - environment = "Production" - name = "test-terraform-%[1]d" - description = "Test parameter group for terraform %[2]s" + environment = "Production" + name = "test-terraform-%[1]d" + description = "Test parameter group for terraform %[2]s" } } `, rInt, rString) @@ -306,7 +306,7 @@ resource "aws_redshift_parameter_group" "default" { description = "Test parameter group for terraform" tags = { - name = "test-terraform-%[1]d" + name = "test-terraform-%[1]d" } } `, rInt) From 565ee26301917ee043decdf74677ee0adaa33562 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Fri, 7 Jun 2019 08:23:34 +0900 Subject: [PATCH 3/9] add error handling for set tags --- aws/resource_aws_redshift_cluster.go | 4 +++- aws/resource_aws_redshift_parameter_group.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_redshift_cluster.go b/aws/resource_aws_redshift_cluster.go index 3b3378a4bef..0beda653f78 100644 --- a/aws/resource_aws_redshift_cluster.go +++ b/aws/resource_aws_redshift_cluster.go @@ -610,7 +610,9 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er d.Set("cluster_public_key", rsc.ClusterPublicKey) d.Set("cluster_revision_number", rsc.ClusterRevisionNumber) - d.Set("tags", tagsToMapRedshift(rsc.Tags)) + if err := d.Set("tags", tagsToMapRedshift(rsc.Tags)); err != nil { + return fmt.Errorf("Error setting Redshift Cluster Tags: %#v", err) + } d.Set("snapshot_copy", flattenRedshiftSnapshotCopy(rsc.ClusterSnapshotCopyStatus)) diff --git a/aws/resource_aws_redshift_parameter_group.go b/aws/resource_aws_redshift_parameter_group.go index a054a19ad6a..929139ae2e5 100644 --- a/aws/resource_aws_redshift_parameter_group.go +++ b/aws/resource_aws_redshift_parameter_group.go @@ -112,7 +112,9 @@ func resourceAwsRedshiftParameterGroupRead(d *schema.ResourceData, meta interfac d.Set("name", describeResp.ParameterGroups[0].ParameterGroupName) d.Set("family", describeResp.ParameterGroups[0].ParameterGroupFamily) d.Set("description", describeResp.ParameterGroups[0].Description) - d.Set("tags", tagsToMapRedshift(describeResp.ParameterGroups[0].Tags)) + if err := d.Set("tags", tagsToMapRedshift(describeResp.ParameterGroups[0].Tags)); err != nil { + return fmt.Errorf("Error setting Redshift Parameter Group Tags: %#v", err) + } describeParametersOpts := redshift.DescribeClusterParametersInput{ ParameterGroupName: aws.String(d.Id()), From f44bdeb08be325c043457ecdad5551a9b8112652 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Fri, 7 Jun 2019 22:58:59 +0900 Subject: [PATCH 4/9] fix to get arn from resource data --- aws/tagsRedshift.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aws/tagsRedshift.go b/aws/tagsRedshift.go index 26af8e7679b..ef3a342ea2f 100644 --- a/aws/tagsRedshift.go +++ b/aws/tagsRedshift.go @@ -9,8 +9,9 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func setTagsRedshift(conn *redshift.Redshift, d *schema.ResourceData, arn string) error { +func setTagsRedshift(conn *redshift.Redshift, d *schema.ResourceData) error { if d.HasChange("tags") { + arn := d.Get("arn").(string) oraw, nraw := d.GetChange("tags") o := oraw.(map[string]interface{}) n := nraw.(map[string]interface{}) From d5b3c52f6ee69336bb04bcc0cf38a8cb61d27ed3 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Fri, 7 Jun 2019 22:59:46 +0900 Subject: [PATCH 5/9] Fix resource_aws_redshift_snapshot_copy_grant to update tags resource --- ...source_aws_redshift_snapshot_copy_grant.go | 38 +++++++++++-- ...e_aws_redshift_snapshot_copy_grant_test.go | 55 +++++++++++++++++++ ...redshift_snapshot_copy_grant.html.markdown | 2 +- 3 files changed, 89 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_redshift_snapshot_copy_grant.go b/aws/resource_aws_redshift_snapshot_copy_grant.go index a9d4ad0261f..e2a8788b2f7 100644 --- a/aws/resource_aws_redshift_snapshot_copy_grant.go +++ b/aws/resource_aws_redshift_snapshot_copy_grant.go @@ -6,6 +6,7 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/redshift" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -17,10 +18,15 @@ func resourceAwsRedshiftSnapshotCopyGrant() *schema.Resource { // Instead changes to most fields will force a new resource Create: resourceAwsRedshiftSnapshotCopyGrantCreate, Read: resourceAwsRedshiftSnapshotCopyGrantRead, + Update: resourceAwsRedshiftSnapshotCopyGrantUpdate, Delete: resourceAwsRedshiftSnapshotCopyGrantDelete, Exists: resourceAwsRedshiftSnapshotCopyGrantExists, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, "snapshot_copy_grant_name": { Type: schema.TypeString, Required: true, @@ -32,11 +38,7 @@ func resourceAwsRedshiftSnapshotCopyGrant() *schema.Resource { ForceNew: true, Computed: true, }, - "tags": { - Type: schema.TypeMap, - Optional: true, - ForceNew: true, - }, + "tags": tagsSchema(), }, } } @@ -90,6 +92,16 @@ func resourceAwsRedshiftSnapshotCopyGrantRead(d *schema.ResourceData, meta inter return nil } + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Service: "redshift", + Region: meta.(*AWSClient).region, + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("snapshotcopygrant:%s", grantName), + }.String() + + d.Set("arn", arn) + d.Set("kms_key_id", grant.KmsKeyId) d.Set("snapshot_copy_grant_name", grant.SnapshotCopyGrantName) if err := d.Set("tags", tagsToMapRedshift(grant.Tags)); err != nil { @@ -99,6 +111,22 @@ func resourceAwsRedshiftSnapshotCopyGrantRead(d *schema.ResourceData, meta inter return nil } +func resourceAwsRedshiftSnapshotCopyGrantUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).redshiftconn + + d.Partial(true) + + if tagErr := setTagsRedshift(conn, d); tagErr != nil { + return tagErr + } else { + d.SetPartial("tags") + } + + d.Partial(false) + + return resourceAwsRedshiftSnapshotCopyGrantRead(d, meta) +} + func resourceAwsRedshiftSnapshotCopyGrantDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).redshiftconn diff --git a/aws/resource_aws_redshift_snapshot_copy_grant_test.go b/aws/resource_aws_redshift_snapshot_copy_grant_test.go index f62043218be..3a5d2ab931f 100644 --- a/aws/resource_aws_redshift_snapshot_copy_grant_test.go +++ b/aws/resource_aws_redshift_snapshot_copy_grant_test.go @@ -33,6 +33,48 @@ func TestAccAWSRedshiftSnapshotCopyGrant_Basic(t *testing.T) { }) } +func TestAccAWSRedshiftSnapshotCopyGrant_Update(t *testing.T) { + + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_redshift_snapshot_copy_grant.basic" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSRedshiftSnapshotCopyGrantDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSRedshiftSnapshotCopyGrant_Basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftSnapshotCopyGrantExists(resourceName), + resource.TestCheckResourceAttr( + resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "tf-redshift-snapshot-copy-grant-basic"), + ), + }, + { + Config: testAccAWSRedshiftSnapshotCopyGrantWithTags(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftSnapshotCopyGrantExists(resourceName), + resource.TestCheckResourceAttr( + resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "tf-redshift-snapshot-copy-grant-basic"), + resource.TestCheckResourceAttr(resourceName, "tags.Env", "Production"), + ), + }, + { + Config: testAccAWSRedshiftSnapshotCopyGrant_Basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftSnapshotCopyGrantExists(resourceName), + resource.TestCheckResourceAttr( + resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "tf-redshift-snapshot-copy-grant-basic"), + ), + }, + }, + }) +} + func testAccCheckAWSRedshiftSnapshotCopyGrantDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).redshiftconn @@ -95,3 +137,16 @@ resource "aws_redshift_snapshot_copy_grant" "basic" { } `, rName) } + +func testAccAWSRedshiftSnapshotCopyGrantWithTags(rName string) string { + return fmt.Sprintf(` +resource "aws_redshift_snapshot_copy_grant" "basic" { + snapshot_copy_grant_name = "%s" + + tags = { + Name = "tf-redshift-snapshot-copy-grant-basic" + Env = "Production" + } +} +`, rName) +} diff --git a/website/docs/r/redshift_snapshot_copy_grant.html.markdown b/website/docs/r/redshift_snapshot_copy_grant.html.markdown index 2357eb575dd..b8d1daf2e14 100644 --- a/website/docs/r/redshift_snapshot_copy_grant.html.markdown +++ b/website/docs/r/redshift_snapshot_copy_grant.html.markdown @@ -38,4 +38,4 @@ The following arguments are supported: ## Attributes Reference -No additional attributes beyond the arguments above are exported. +* `arn` - Amazon Resource Name (ARN) of snapshot copy grant From 9c444a1913e0b75c4d806d7d4dc57975738f2a18 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Sat, 8 Jun 2019 00:50:10 +0900 Subject: [PATCH 6/9] add arn attributes for aws_redshift_subnet_group resource --- aws/resource_aws_redshift_subnet_group.go | 29 ++++++++++++++----- .../r/redshift_subnet_group.html.markdown | 1 + 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_redshift_subnet_group.go b/aws/resource_aws_redshift_subnet_group.go index e503108ece7..85f8848d206 100644 --- a/aws/resource_aws_redshift_subnet_group.go +++ b/aws/resource_aws_redshift_subnet_group.go @@ -22,6 +22,11 @@ func resourceAwsRedshiftSubnetGroup() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "name": { Type: schema.TypeString, ForceNew: true, @@ -103,12 +108,6 @@ func resourceAwsRedshiftSubnetGroupRead(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error setting Redshift Subnet Group Tags: %#v", err) } - return nil -} - -func resourceAwsRedshiftSubnetGroupUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).redshiftconn - arn := arn.ARN{ Partition: meta.(*AWSClient).partition, Service: "redshift", @@ -116,8 +115,20 @@ func resourceAwsRedshiftSubnetGroupUpdate(d *schema.ResourceData, meta interface AccountID: meta.(*AWSClient).accountid, Resource: fmt.Sprintf("subnetgroup:%s", d.Id()), }.String() - if tagErr := setTagsRedshift(conn, d, arn); tagErr != nil { + + d.Set("arn", arn) + + return nil +} + +func resourceAwsRedshiftSubnetGroupUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).redshiftconn + d.Partial(true) + + if tagErr := setTagsRedshift(conn, d); tagErr != nil { return tagErr + } else { + d.SetPartial("tags") } if d.HasChange("subnet_ids") || d.HasChange("description") { @@ -143,7 +154,9 @@ func resourceAwsRedshiftSubnetGroupUpdate(d *schema.ResourceData, meta interface } } - return nil + d.Partial(false) + + return resourceAwsRedshiftSubnetGroupRead(d, meta) } func resourceAwsRedshiftSubnetGroupDelete(d *schema.ResourceData, meta interface{}) error { diff --git a/website/docs/r/redshift_subnet_group.html.markdown b/website/docs/r/redshift_subnet_group.html.markdown index a2f814b5335..cc050bb0802 100644 --- a/website/docs/r/redshift_subnet_group.html.markdown +++ b/website/docs/r/redshift_subnet_group.html.markdown @@ -60,6 +60,7 @@ The following arguments are supported: In addition to all arguments above, the following attributes are exported: +* `arn` - Amazon Resource Name (ARN) of the Redshift Subnet group name * `id` - The Redshift Subnet group ID. ## Import From 4c4107f4b649cdd7c76e38bc3457707831c1cd2e Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Sat, 8 Jun 2019 00:55:23 +0900 Subject: [PATCH 7/9] Add arn attributes for aws_redshift_event_subscription resource Add update tags step --- ...esource_aws_redshift_event_subscription.go | 32 ++++++-- ...ce_aws_redshift_event_subscription_test.go | 75 +++++++++++++++++++ .../redshift_event_subscription.html.markdown | 1 + 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/aws/resource_aws_redshift_event_subscription.go b/aws/resource_aws_redshift_event_subscription.go index 8704ba6fb83..542016c7aa9 100644 --- a/aws/resource_aws_redshift_event_subscription.go +++ b/aws/resource_aws_redshift_event_subscription.go @@ -6,6 +6,7 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/redshift" "github.com/hashicorp/terraform/helper/schema" ) @@ -25,6 +26,11 @@ func resourceAwsRedshiftEventSubscription() *schema.Resource { Update: schema.DefaultTimeout(40 * time.Minute), }, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "name": { Type: schema.TypeString, Required: true, @@ -68,11 +74,7 @@ func resourceAwsRedshiftEventSubscription() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": { - Type: schema.TypeMap, - Optional: true, - ForceNew: true, - }, + "tags": tagsSchema(), }, } } @@ -106,6 +108,16 @@ func resourceAwsRedshiftEventSubscriptionCreate(d *schema.ResourceData, meta int func resourceAwsRedshiftEventSubscriptionRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).redshiftconn + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Service: "redshift", + Region: meta.(*AWSClient).region, + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("eventsubscription:%s", d.Id()), + }.String() + + d.Set("arn", arn) + sub, err := resourceAwsRedshiftEventSubscriptionRetrieve(d.Id(), conn) if err != nil { return fmt.Errorf("Error retrieving Redshift Event Subscription %s: %s", d.Id(), err) @@ -175,6 +187,8 @@ func resourceAwsRedshiftEventSubscriptionRetrieve(name string, conn *redshift.Re func resourceAwsRedshiftEventSubscriptionUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).redshiftconn + d.Partial(true) + req := &redshift.ModifyEventSubscriptionInput{ SubscriptionName: aws.String(d.Id()), SnsTopicArn: aws.String(d.Get("sns_topic_arn").(string)), @@ -191,6 +205,14 @@ func resourceAwsRedshiftEventSubscriptionUpdate(d *schema.ResourceData, meta int return fmt.Errorf("Modifying Redshift Event Subscription %s failed: %s", d.Id(), err) } + if tagErr := setTagsRedshift(conn, d); tagErr != nil { + return tagErr + } else { + d.SetPartial("tags") + } + + d.Partial(false) + return nil } diff --git a/aws/resource_aws_redshift_event_subscription_test.go b/aws/resource_aws_redshift_event_subscription_test.go index 07f4a0830e7..957fd072ac4 100644 --- a/aws/resource_aws_redshift_event_subscription_test.go +++ b/aws/resource_aws_redshift_event_subscription_test.go @@ -173,6 +173,54 @@ func TestAccAWSRedshiftEventSubscription_categoryUpdate(t *testing.T) { }) } +func TestAccAWSRedshiftEventSubscription_tagsUpdate(t *testing.T) { + var v redshift.EventSubscription + rInt := acctest.RandInt() + resourceName := "aws_redshift_event_subscription.bar" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSRedshiftEventSubscriptionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSRedshiftEventSubscriptionConfig(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftEventSubscriptionExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "name"), + ), + }, + { + Config: testAccAWSRedshiftEventSubscriptionConfigUpdateTags(rInt, "aaaaa"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftEventSubscriptionExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "name"), + resource.TestCheckResourceAttr(resourceName, "tags.Test", "aaaaa"), + ), + }, + { + Config: testAccAWSRedshiftEventSubscriptionConfigUpdateTags(rInt, "bbbbb"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftEventSubscriptionExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "name"), + resource.TestCheckResourceAttr(resourceName, "tags.Test", "bbbbb"), + ), + }, + { + Config: testAccAWSRedshiftEventSubscriptionConfig(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRedshiftEventSubscriptionExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "name"), + ), + }, + }, + }) +} + func testAccCheckAWSRedshiftEventSubscriptionExists(n string, v *redshift.EventSubscription) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -382,3 +430,30 @@ resource "aws_redshift_event_subscription" "bar" { } `, rInt, rInt) } + +func testAccAWSRedshiftEventSubscriptionConfigUpdateTags(rInt int, rString string) string { + return fmt.Sprintf(` +resource "aws_sns_topic" "aws_sns_topic" { + name = "tf-acc-test-redshift-event-subs-sns-topic-%d" +} + +resource "aws_redshift_event_subscription" "bar" { + name = "tf-acc-test-redshift-event-subs-%d" + sns_topic_arn = "${aws_sns_topic.aws_sns_topic.arn}" + source_type = "cluster" + severity = "INFO" + + event_categories = [ + "configuration", + "management", + "monitoring", + "security", + ] + + tags = { + Name = "name" + Test = "%s" + } +} +`, rInt, rInt, rString) +} diff --git a/website/docs/r/redshift_event_subscription.html.markdown b/website/docs/r/redshift_event_subscription.html.markdown index 688fbf4134d..6bb3cba0362 100644 --- a/website/docs/r/redshift_event_subscription.html.markdown +++ b/website/docs/r/redshift_event_subscription.html.markdown @@ -63,6 +63,7 @@ The following arguments are supported: The following additional atttributes are provided: +* `arn` - Amazon Resource Name (ARN) of the Redshift event notification subscription * `id` - The name of the Redshift event notification subscription * `customer_aws_id` - The AWS customer account associated with the Redshift event notification subscription From 8d920982b167d342ab111db7b4e8f139be5a2db0 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Sun, 9 Jun 2019 15:48:31 +0900 Subject: [PATCH 8/9] add attribute arn support for redshift_parameter_group resource --- aws/resource_aws_redshift_parameter_group.go | 24 ++++++++++++------- .../r/redshift_parameter_group.html.markdown | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_redshift_parameter_group.go b/aws/resource_aws_redshift_parameter_group.go index 929139ae2e5..c0ed546c24c 100644 --- a/aws/resource_aws_redshift_parameter_group.go +++ b/aws/resource_aws_redshift_parameter_group.go @@ -25,6 +25,11 @@ func resourceAwsRedshiftParameterGroup() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "name": { Type: schema.TypeString, ForceNew: true, @@ -109,6 +114,16 @@ func resourceAwsRedshiftParameterGroupRead(d *schema.ResourceData, meta interfac return fmt.Errorf("Unable to find Parameter Group: %#v", describeResp.ParameterGroups) } + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Service: "redshift", + Region: meta.(*AWSClient).region, + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("parametergroup:%s", d.Id()), + }.String() + + d.Set("arn", arn) + d.Set("name", describeResp.ParameterGroups[0].ParameterGroupName) d.Set("family", describeResp.ParameterGroups[0].ParameterGroupFamily) d.Set("description", describeResp.ParameterGroups[0].Description) @@ -168,14 +183,7 @@ func resourceAwsRedshiftParameterGroupUpdate(d *schema.ResourceData, meta interf d.SetPartial("parameter") } - arn := arn.ARN{ - Partition: meta.(*AWSClient).partition, - Service: "redshift", - Region: meta.(*AWSClient).region, - AccountID: meta.(*AWSClient).accountid, - Resource: fmt.Sprintf("parametergroup:%s", d.Id()), - }.String() - if tagErr := setTagsRedshift(conn, d, arn); tagErr != nil { + if tagErr := setTagsRedshift(conn, d); tagErr != nil { return tagErr } else { d.SetPartial("tags") diff --git a/website/docs/r/redshift_parameter_group.html.markdown b/website/docs/r/redshift_parameter_group.html.markdown index e22233baade..f027bf12071 100644 --- a/website/docs/r/redshift_parameter_group.html.markdown +++ b/website/docs/r/redshift_parameter_group.html.markdown @@ -55,6 +55,7 @@ You can read more about the parameters that Redshift supports in the [documentat In addition to all arguments above, the following attributes are exported: +* `arn` - Amazon Resource Name (ARN) of parameter group * `id` - The Redshift parameter group name. ## Import From dfc7019aa1fa28d5409351ad63f8a67dfd21562f Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Sun, 9 Jun 2019 15:49:01 +0900 Subject: [PATCH 9/9] add attribute arn support for redshift_cluster resource --- aws/resource_aws_redshift_cluster.go | 25 +++++++++++++------ website/docs/r/redshift_cluster.html.markdown | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_redshift_cluster.go b/aws/resource_aws_redshift_cluster.go index 0beda653f78..eb39321c5b3 100644 --- a/aws/resource_aws_redshift_cluster.go +++ b/aws/resource_aws_redshift_cluster.go @@ -32,6 +32,11 @@ func resourceAwsRedshiftCluster() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { Type: schema.TypeString, Optional: true, @@ -620,13 +625,6 @@ func resourceAwsRedshiftClusterRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("error setting logging: %s", err) } - return nil -} - -func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).redshiftconn - d.Partial(true) - arn := arn.ARN{ Partition: meta.(*AWSClient).partition, Service: "redshift", @@ -634,7 +632,17 @@ func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{}) AccountID: meta.(*AWSClient).accountid, Resource: fmt.Sprintf("cluster:%s", d.Id()), }.String() - if tagErr := setTagsRedshift(conn, d, arn); tagErr != nil { + + d.Set("arn", arn) + + return nil +} + +func resourceAwsRedshiftClusterUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).redshiftconn + d.Partial(true) + + if tagErr := setTagsRedshift(conn, d); tagErr != nil { return tagErr } else { d.SetPartial("tags") @@ -880,6 +888,7 @@ func resourceAwsRedshiftClusterDelete(d *schema.ResourceData, meta interface{}) } log.Printf("[DEBUG] Deleting Redshift Cluster: %s", deleteOpts) + log.Printf("[DEBUG] schema.TimeoutDelete: %+v", d.Timeout(schema.TimeoutDelete)) err := deleteAwsRedshiftCluster(&deleteOpts, conn, d.Timeout(schema.TimeoutDelete)) if err != nil { return err diff --git a/website/docs/r/redshift_cluster.html.markdown b/website/docs/r/redshift_cluster.html.markdown index dfb2ad528d0..336f71d213a 100644 --- a/website/docs/r/redshift_cluster.html.markdown +++ b/website/docs/r/redshift_cluster.html.markdown @@ -101,6 +101,7 @@ For more information on the permissions required for the bucket, please read the In addition to all arguments above, the following attributes are exported: +* `arn` - Amazon Resource Name (ARN) of cluster * `id` - The Redshift Cluster ID. * `cluster_identifier` - The Cluster Identifier * `cluster_type` - The cluster type