Terraform - 资源重复多次

Terraform - resource repeated multiple times

我有一个 terraform 计划,其中包含多个 aws_sqs_queue 资源,这些资源或多或少共享相同的配置。在删除任何重复配置并使用变量之前,我想 运行 terraform plan 看看它是否有效。但是我一直 运行ning 进入 -

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
}

我认为这个错误意味着你不止一次声明了同名资源,它在同一个 tf 文件中,或者在你所在的同一目录中的另一个 tf 文件中 运行 terraform。

您可以使用一个变量来指定您想要的数量,然后将其添加到队列的名称中。

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}"
}

https://www.terraform.io/intro/examples/count.html