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

aws_sns_topic_subscription resource produced new value for was present but now absent #12692

Closed
MattMcKeithen opened this issue Apr 6, 2020 · 3 comments · Fixed by #18475
Closed
Assignees
Labels
bug Addresses a defect in current functionality. service/sns Issues and PRs that pertain to the sns service.
Milestone

Comments

@MattMcKeithen
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

2.53.0 (compared to Master - no changes)

Affected Resource(s)

  • aws_sns_topic_subscription

Initial Triage

Protocol sqs

It looks like the response to the subscribe request returns "pending confirmation"
and we end up with
'Invalid SNS Subscription, received a "pending confirmation" ARN'

This can be seen by following the logic beginning here:
https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_sns_topic_subscription.go#L223
and here where it returns nil
https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_sns_topic_subscription.go#L109

It appears that if your protocol is http or https it will check for pending confirmation and retry but not for SQS. I don't think it would be too difficult to add a bit of retry logic here for SQS as well?

You can easily reproduce this in the console or cli.
<entry> <key>PendingConfirmation</key> <value>true</value> </entry>

in my case our endpoint is in another account (not sure if that is adding just enough delay?).

Terraform Configuration Files

resource "aws_sns_topic_subscription" "sqs_target" {
  topic_arn  = aws_sns_topic.topic.arn
  protocol   = "sqs"
  endpoint   = "arn:aws:sqs:REGION:OTHER_ACCOUNT:SQS_NAME"
}

Debug Output

Sorry, can't create gist because of network policy :-(

2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: 2020/04/06 16:07:08 [DEBUG] [aws-sdk-go] DEBUG: Response sns/Subscribe Details:
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: ---[ RESPONSE ]--------------------------------------
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: HTTP/1.1 200 OK
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: Connection: close
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: Content-Length: 298
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: Content-Type: text/xml
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: Date: Mon, 06 Apr 2020 16:07:07 GMT
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: X-Amzn-Requestid: f1856eaa-ce61-59e5-87b1-39af9b8d044e
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4:
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4:
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: -----------------------------------------------------
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: 2020/04/06 16:07:08 [DEBUG] [aws-sdk-go]
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4:
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: pending confirmation
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4:
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4:
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: f1856eaa-ce61-59e5-87b1-39af9b8d044e
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4:
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4:
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: 2020/04/06 16:07:08 [DEBUG] Finished subscribing to topic arn:aws:sns:REGION:ACCOUNT:TOPIC with subscription arn pending confirmation
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: 2020/04/06 16:07:08 [DEBUG] Created new subscription! pending confirmation
2020-04-06T16:07:08.624Z [DEBUG] plugin.terraform-provider-aws_v2.53.0_x4: 2020/04/06 16:07:08 [WARN] Invalid SNS Subscription, received a "pending confirmation" ARN
2020/04/06 16:07:08 [DEBUG] module.MODULE1.module.MODULE2.module.MODULE3.aws_sns_topic_subscription.SUBSCRIPTION: apply errored, but we're indicating that via the Error pointer rather than returning it: Provider produced inconsistent result after apply: When applying changes to module.MODULE1.module.MODULE2.module.MODULE3.aws_sns_topic_subscription.SUBSCRIPTION, provider "aws" produced an unexpected new value for was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own issue tracker.
2020/04/06 16:07:08 [TRACE] module.MODULE1.module.MODULE2.module.MODULE3: eval: *terraform.EvalMaybeTainted
2020/04/06 16:07:08 [TRACE] EvalMaybeTainted: module.MODULE1.module.MODULE2.module.MODULE3.aws_sns_topic_subscription.SUBSCRIPTION encountered an error during creation, so it is now marked as tainted
2020/04/06 16:07:08 [ERROR] module.MODULE1.module.MODULE2.module.MODULE3: eval: *terraform.EvalApplyPost, err: Provider produced inconsistent result after apply: When applying changes to module.MODULE1.module.MODULE2.module.MODULE3.aws_sns_topic_subscription.SUBSCRIPTION, provider "aws" produced an unexpected new value for was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own issue tracker.
2020/04/06 16:07:08 [ERROR] module.MODULE1.module.MODULE2.module.MODULE3: eval: *terraform.EvalSequence, err: Provider produced inconsistent result after apply: When applying changes to module.MODULE1.module.MODULE2.module.MODULE3.aws_sns_topic_subscription.SUBSCRIPTION, provider "aws" produced an unexpected new value for was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own issue tracker.

Panic Output

Expected Behavior

Create subscription, wait for confirmation to complete, and update state

Actual Behavior

Creates subscription, doesn't wait for confirmation, doesn't update state, throws above error

Steps to Reproduce

  1. terraform apply

Important Factoids

SNS subscription endpoint is in another account. Subscription is created but terraform errors and state is not update.

References

@ghost ghost added the service/sns Issues and PRs that pertain to the sns service. label Apr 6, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Apr 6, 2020
@GiedriusQ
Copy link

For all of those who are struggling to create subscription to SQS located in different account: firstly you need to add SNS policy (SNS:Subscribe) to allow subscription creation from other account, it can be found here https://docs.aws.amazon.com/sns/latest/dg/sns-send-message-to-sqs-cross-account.html. Then you can create subscription resource using SQS owner's account.

rjulian added a commit to reflexivesecurity/reflex-engine that referenced this issue Aug 19, 2020
@ewbankkit ewbankkit added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Jan 27, 2021
bflad added a commit that referenced this issue Mar 30, 2021
…l consistency, enforce lowercase protocol argument validation

