簡體   English   中英

為sqs及其訪問策略創建terraform代碼時出現循環錯誤

[英]cycle error when creating terraform code for sqs and its access policy

我嘗試創建 sqs 隊列並將訪問策略附加到它,策略是“數據”類型 - 沒有創建實際資源,它只是附加到新創建的 sqs 隊列。

╷
│ Error: Cycle: data.aws_iam_policy_document.sqs_vote_policy, aws_sqs_queue.sqs_vote
│

tf 代碼:

resource "aws_sqs_queue" "sqs_vote" {
  name                      = "sqs-erjan"
  delay_seconds             = 0
  message_retention_seconds = 86400
  receive_wait_time_seconds = 0
  policy                    = data.aws_iam_policy_document.sqs_vote_policy.json



}


data "aws_iam_policy_document" "sqs_vote_policy" {
  policy_id = "__default_policy_ID"

  statement {
    sid       = "__console_sub_0"
    actions   = ["SQS:SendMessage"]
    resources = [aws_sqs_queue.sqs_vote.arn]
    principals {
      type        = "AWS"
      identifiers = ["*"]
    }
    effect = "Allow"

    condition {
      test     = "ArnLike"
      variable = "AWS:SourceArn"

      values = [
        aws_sns_topic.vote_sns.arn
      ]
    }

  }

  statement {
    sid       = "__owner_statement"
    actions   = ["SQS:*"]
    resources = [aws_sqs_queue.sqs_vote.arn]
    principals {
      type        = "arn:aws:iam::025416187662:root"
      identifiers = ["*"]
    }
    effect = "Allow"

  }

  # i put depends on to make sure it runs first - but it still gives cycle error
  depends_on = [
    aws_sqs_queue.sqs_vote,aws_sns_topic.vote_sns
  ]

}

如何解決?

aws_sqs_queue更改為:

resource "aws_sqs_queue" "sqs_vote" {
  name                      = "sqs-erjan"
  delay_seconds             = 0
  message_retention_seconds = 86400
  receive_wait_time_seconds = 0
}

並使用aws_sqs_queue_policy將策略附加到隊列:

resource "aws_sqs_queue_policy" "test" {
  queue_url = aws_sqs_queue.sqs_vote.id
  policy = data.aws_iam_policy_document.sqs_vote_policy.json
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM