我是Terraform的新手,正在尝试创建一个AWS SNS主题和订阅。我的代码如下所示:
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}"
}
Run Code Online (Sandbox Code Playgroud)
但是,运行时出现以下错误输出terraform apply:
Error: aws_sns_topic_subscription.code_commit_notification: resource depends on
non-existent resource '${aws_sns_topic.sns_my_topic}'
在添加depends on上面的代码块之前,我也收到了同样的错误(并且在阅读https://github.com/hashicorp/terraform/issues/10462之后,还将其从模块中移出了)。使Terraform处理这些的正确方法是什么?