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

r/sns_topic - add firehose args #19528

Merged
merged 3 commits into from
May 26, 2021
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
11 changes: 11 additions & 0 deletions .changelog/19528.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/aws_sns_topic: Add `firehose_success_feedback_role_arn`, `firehose_success_feedback_sample_rate` and `firehose_failure_feedback_role_arn` arguments.
```

```release-note:enhancement
resource/aws_sns_topic: Add plan time validation for `application_success_feedback_role_arn`, `application_failure_feedback_role_arn`, `http_success_feedback_role_arn`, `http_failure_feedback_role_arn`, `lambda_success_feedback_role_arn`, `lambda_failure_feedback_role_arn`, `sqs_success_feedback_role_arn`, `sqs_failure_feedback_role_arn`.
```

```release-note:enhancement
resource/aws_sns_topic: Add `owner` attribute.
```
110 changes: 94 additions & 16 deletions aws/resource_aws_sns_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,34 @@ func resourceAwsSnsTopic() *schema.Resource {
},
},
"application_success_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"application_success_feedback_sample_rate": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 100),
},
"application_failure_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"http_success_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"http_success_feedback_sample_rate": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 100),
},
"http_failure_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"kms_master_key_id": {
Type: schema.TypeString,
Expand All @@ -115,36 +119,59 @@ func resourceAwsSnsTopic() *schema.Resource {
Optional: true,
Default: false,
},
"firehose_success_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"firehose_success_feedback_sample_rate": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 100),
},
"firehose_failure_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"lambda_success_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"lambda_success_feedback_sample_rate": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 100),
},
"lambda_failure_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"sqs_success_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"sqs_success_feedback_sample_rate": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 100),
},
"sqs_failure_feedback_role_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"owner": {
Type: schema.TypeString,
Computed: true,
},
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
},
Expand Down Expand Up @@ -298,6 +325,24 @@ func resourceAwsSnsTopicCreate(d *schema.ResourceData, meta interface{}) error {
return err
}
}
if d.HasChange("firehose_failure_feedback_role_arn") {
_, v := d.GetChange("firehose_failure_feedback_role_arn")
if err := updateAwsSnsTopicAttribute(d.Id(), "FirehoseFailureFeedbackRoleArn", v, snsconn); err != nil {
return err
}
}
if d.HasChange("firehose_success_feedback_role_arn") {
_, v := d.GetChange("firehose_success_feedback_role_arn")
if err := updateAwsSnsTopicAttribute(d.Id(), "FirehoseSuccessFeedbackRoleArn", v, snsconn); err != nil {
return err
}
}
if d.HasChange("firehose_success_feedback_sample_rate") {
_, v := d.GetChange("firehose_success_feedback_sample_rate")
if err := updateAwsSnsTopicAttribute(d.Id(), "FirehoseSuccessFeedbackSampleRate", v, snsconn); err != nil {
return err
}
}

return resourceAwsSnsTopicRead(d, meta)
}
Expand Down Expand Up @@ -414,6 +459,24 @@ func resourceAwsSnsTopicUpdate(d *schema.ResourceData, meta interface{}) error {
return err
}
}
if d.HasChange("firehose_failure_feedback_role_arn") {
_, v := d.GetChange("firehose_failure_feedback_role_arn")
if err := updateAwsSnsTopicAttribute(d.Id(), "FirehoseFailureFeedbackRoleArn", v, snsconn); err != nil {
return err
}
}
if d.HasChange("firehose_success_feedback_role_arn") {
_, v := d.GetChange("firehose_success_feedback_role_arn")
if err := updateAwsSnsTopicAttribute(d.Id(), "FirehoseSuccessFeedbackRoleArn", v, snsconn); err != nil {
return err
}
}
if d.HasChange("firehose_success_feedback_sample_rate") {
_, v := d.GetChange("firehose_success_feedback_sample_rate")
if err := updateAwsSnsTopicAttribute(d.Id(), "FirehoseSuccessFeedbackSampleRate", v, snsconn); err != nil {
return err
}
}

if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")
Expand Down Expand Up @@ -463,6 +526,9 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error {
d.Set("policy", attributeOutput.Attributes["Policy"])
d.Set("sqs_failure_feedback_role_arn", attributeOutput.Attributes["SQSFailureFeedbackRoleArn"])
d.Set("sqs_success_feedback_role_arn", attributeOutput.Attributes["SQSSuccessFeedbackRoleArn"])
d.Set("firehose_success_feedback_role_arn", attributeOutput.Attributes["FirehoseSuccessFeedbackRoleArn"])
d.Set("firehose_failure_feedback_role_arn", attributeOutput.Attributes["FirehoseFailureFeedbackRoleArn"])
d.Set("owner", attributeOutput.Attributes["Owner"])

// set the boolean values
if v, ok := attributeOutput.Attributes["FifoTopic"]; ok && aws.StringValue(v) == "true" {
Expand Down Expand Up @@ -513,6 +579,15 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("sqs_success_feedback_sample_rate", v)
}

vStr = aws.StringValue(attributeOutput.Attributes["FirehoseSuccessFeedbackSampleRate"])
if vStr != "" {
v, err = strconv.ParseInt(vStr, 10, 64)
if err != nil {
return fmt.Errorf("error parsing integer attribute 'FirehoseSuccessFeedbackSampleRate': %w", err)
}
d.Set("firehose_success_feedback_sample_rate", v)
}
}

d.Set("fifo_topic", fifoTopic)
Expand Down Expand Up @@ -560,6 +635,9 @@ func resourceAwsSnsTopicDelete(d *schema.ResourceData, meta interface{}) error {
})

if err != nil {
if isAWSErr(err, sns.ErrCodeNotFoundException, "") {
return nil
}
return fmt.Errorf("error deleting SNS Topic (%s): %w", d.Id(), err)
}

Expand Down
39 changes: 39 additions & 0 deletions aws/resource_aws_sns_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func TestAccAWSSNSTopic_basic(t *testing.T) {
naming.TestCheckResourceAttrNameGenerated(resourceName, "name"),
resource.TestCheckResourceAttr(resourceName, "name_prefix", "terraform-"),
resource.TestCheckResourceAttr(resourceName, "fifo_topic", "false"),
testAccCheckResourceAttrAccountID(resourceName, "owner"),
),
},
{
Expand Down Expand Up @@ -227,6 +228,11 @@ func TestAccAWSSNSTopic_withIAMRole(t *testing.T) {
testAccCheckAWSSNSTopicExists(resourceName, attributes),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -304,8 +310,16 @@ func TestAccAWSSNSTopic_deliveryStatus(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "sqs_success_feedback_role_arn", iamRoleResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "sqs_success_feedback_sample_rate", "70"),
resource.TestCheckResourceAttrPair(resourceName, "sqs_failure_feedback_role_arn", iamRoleResourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "firehose_failure_feedback_role_arn", iamRoleResourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "firehose_success_feedback_role_arn", iamRoleResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "firehose_success_feedback_sample_rate", "60"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -526,6 +540,28 @@ func TestAccAWSSNSTopic_tags(t *testing.T) {
})
}

func TestAccAWSSNSTopic_disappears(t *testing.T) {
attributes := make(map[string]string)
resourceName := "aws_sns_topic.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, sns.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSNSTopicDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSNSTopicConfigNameGenerated,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSNSTopicExists(resourceName, attributes),
testAccCheckResourceDisappears(testAccProvider, resourceAwsSnsTopic(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckAWSNSTopicHasPolicy(n string, expectedPolicyText string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -871,6 +907,9 @@ resource "aws_sns_topic" "test" {
sqs_success_feedback_role_arn = aws_iam_role.example.arn
sqs_success_feedback_sample_rate = 70
sqs_failure_feedback_role_arn = aws_iam_role.example.arn
firehose_success_feedback_sample_rate = 60
firehose_failure_feedback_role_arn = aws_iam_role.example.arn
firehose_success_feedback_role_arn = aws_iam_role.example.arn
}

data "aws_partition" "current" {}
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/sns_topic.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ The following arguments are supported:
* `sqs_success_feedback_role_arn` - (Optional) The IAM role permitted to receive success feedback for this topic
* `sqs_success_feedback_sample_rate` - (Optional) Percentage of success to sample
* `sqs_failure_feedback_role_arn` - (Optional) IAM role for failure feedback
* `firehose_success_feedback_role_arn` - (Optional) The IAM role permitted to receive success feedback for this topic
* `firehose_success_feedback_sample_rate` - (Optional) Percentage of success to sample
* `firehose_failure_feedback_role_arn` - (Optional) IAM role for failure feedback
* `tags` - (Optional) Key-value map of resource tags. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.

## Attributes Reference
Expand All @@ -100,6 +103,7 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The ARN of the SNS topic
* `arn` - The ARN of the SNS topic, as a more obvious property (clone of id)
* `owner` - The AWS Account ID of the SNS topic owner
* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block).

## Import
Expand Down