2017-06-06 293 views
1

我有一個terraform計劃,它由多個aws_sqs_queue資源組成,它們更少或更少共享相同的配置。在我刪除任何重複的配置並使用變量之前,我想運行terraform plan以查看它是否有效。但我一直碰到 -Terraform - 資源重複多次

module root: 1 error(s) occurred: 

* data.template_file.ep_match_result_queues: resource repeated multiple times 

我試過Google搜索,但沒有太多的信息可用。任何幫助都感激不盡。我的計劃是這樣的:(忽略多餘的括號,錯別字,因爲這僅僅是一個框架給你一個總體思路的計劃是如何sturctured):

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 
} 

回答

2

我認爲錯誤意味着您已聲明與資源相同的名稱不止一次,這是在同一個tf文件或另一個tf文件中您正在運行terraform的同一目錄中。

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

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