I tried to use newer_noncurrent_versions in S3 Lifecycle.
In Terraform 4.3.0, lifecycle was released.
However, when applying on Terraform cloud, an error saying to use Lifecycle V2 occurred.
Is my code the problem? Is it a terraform provider problem?
Terraform CLI and Terraform AWS Provider Version
Terraform v1.1.5
on darwin_amd64
Terraform Configuration Files
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
}
}
}
Actual Behavior
- When I run
terrafrom plan
on local, it seems to be created just fine.
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
}
}
}
However, when applying in Terraform Cloud, the following error occurs.
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":
CodePudding user response:
Your are missing filter
in the rule:
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
}
}
}