我有一个由多个aws_sqs_queue
资源组成的terraform计划,其中更多的资源共享相同的配置。在删除任何重复配置并使用变量之前,我想运行terraform plan
以查看它是否有效。但是我一直在努力 -
module root: 1 error(s) occurred:
* data.template_file.ep_match_result_queues: resource repeated multiple times
我试过谷歌搜索,但没有太多可用的信息。任何帮助都感激不尽。我的计划看起来像这样:(忽略额外的大括号,拼写错误,因为这只是一个骨架,可以让您大致了解该计划是如何构建的):
data "template_file" "ep_match_result_queues" {
template = "${var.namespace}-sm-ep"
}
resource "aws_sns_topic" "sns_topic_name" {
name = "ep_sm_match_result_topic${var.environment}"
display_name = ""
policy = <<POLICY
{
#policy
}
resource "aws_sqs_queue" "queue1" {
#config
}
resource "aws_sqs_queue" "queue2" {
#config
redrive_policy = <<POLICY
{
#policy
}
POLICY
}
resource "aws_sqs_queue" "queue3" {
#config
}
resource "aws_sqs_queue" "queue4" {
#config
redrive_policy = <<POLICY
{
#policy
}
POLICY
}
resource "aws_sqs_queue" "queue5" {
#config
}
resource "aws_sqs_queue" "queue6" {
#config
redrive_policy = <<POLICY
{
#policy
}
POLICY
}
resource "aws_sqs_queue" "queue7" {
#config
}
resource "aws_sqs_queue" "queue8" {
#config
redrive_policy = <<POLICY
{
#policy
}
POLICY
}
resource "aws_sqs_queue_policy" "queue_policy" {
queue_url = [ ... ]
policy = "${data.aws_iam_policy_document.match_result_queues_policy.json}"
}
data "aws_iam_policy_document" "match_result_queues_policy" {
#policy
}
答案 0 :(得分:6)
我认为该错误意味着您已多次声明具有相同名称的资源,该资源位于同一个tf文件中或您运行terraform的同一目录中的另一个tf文件中。
答案 1 :(得分:0)
您可以使用变量指定所需的数量,然后将其添加到队列的名称中。
resource "aws_sqs_queue" "terraform_queue" {
count = "${var.queue_count}"
name = "terraform-example-queue-${count.index}"
delay_seconds = 90
max_message_size = 2048
message_retention_seconds = 86400
receive_wait_time_seconds = 10
redrive_policy = "{\"deadLetterTargetArn\":\"${aws_sqs_queue.terraform_queue_deadletter.arn}\",\"maxReceiveCount\":4}"
}