Skip to content

Commit

Permalink
Merge pull request #14923 from nikhil-goenka/sns_topic_subscription-e…
Browse files Browse the repository at this point in the history
…mail-support

Modernize aws_sns_topic_subscription
  • Loading branch information
YakDriver committed Feb 25, 2021
2 parents 9d15949 + 0344547 commit eec75fd
Show file tree
Hide file tree
Showing 6 changed files with 511 additions and 364 deletions.
3 changes: 3 additions & 0 deletions .changelog/14923.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_sns_topic_subscription: Add `email`, `email-json`, and `firehose` to protocol values. Add `subscription_role_arn` argument for Firehose support. Add `confirmation_was_authenticated`, `owner_id`, and `pending_confirmation` attributes.
```
30 changes: 30 additions & 0 deletions aws/internal/service/sns/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package waiter

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sns"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func SubscriptionPendingConfirmation(conn *sns.SNS, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := conn.GetSubscriptionAttributes(&sns.GetSubscriptionAttributesInput{
SubscriptionArn: aws.String(id),
})

if tfawserr.ErrCodeEquals(err, sns.ErrCodeResourceNotFoundException) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

if output == nil {
return nil, "", nil
}

return output, aws.StringValue(output.Attributes["PendingConfirmation"]), nil
}
}
28 changes: 28 additions & 0 deletions aws/internal/service/sns/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package waiter

import (
"time"

"github.com/aws/aws-sdk-go/service/sns"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

const (
SubscriptionPendingConfirmationTimeout = 2 * time.Minute
)

func SubscriptionConfirmed(conn *sns.SNS, id, expectedValue string, timeout time.Duration) (*sns.GetSubscriptionAttributesOutput, error) {
stateConf := &resource.StateChangeConf{
Target: []string{expectedValue},
Refresh: SubscriptionPendingConfirmation(conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*sns.GetSubscriptionAttributesOutput); ok {
return output, err
}

return nil, err
}
Loading

0 comments on commit eec75fd

Please sign in to comment.