-
-
Notifications
You must be signed in to change notification settings - Fork 343
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
When passing in SNS Topic, there's a race condition if it's not already created #46
Comments
The workaround for this is to target your sns topic and apply it before you plan the rest of your stuff. It works, but when your system is set up for applying terraform with a CI Pipeline, this falls apart.
|
Hi @bushong1 ! I agree it should work automatically within a CI/CD pipeline and, I believe, it does so. I tried to reproduce this issue on version 2.0.0 with the exact code as you provide. See this updated example. The sequence of execution is correct:
Can you please show the sequence of resources it tries to create during |
Thanks for looking into it. Sorry about the 'sample code' that worked. I was trying to condense the issue from our code found here: https://github.com/USSBA/terraform-aws-sns-notification-framework/blob/master/main.tf I'm curious if it has something to do with nested modules? I'll try testing it out. |
Okay @antonbabenko, here's an update: TL;DR: Try your sample code again, but with a workspace that has already had 1 deployment to it. Here's my brain-train of how I got to replicate the issue:
Running this with a workspace that has some of my application or account code, I get the error:
But... running this same code in a fresh workspace with no other code applied, i get a totally clean plan, just like your example code:
Super strange. HOWEVER.... If in my new workspace I comment out these sns creations first, create a temporary resource:
Apply this, to "initialize" the workspace, then un-comment this sample code...
I get the error:
And, in fact, if I re-enable the notify-slack module, i get the same failure to plan.
|
Any update on this, @antonbabenko ? |
Unfortunately, I don't understand what is going on here in your code. You are using Terraform workspaces and I am almost certain that the problem is related to that. PS: I am against using Terraform workspaces in 99% of cases (including yours) :) |
@antonbabenko okay, as I said at the top with some rewording: For example:
and then edit the file to be this and apply again:
|
I just ran into this issue as well and have hit it in other modules in the past. I believe this is due to a change of behavior in terraform 0.12. The suggested change is we should no longer be looking up data sources from inside modules, but instead we should be passing in the entire resource objects as variables. See hashicorp/terraform#22730 for details. |
@antonbabenko any chance to take a look at this PR? |
Bump |
I also face this issue with Thanks in advance |
Just want to +1 here, I've run into a lot of issues with using this module and an already existing topic. 😓 Would be great if this fix could be merged. |
I still don't understand why it is happening, and the solution of passing the whole resource as an object does work but it is not how we handle arguments in Also, I could not reproduce this problem myself which makes the fix rather hard for me. If anyone can give me 100% working instructions (as similar to |
@antonbabenko I gave an example of the bug that you never replied to. I'll re-paste it here: The bug only crops up in an already existing terraform state. So...
and then edit the file to be this and apply again:
|
…race condition Data Resources are evaluated before any code is executed, so if a single terraform apply intends to create an SNS topic _and_ create this module, the apply will fail because the data resource cannot resolve. Avoiding the use of data resources by deriving the SNS manually corrects the issue in this case.
…race condition Data Resources are evaluated before any code is executed, so if a single terraform apply intends to create an SNS topic _and_ create this module, the apply will fail because the data resource cannot resolve. Avoiding the use of data resources by deriving the SNS manually corrects the issue in this case.
…race condition Data Resources are evaluated before any code is executed, so if a single terraform apply intends to create an SNS topic _and_ create this module, the apply will fail because the data resource cannot resolve. Avoiding the use of data resources by deriving the SNS manually corrects the issue in this case.
…race condition Data Resources are evaluated before any code is executed, so if a single terraform apply intends to create an SNS topic _and_ create this module, the apply will fail because the data resource cannot resolve. Avoiding the use of data resources by deriving the SNS manually corrects the issue in this case.
…form-aws-modulesGH-46 Data Resources are evaluated before any code is executed, so if a single terraform apply intends to create an SNS topic _and_ create this module, the apply will fail because the data resource cannot resolve. Avoiding the use of data resources by deriving the SNS manually corrects the issue in this case.
@antonbabenko I've created a fairly straightforward PR to address the problem. Hopefully this helps clear things up. |
…form-aws-modulesGH-46 Data Resources are evaluated before any code is executed, so if a single terraform apply intends to create an SNS topic _and_ create this module, the apply will fail because the data resource cannot resolve. Avoiding the use of data resources by deriving the SNS manually corrects the issue in this case.
Not sure if you are still facing this but I managed to get around by adding depends_on in data section of the module instead of creating topic resource outside of the module.
|
Commenting to mention that I also ran into this issue |
Bump |
Finally! :) v4.12.0 has been just released. |
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
If the SNS topic passed in is NOT already created, the notify-slack module will fail. This is due to notify-slack's data objects being resolved before my
resource
objects.From what I can tell, the only usage of the data resource is to ensure that SNS exists before running, and then to craft the ARN. I'd suggest hand-crafting the ARN with the Topic Name instead. I can submit a PR if it would be helpful.
The text was updated successfully, but these errors were encountered: