In order to have the state of you terraform in a remote place let say at AWS S3 you need to :
- You need to create the bucket at AWS S3 using terraform
- you need to add backend to indicate that you will use the bucket created to store the terraform state (encryting it)
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "terraform_state" {
bucket = "${var.bucket_name}"
versioning {
enabled = true
}
lifecycle {
prevent_destroy = true
}
}
terraform {
backend "s3" {
bucket = "lokisha-s3"
region = "us-east-1"
key = "terraform.tfstate"
encrypt = true
}
}
Sometimes when you run terraform plan
you will start watching the next error:
Error: Error asking for user input: 1 error(s) occurred:
* provider.aws: fork/exec /Users/loko/Workspace/TerraformLabs/terraform-up-and-running-code/code/terraform/03-terraform-state/file-layout-example/prod/data-stores/mysql/.terraform/plugins/darwin_amd64/terraform-provider-aws_v1.11.0_x4: permission denied
In order to fix that issue related with the plugin permissions, try
- The provider binary needs execute permissions, so try using 755
- at you current terraform module or resource (using Mac)
chmod 755 .terraform/plugins/darwin_amd64/terraform-provider-aws_v1.11.0_x4
- Then try
terraform init
andterraform plan
it should be fixec