Can't configure a value for "lifecycle_rule": its value will be decided automatically based on the result of applying this configuration

aws Habibur Rhoman Joy

Problem:

When I run "terraform apply" then got this error message - 

Can't configure a value for "lifecycle_rule": its value will be decided automatically based on the result of applying this configuration

Solution 1:

Terraform AWS Provider is upgraded to version 4.0.0 which is published on 10 February 2022.

Major changes in the release include:

  • Version 4.0.0 of the AWS Provider introduces significant changes to the aws_s3_bucket resource.
  • Version 4.0.0 of the AWS Provider will be the last major version to support EC2-Classic resources as AWS plans to fully retire EC2-Classic Networking. See the AWS News Blog for additional details.
  • Version 4.0.0 and 4.x.x versions of the AWS Provider will be the last versions compatible with Terraform 0.12-0.15.

The reason for this change by Terraform is as follows: To help distribute the management of S3 bucket settings via independent resources, various arguments and attributes in the aws_s3_bucket resource have become read-only. Configurations dependent on these arguments should be updated to use the corresponding aws_s3_bucket_* resource. Once updated, new aws_s3_bucket_* resources should be imported into Terraform state.

So, I updated my code accordingly by following the guide here: Terraform AWS Provider Version 4 Upgrade Guide | S3 Bucket Refactor


Solution 2:

If you can't upgrade your version maybe you could lock your AWS provider version like this:

terraform {

  required_version = "~> 0.12.31"

  required_providers {
    aws  = "~> 3.74.1"
  }
}

Thank you for reading the article. If you face any problem please comment below.