Skip to content

Commit

Permalink
#46 Remove data resource for sns topic to avoid race condition
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bushong1 committed Apr 29, 2020
1 parent 7db29f9 commit 3b4c166
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
data "aws_sns_topic" "this" {
count = false == var.create_sns_topic && var.create ? 1 : 0

name = var.sns_topic_name
}
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}

resource "aws_sns_topic" "this" {
count = var.create_sns_topic && var.create ? 1 : 0
Expand All @@ -15,9 +12,8 @@ resource "aws_sns_topic" "this" {
locals {
sns_topic_arn = element(
concat(
aws_sns_topic.this.*.arn,
data.aws_sns_topic.this.*.arn,
[""],
aws_sns_topic.this.*.id,
["arn:aws:sns:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${var.sns_topic_name}"],
),
0,
)
Expand Down

0 comments on commit 3b4c166

Please sign in to comment.