I'm new to Terraform and I'm trying to create an AWS SNS topic and subscription. My code looks like the following:
provider "aws" {
region = "${var.aws_region}"
}
resource "aws_sns_topic" "sns_my_topic" {
name = "${var.sns_topic_name}"
}
resource "aws_sns_topic_subscription" "code_commit_notification" {
depends_on = ["${aws_sns_topic.sns_my_topic}"]
topic_arn = "${aws_sns_topic.sns_my_topic.arn}"
protocol = "email"
endpoint = "${var.sns_subscribe_endpoint}"
}
However, I get the following error output when running terraform apply:
Error: aws_sns_topic_subscription.code_commit_notification: resource depends on
non-existent resource '${aws_sns_topic.sns_my_topic}'
I was receiving the same error before adding the depends on block above as well (and also moved it out of a module after reading https://github.com/hashicorp/terraform/issues/10462). What is the proper way to get Terraform to process these?
depends_on = ["aws_sns_topic.sns_my_topic"](without ${} brackets -depends_onsyntax is a little different from the rest). Still strange that you also get that error when you do not usedepends_on.