如何使用Terraform创建S3生命周期配置



我尝试在S3生命周期中使用newer_noncurrent_versions。

在Terraform 4.3.0中,发布了生命周期。

然而,在Terraform云上应用时,出现了一个错误,说要使用Lifecycle V2。

我的代码有问题吗?这是地形提供者的问题吗?

Terraform CLI和Terraform AWS提供程序版本

Terraform v1.1.5
on darwin_amd64

Terraform配置文件

resource "aws_s3_bucket_lifecycle_configuration" "s3" {
bucket = "aws-test-bucket"
rule {
id     = "rule"
status = "Enabled"
noncurrent_version_expiration {
noncurrent_days                  = 1
newer_noncurrent_versions = 2
}
}
}

实际行为

  • 当我在本地运行terrafrom plan时,它似乎创建得很好
+ resource "aws_s3_bucket_lifecycle_configuration" "s3" {
+ bucket = (known after apply)
+ id     = (known after apply)
+ rule {
+ id     = "rule"
+ status = "Enabled"
+ noncurrent_version_expiration {
+ newer_noncurrent_versions = 2
+ noncurrent_days                  = 1
}
}
}

但是,在Terraform Cloud中应用时,会出现以下错误

Error: error creating S3 Lifecycle Configuration for bucket (aws-test-bucket): InvalidRequest: 
NewerNoncurrentVersions element can only be used in Lifecycle V2. 
status code: 400, with aws_s3_bucket_lifecycle_configuration.s3
on s3.tf line 66, in resource "aws_s3_bucket_lifecycle_configuration" "s3":

您在规则中缺少filter

resource "aws_s3_bucket_lifecycle_configuration" "s3" {
bucket = "aws-test-bucket"
rule {
id     = "rule"
status = "Enabled"

filter {} 
noncurrent_version_expiration {
noncurrent_days                  = 1
newer_noncurrent_versions = 2
}
}

}

相关内容

  • 没有找到相关文章

最新更新