You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The path to the key is not clear as the directory "03-basics/import-bootstrap/terraform.tfstate" does not exist during the aws bootstrap process:
terraform {
#############################################################
## AFTER RUNNING TERRAFORM APPLY (WITH LOCAL BACKEND)
## YOU WILL UNCOMMENT THIS CODE THEN RERUN TERRAFORM INIT
## TO SWITCH FROM LOCAL BACKEND TO REMOTE AWS BACKEND
#############################################################
# backend "s3" {
# bucket = "devops-directive-tf-state" # REPLACE WITH YOUR BUCKET NAME
# key = "03-basics/import-bootstrap/terraform.tfstate"
# region = "us-east-1"
# dynamodb_table = "terraform-state-locking"
# encrypt = true
# }
...
If we use the locally stored terraform.tfstate file while in the path 03-basics/aws-backend we can successfully create the remote s3 backend:
03-basics/aws-backend/ $ cat main.tf
terraform {
#############################################################
## AFTER RUNNING TERRAFORM APPLY (WITH LOCAL BACKEND)
## YOU WILL UNCOMMENT THIS CODE THEN RERUN TERRAFORM INIT
## TO SWITCH FROM LOCAL BACKEND TO REMOTE AWS BACKEND
#############################################################
# backend "s3" {
# bucket = "devops-directive-tf-state" # REPLACE WITH YOUR BUCKET NAME
# key = "terraform.tfstate"
# region = "us-east-1"
# dynamodb_table = "terraform-state-locking"
# encrypt = true
# }
...
03-basics/aws-backend/ $ terraform init
03-basics/aws-backend/ $ terraform plan
03-basics/aws-backend/ $ terraform apply
# This works!
Then the problem is how to use the aws-backend terraform.tfstate in the web-app terrform config? Doing terrform init and terrform plan with the following config while in the 03-basics/web-app directory shows that it will end up deleting the backend resources:
03-basics/web-app/ $ cat main.tf
terraform {
# assuems that the bootstapping process has been done already
# bootstrapping with done in 03-basics/aws-bootstrap
backend "s3" {
bucket = "rafay-tf-state-bucket"
key = "terraform.tfstate" # in the code the actual value is "03-basics/web-app/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-state-locking"
encrypt = true
}
...
The path to the key is not clear as the directory
"03-basics/import-bootstrap/terraform.tfstate"
does not exist during the aws bootstrap process:If we use the locally stored
terraform.tfstate
file while in the path03-basics/aws-backend
we can successfully create the remote s3 backend:Then the problem is how to use the aws-backend
terraform.tfstate
in theweb-app
terrform config? Doingterrform init
andterrform plan
with the following config while in the03-basics/web-app
directory shows that it will end up deleting the backend resources:plan
outputThe text was updated successfully, but these errors were encountered: