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/aws_sns_topic: Provider now errors with fake iam role #1548

Merged
merged 3 commits into from
Sep 1, 2017

Conversation

mbfrahry
Copy link
Member

This PR is a migration from hashicorp/terraform#14226 and fixes #738.

make testacc TEST=./aws TESTARGS="-run=TestAccAWSSNSTopic_withFakeIAMRole"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSSNSTopic_withFakeIAMRole -timeout 120m
=== RUN   TestAccAWSSNSTopic_withFakeIAMRole
--- PASS: TestAccAWSSNSTopic_withFakeIAMRole (8.34s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	8.375s

@mbfrahry mbfrahry requested a review from catsby August 30, 2017 22:12
@Ninir Ninir changed the title Provider now errors with fake iam role r/aws_sns_topic: Provider now errors with fake iam role Aug 31, 2017
@Ninir Ninir added the bug Addresses a defect in current functionality. label Aug 31, 2017
Copy link
Contributor

@Ninir Ninir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mbfrahry

Seems good to me! 👍
Ran all the SnsTopic* tests, and found a small issue:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSSNSTopic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSSNSTopic -timeout 120m
=== RUN   TestAccAWSSNSTopicSubscription_importBasic
--- PASS: TestAccAWSSNSTopicSubscription_importBasic (43.31s)
=== RUN   TestAccAWSSNSTopic_importBasic
--- PASS: TestAccAWSSNSTopic_importBasic (32.88s)
=== RUN   TestAccAWSSNSTopicPolicy_basic
--- PASS: TestAccAWSSNSTopicPolicy_basic (30.70s)
=== RUN   TestAccAWSSNSTopicSubscription_basic
--- PASS: TestAccAWSSNSTopicSubscription_basic (42.49s)
=== RUN   TestAccAWSSNSTopicSubscription_autoConfirmingEndpoint
--- PASS: TestAccAWSSNSTopicSubscription_autoConfirmingEndpoint (76.98s)
=== RUN   TestAccAWSSNSTopicSubscription_autoConfirmingSecuredEndpoint
--- PASS: TestAccAWSSNSTopicSubscription_autoConfirmingSecuredEndpoint (116.68s)
=== RUN   TestAccAWSSNSTopic_basic
--- PASS: TestAccAWSSNSTopic_basic (34.14s)
=== RUN   TestAccAWSSNSTopic_policy
--- PASS: TestAccAWSSNSTopic_policy (34.95s)
=== RUN   TestAccAWSSNSTopic_withIAMRole
--- FAIL: TestAccAWSSNSTopic_withIAMRole (36.00s)
	testing.go:435: Step 0 error: Error applying: 1 error(s) occurred:
		
		* aws_sns_topic.test_topic: 1 error(s) occurred:
		
		* aws_sns_topic.test_topic: InvalidParameter: Invalid parameter: Policy Error: PrincipalNotFound
			status code: 400, request id: 653c854c-bdec-5599-8f12-d76d0c373c3e
=== RUN   TestAccAWSSNSTopic_withFakeIAMRole
--- PASS: TestAccAWSSNSTopic_withFakeIAMRole (21.62s)
=== RUN   TestAccAWSSNSTopic_withDeliveryPolicy
--- PASS: TestAccAWSSNSTopic_withDeliveryPolicy (22.23s)
FAIL
exit status 1
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	491.98s
make: *** [testacc] Error 1

Can you fix the related test? thanks!

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the error message mentioned in #738 is very confusing, but we have the retry logic in place because IAM is eventually consistent, so that needs to stay there (i.e. we still need to retry, not stop on first error which may just be an effect of delayed replication).

The ideal solution would be to just replace the unnecessarily complex resource.StateChangeConf which is lacking support for "retryable errors" and other things we need here and requires pending/target state to be a thing (which we're just making up here to satisfy the interface).

resource.Retry is IMO better suited for this job: https://github.com/hashicorp/terraform/blob/master/helper/resource/wait.go#L53

Let me know what you think.

@@ -147,7 +147,7 @@ func resourceAwsSNSUpdateRefreshFunc(
// if the error contains the PrincipalNotFound message, we can retry
if strings.Contains(awsErr.Message(), "PrincipalNotFound") {
log.Printf("[DEBUG] Retrying AWS SNS Topic Update: %s", params)
return nil, "retrying", nil
return nil, "retrying", err
Copy link
Contributor

@catsby catsby Aug 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning err here instead of nil will cause this WaitForState method to quit immediately. We have to return nil here because the intent is to retry right here:

https://github.com/terraform-providers/terraform-provider-aws/blob/068ff1beeb935dc6034b52a6ee38cef9f6fd60bd/vendor/github.com/hashicorp/terraform/helper/resource/state.go#L41

I agree with Radek, reworking this into resource.Retry may be better. I realize this isn't your code or change so let me know if you want to hand it off. Until StateChangeConf can surface "error before last", we're in this spot.

@mbfrahry
Copy link
Member Author

Alright, I swapped it to use resource.Retry and got all passing tests.

make testacc TEST=./aws TESTARGS="-run=TestAccAWSSNSTop"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSSNSTop -timeout 120m
=== RUN   TestAccAWSSNSTopicSubscription_importBasic
--- PASS: TestAccAWSSNSTopicSubscription_importBasic (17.87s)
=== RUN   TestAccAWSSNSTopic_importBasic
--- PASS: TestAccAWSSNSTopic_importBasic (14.94s)
=== RUN   TestAccAWSSNSTopicPolicy_basic
--- PASS: TestAccAWSSNSTopicPolicy_basic (13.65s)
=== RUN   TestAccAWSSNSTopicSubscription_basic
--- PASS: TestAccAWSSNSTopicSubscription_basic (16.03s)
=== RUN   TestAccAWSSNSTopicSubscription_autoConfirmingEndpoint
--- PASS: TestAccAWSSNSTopicSubscription_autoConfirmingEndpoint (47.91s)
=== RUN   TestAccAWSSNSTopicSubscription_autoConfirmingSecuredEndpoint
--- PASS: TestAccAWSSNSTopicSubscription_autoConfirmingSecuredEndpoint (74.01s)
=== RUN   TestAccAWSSNSTopic_basic
--- PASS: TestAccAWSSNSTopic_basic (13.92s)
=== RUN   TestAccAWSSNSTopic_policy
--- PASS: TestAccAWSSNSTopic_policy (12.64s)
=== RUN   TestAccAWSSNSTopic_withIAMRole
--- PASS: TestAccAWSSNSTopic_withIAMRole (32.41s)
=== RUN   TestAccAWSSNSTopic_withFakeIAMRole
--- PASS: TestAccAWSSNSTopic_withFakeIAMRole (69.48s)
=== RUN   TestAccAWSSNSTopic_withDeliveryPolicy
--- PASS: TestAccAWSSNSTopic_withDeliveryPolicy (12.96s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	325.855s

@mbfrahry
Copy link
Member Author

Thanks for pointing me towards that retry function!

@radeksimko
Copy link
Member

Thanks for making those changes, retryOnAwsCode is probably even better.

Do you mind replacing this in the two other operations (resourceAwsSnsTopicPolicyUpsert & resourceAwsSnsTopicPolicyDelete) too & removing resourceAwsSNSUpdateRefreshFunc altogether?

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Sep 1, 2017
@mbfrahry
Copy link
Member Author

mbfrahry commented Sep 1, 2017

Alright! It's all gone and tests are passing

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@mbfrahry mbfrahry merged commit 48a88a0 into master Sep 1, 2017
@mbfrahry mbfrahry deleted the b-sns-topic-policy-fake-principal branch September 1, 2017 15:26
nbaztec pushed a commit to nbaztec/terraform-provider-aws that referenced this pull request Sep 26, 2017
…c-policy-fake-principal

r/aws_sns_topic: Provider now errors with fake iam role
@ghost
Copy link

ghost commented Apr 11, 2020

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 and limited conversation to collaborators Apr 11, 2020
@breathingdust breathingdust removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 17, 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_sns_topic_policy fails to return errors to user
5 participants