Junior — Middle
How can Amazon S3 be configured for storing Terraform state files?
sobes.tech AI
Answer from AI
To store Terraform state files in Amazon S3, you need to perform the following steps:
- Create an S3 bucket with a unique name.
- Configure access permissions (IAM policies) so that Terraform can read and write to this bucket.
- Optionally enable versioning on the bucket to keep a history of states.
- In your Terraform configuration, specify the backend of type
s3with the bucket parameters.
Example backend configuration in the terraform {} file:
terraform {
backend "s3" {
bucket = "my-terraform-state-bucket"
key = "path/to/my/terraform.tfstate"
region = "us-east-1"
}
}
After this, during initialization (terraform init), the state will be saved and loaded from the specified S3 bucket.