[英]Using aws_s3_bucket_cors_configuration for multiple cors_rules with terraform aws provider version 4
[英]Unable to add versioning_configuration for multiple aws s3 in terraform version 4.5.0
嘗試使用 Terraform 和下面提供的代碼創建多個 AWS s3 存儲桶。 提供商版本:4.5.0
沒有count
function 也嘗試過for_each
function
resource "aws_s3_bucket" "public_bucket" {
count = "${length(var.public_bucket_names)}"
bucket = "${var.public_bucket_names[count.index]}"
# acceleration_status = var.public_bucket_acceleration
tags = {
ProjectName = "${var.project_name}"
Environment = "${var.env_suffix}"
}
}
resource "aws_s3_bucket_versioning" "public_bucket_versioning" {
bucket = aws_s3_bucket.public_bucket[count.index].id
versioning_configuration {
status = "Enabled"
}
}
面臨以下錯誤
Error: Reference to "count" in non-counted context
│
│ on modules/S3-Public/s3-public.tf line 24, in resource "aws_s3_bucket_versioning" "public_bucket_versioning":
│ 24: bucket = aws_s3_bucket.public_bucket[count.index].id
│
│ The "count" object can only be used in "module", "resource", and "data" blocks, and only when the "count" argument is set.
您當前的代碼創建多個 S3 存儲桶,但僅嘗試創建單個存儲桶版本控制配置。 您正在引用存儲桶版本控制資源中的count
變量,但您尚未為該資源聲明count
屬性。
您需要聲明對存儲桶版本控制資源的count
,就像您對 s3 存儲桶資源所做的那樣。
resource "aws_s3_bucket_versioning" "public_bucket_versioning" {
count = "${length(var.public_bucket_names)}"
bucket = aws_s3_bucket.public_bucket[count.index].id
versioning_configuration {
status = "Enabled"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.