无法在地形版本4.5.0中为多个aws s3添加version_configuration



尝试使用以下提供的代码使用Terraform创建多个AWS s3存储桶。提供商版本:4.5.0

尝试不使用count功能,同时使用for_each功能和

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存储桶,但只尝试创建一个存储桶版本控制配置。您正在bucket版本控制资源中引用一个count变量,但尚未为该资源声明count属性。

您需要在bucket版本控制资源上声明count,就像您对s3 bucket资源所做的那样。

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

相关内容

  • 没有找到相关文章

最新更新