Reference: #10225
Reference: #11737
Reference: #12692
Reference: #16695
Reference: #16796

The `protocol` validation update is to catch where the API accepts uppercase values such as `HTTPS`, but prevents proper handling when the API canonicalizes it to lowercase. The API documentation and existing Terraform documentation solely use lowercase.

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAWSSNSTopicSubscription_autoConfirmingEndpoint (95.60s)
--- PASS: TestAccAWSSNSTopicSubscription_autoConfirmingSecuredEndpoint (137.43s)
--- PASS: TestAccAWSSNSTopicSubscription_basic (66.20s)
--- PASS: TestAccAWSSNSTopicSubscription_deliveryPolicy (69.55s)
--- PASS: TestAccAWSSNSTopicSubscription_disappears (74.02s)
--- PASS: TestAccAWSSNSTopicSubscription_disappears_topic (75.13s)
--- PASS: TestAccAWSSNSTopicSubscription_email (16.78s)
--- PASS: TestAccAWSSNSTopicSubscription_filterPolicy (71.62s)
--- PASS: TestAccAWSSNSTopicSubscription_firehose (140.29s)
--- PASS: TestAccAWSSNSTopicSubscription_rawMessageDelivery (69.77s)
--- PASS: TestAccAWSSNSTopicSubscription_redrivePolicy (64.88s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAWSSNSTopicSubscription_basic (70.13s)
--- PASS: TestAccAWSSNSTopicSubscription_deliveryPolicy (106.45s)
--- PASS: TestAccAWSSNSTopicSubscription_disappears (82.09s)
--- PASS: TestAccAWSSNSTopicSubscription_disappears_topic (68.14s)
--- PASS: TestAccAWSSNSTopicSubscription_email (20.04s)
--- PASS: TestAccAWSSNSTopicSubscription_filterPolicy (106.32s)
--- PASS: TestAccAWSSNSTopicSubscription_rawMessageDelivery (95.36s)
--- PASS: TestAccAWSSNSTopicSubscription_redrivePolicy (110.75s)
--- SKIP: TestAccAWSSNSTopicSubscription_autoConfirmingEndpoint (1.41s)
--- SKIP: TestAccAWSSNSTopicSubscription_autoConfirmingSecuredEndpoint (1.41s)
--- SKIP: TestAccAWSSNSTopicSubscription_firehose (53.36s)
```
@bflad bflad self-assigned this Mar 30, 2021
bflad added a commit that referenced this issue Mar 30, 2021
…l consistency, enforce lowercase protocol argument validation (#18475)

* resource/aws_sns_topic_subscription: Handle read-after-create eventual consistency, enforce lowercase protocol argument validation

Reference: #10225
Reference: #11737
Reference: #12692
Reference: #16695
Reference: #16796

The `protocol` validation update is to catch where the API accepts uppercase values such as `HTTPS`, but prevents proper handling when the API canonicalizes it to lowercase. The API documentation and existing Terraform documentation solely use lowercase.

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAWSSNSTopicSubscription_autoConfirmingEndpoint (95.60s)
--- PASS: TestAccAWSSNSTopicSubscription_autoConfirmingSecuredEndpoint (137.43s)
--- PASS: TestAccAWSSNSTopicSubscription_basic (66.20s)
--- PASS: TestAccAWSSNSTopicSubscription_deliveryPolicy (69.55s)
--- PASS: TestAccAWSSNSTopicSubscription_disappears (74.02s)
--- PASS: TestAccAWSSNSTopicSubscription_disappears_topic (75.13s)
--- PASS: TestAccAWSSNSTopicSubscription_email (16.78s)
--- PASS: TestAccAWSSNSTopicSubscription_filterPolicy (71.62s)
--- PASS: TestAccAWSSNSTopicSubscription_firehose (140.29s)
--- PASS: TestAccAWSSNSTopicSubscription_rawMessageDelivery (69.77s)
--- PASS: TestAccAWSSNSTopicSubscription_redrivePolicy (64.88s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAWSSNSTopicSubscription_basic (70.13s)
--- PASS: TestAccAWSSNSTopicSubscription_deliveryPolicy (106.45s)
--- PASS: TestAccAWSSNSTopicSubscription_disappears (82.09s)
--- PASS: TestAccAWSSNSTopicSubscription_disappears_topic (68.14s)
--- PASS: TestAccAWSSNSTopicSubscription_email (20.04s)
--- PASS: TestAccAWSSNSTopicSubscription_filterPolicy (106.32s)
--- PASS: TestAccAWSSNSTopicSubscription_rawMessageDelivery (95.36s)
--- PASS: TestAccAWSSNSTopicSubscription_redrivePolicy (110.75s)
--- SKIP: TestAccAWSSNSTopicSubscription_autoConfirmingEndpoint (1.41s)
--- SKIP: TestAccAWSSNSTopicSubscription_autoConfirmingSecuredEndpoint (1.41s)
--- SKIP: TestAccAWSSNSTopicSubscription_firehose (53.36s)
```

* Update CHANGELOG for #18475
@github-actions github-actions bot added this to the v3.35.0 milestone Mar 30, 2021
@ghost
Copy link

ghost commented Apr 1, 2021

This has been released in version 3.35.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Apr 30, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/sns Issues and PRs that pertain to the sns service.
Projects
None yet
4 participants