Solving resource dependency in Terraform


I’m new to Terraform and I’m trying to create an AWS SNS topic and subscription. My code looks like the following:

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 What is the proper way to get Terraform to process these?


As mentioned in the comments, this looks like a syntax issue.

It should be:

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.

Leave a Reply