I am currently reading the book called "Terraform-up-and-learning 2nd edition"
In the section introducing setting state file remotely, I faced a trouble.
this is the code that I ran.
terraform {
backend "s3" {
bucket = "my-state"
key = "workspaces-example/terraform.tfstate"
region = "ap-southeast-1"
dynamodb_table = "my-lock"
encrypt = true
}
}
provider "aws" {
region = "ap-southeast-1"
profile = "my-test"
}
resource "aws_instance" "example" {
ami = "ami-02045ebddb047018b"
instance_type = "t2.micro"
}
prior to running this code, I made s3 and DDB using my AWS console by hand. And
terraform init
terraform plan
works well.
But I can't find any state file in my AWS console. Following the book, the state file should be in "my-state" s3.
In addition, I can't find any statefile in my local too.
CodePudding user response:
The state file goes to the backend after you run terraform apply
.
After that, when you run terraform init
again it will look for the remote state file.
In your case, your plan does show the changes list but it did not output any files. You have to apply now.
manual approval -
terraform apply
auto -
terraform apply -auto-approve
Remember to destroy after playing around to save costs. Run
terraform destroy
Best wishes.