Comments (20)
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.
from terraform-aws-notify-slack.
Finally! :)
v4.12.0 has been just released.
from terraform-aws-notify-slack.
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.
terraform apply -target aws_sns_topic.my_sns
...
terraform plan
terraform apply
from terraform-aws-notify-slack.
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:
aws_sns_topic.my_sns: Creating...
module.notify_slack.aws_iam_role.lambda[0]: Creating...
aws_sns_topic.my_sns: Creation complete after 1s [id=arn:aws:sns:eu-west-1:835367859852:my-sns]
module.notify_slack.data.aws_sns_topic.this[0]: Refreshing state...
...
Can you please show the sequence of resources it tries to create during terraform apply
?
from terraform-aws-notify-slack.
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.
from terraform-aws-notify-slack.
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:
With a file sns.tf
resource "aws_sns_topic" "my_sns" {
name = "my-sns"
}
data "aws_sns_topic" "this" {
name = aws_sns_topic.my_sns.name
}
Running this with a workspace that has some of my application or account code, I get the error:
Error: No topic with name "my-sns" found in this region.
on sns.tf line 4, in data "aws_sns_topic" "this":
4: data "aws_sns_topic" "this" {
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:
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
<= read (data resources)
Terraform will perform the following actions:
# data.aws_sns_topic.this will be read during apply
# (config refers to values not yet known)
<= data "aws_sns_topic" "this" {
+ arn = (known after apply)
+ id = (known after apply)
+ name = "my-sns"
}
# aws_sns_topic.my_sns will be created
+ resource "aws_sns_topic" "my_sns" {
+ arn = (known after apply)
+ id = (known after apply)
+ name = "my-sns"
+ policy = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Super strange. HOWEVER.... If in my new workspace I comment out these sns creations first, create a temporary resource:
resource "aws_ssm_parameter" "my_test_parameter" {
name = "test_parameter"
type = "String"
value = "foo"
}
#resource "aws_sns_topic" "my_sns" {
# name = "my-sns"
#}
#data "aws_sns_topic" "this" {
# name = aws_sns_topic.my_sns.name
#}
Apply this, to "initialize" the workspace, then un-comment this sample code...
resource "aws_ssm_parameter" "my_test_parameter" {
name = "test_parameter"
type = "String"
value = "foo"
}
resource "aws_sns_topic" "my_sns" {
name = "my-sns"
}
data "aws_sns_topic" "this" {
name = aws_sns_topic.my_sns.name
}
I get the error:
Error: No topic with name "my-sns" found in this region.
on sns.tf line 9, in data "aws_sns_topic" "this":
9: data "aws_sns_topic" "this" {
And, in fact, if I re-enable the notify-slack module, i get the same failure to plan.
Error: No topic with name "my-sns" found in this region.
on .terraform/modules/notify_slack/terraform-aws-modules-terraform-aws-notify-slack-e3ffbba/main.tf line 1, in data "aws_sns_topic" "this":
1: data "aws_sns_topic" "this" {
from terraform-aws-notify-slack.
Any update on this, @antonbabenko ?
from terraform-aws-notify-slack.
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) :)
from terraform-aws-notify-slack.
@antonbabenko okay, as I said at the top with some rewording:
Try your sample code again, but with a workspace terraform state that has already had 1 deployment to it.
For example:
tf apply
this:
provider "aws" {
region = "eu-west-1"
}
resource "aws_sns_topic" "bogus_sns" {
name = "some-bogus-sns-topic"
}
and then edit the file to be this and apply again:
provider "aws" {
region = "eu-west-1"
}
resource "aws_sns_topic" "my_sns" {
name = "my-sns"
}
module "notify_slack" {
source = "../../"
sns_topic_name = aws_sns_topic.my_sns.name
create_sns_topic = false
slack_webhook_url = "https://hooks.slack.com/services/AAA/BBB/CCC"
slack_channel = "aws-notification"
slack_username = "reporter"
tags = {
Name = "notify-slack-simple"
}
}
from terraform-aws-notify-slack.
@antonbabenko any chance to take a look at this PR?
from terraform-aws-notify-slack.
Bump
from terraform-aws-notify-slack.
I also face this issue with terraform 0.12
and it makes the pipeline to fail as well. @antonbabenko would you be able to find some time to review MR and hopefully merge it?
Thanks in advance
from terraform-aws-notify-slack.
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.
from terraform-aws-notify-slack.
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 terraform-aws-modules
. Module arguments should always have plan types - string, list, map, bool, but not objects.
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 examples/notify-slack-simple
as possible) I can take another look.
from terraform-aws-notify-slack.
@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... terraform apply
this:
provider "aws" {
region = "eu-west-1"
}
resource "aws_sns_topic" "bogus_sns" {
name = "some-bogus-sns-topic"
}
and then edit the file to be this and apply again:
provider "aws" {
region = "eu-west-1"
}
resource "aws_sns_topic" "my_sns" {
name = "my-sns"
}
module "notify_slack" {
source = "../../"
sns_topic_name = aws_sns_topic.my_sns.name
create_sns_topic = false
slack_webhook_url = "https://hooks.slack.com/services/AAA/BBB/CCC"
slack_channel = "aws-notification"
slack_username = "reporter"
tags = {
Name = "notify-slack-simple"
}
}
from terraform-aws-notify-slack.
@antonbabenko I've created a fairly straightforward PR to address the problem. Hopefully this helps clear things up.
from terraform-aws-notify-slack.
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.
data "aws_sns_topic" "this" {
name = var.sns_topic_name
depends_on = [
aws_sns_topic.this,
]
}
from terraform-aws-notify-slack.
Commenting to mention that I also ran into this issue
from terraform-aws-notify-slack.
Bump
from terraform-aws-notify-slack.
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.
from terraform-aws-notify-slack.
Related Issues (20)
- Noisy output HOT 4
- event to slack using event subscription HOT 1
- Noisy output HOT 4
- Support @here in Slack Notifications HOT 6
- lambda-runtime configurable HOT 3
- Make lambda logging level configurable HOT 3
- The link to the CloudWatch alarm is no longer valid. HOT 10
- SNS Feedback role is broken HOT 7
- Messages to slack are not delivered HOT 2
- Add formatting for Security Hub findings HOT 3
- Have a more descriptive Slack CloudTrail notification format HOT 3
- Apply fails when multiple module calls are used HOT 2
- Provider produced inconsistent final plan in CI/CD environment HOT 4
- AWS Lambda runtime python3.8 deprecation HOT 10
- SNS Feedback role is broken HOT 4
- Add formatter for Security Hub Findings HOT 4
- Add variable for Lambda Architecture to support ARM HOT 1
- Add formatter for Amazon Managed Prometheus alerts HOT 4
- Expected runtime expects Python 3.9 but locally using 3.11 HOT 1
- Lambda function isn't attaching to the specified VPC HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-aws-notify-slack.