All technological notes.
backend
terraform.tfstate file is stored and how state locking is handled.local: stores state as a local file on disk.terraform {
backend "local" {}
}
remote backend
terraform.tfstate fileterraform {
backend "s3" {
bucket = ""
key = ""
region = ""
}
}
terraform init -backend-config# key/value pairs
terraform init -backend-config="bucket=mybucket" \
-backend-config="key=mykey"
-backend-config="region=myregion"
# for dev
terraform init -backend-config=dev.config
# for test
terraform init -backend-config=test.config
# for prod
terraform init -backend-config=prod.config
provider.tfterraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
# Configuring a remote backend
backend "s3" {
bucket = ""
region = ""
key = ""
dynamodb_table = "" # backend lock in dynamodb
}
}
state.config# state.config
bucket = "your-bucket"
key = "your-state.tfstate"
region = "eu-central-1"
profile= "Your_Profile"
`terraform init -backend-config="./state.config"`
# cli
terraform init \
-backend-config="address=demo.consul.io" \
-backend-config="path=example_app/terraform_state" \
-backend-config="scheme=https"
data "terraform_remote_state" "network" {
backend = "s3"
config = {
bucket = "terraform-state-prod"
key = "network/terraform.tfstate"
region = "us-east-1"
}
}