Question:
I’m new to Terraform and I’m trying to create an AWS SNS topic and subscription. My code looks like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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?
Answer:
As mentioned in the comments, this looks like a syntax issue.
It should be:
1 2 3 4 5 6 |
resource "aws_sns_topic_subscription" "code_commit_notification" { depends_on = ["aws_sns_topic.sns_my_topic"] ... } |
The depends_on
syntax is a little different from the rest and does not require ${}
brackets around the referenced resource variables. It is still a little strange to me that you are receiving the same error without depends_on
.