search by tags

for the user

adventures into the land of the command line

terraform remote backends

some terraform documentation about it here.
this example uses microsoft azure blob storage as the location for the remote backend.

★ tree
.
├── README.md
├── modules
│   ├── my_app
│   │   ├── provider.tf
│   │   ├── main.tf
│   │   └── variables.tf
├── prod
│   ├── backend.tf  <---------- this one
│   └── main.tf


> prod/backend.tf

terraform {
  backend "azurerm" {
    storage_account_name = "my_storage_account"
    container_name       = "my_folder_or_blob_name"
    key                  = "the_file_name"
    resource_group_name  = "blah"
    arm_subscription_id  = "xxxEXAMPLE"
    arm_client_id        = "xxxEXAMPLE"
    arm_tenant_id        = "xxxEXAMPLE"
  }
}


★ terraform init -backend-config "arm_client_secret=xxxEXAMPLE"

things to remember:
• a remote backend functions as a single point of truth in a system where the repo can exist in multiple places at once.
• when working in a team, a remote backend will help to ensure everyone has the latest version of the terraform state.
• you must remember to always run terraform init before running a terraform plan/apply in order to sync your local stuff with the remote state.

after running terraform init, the file in the blob on the remote cloud storage will contain the same state contents as appears in your local .terraform/terraform.tfstate file

├── prod
│   ├── .terraform
│   │   └── terraform.tfstate <-------------- this guy
│   ├── backend.tf
│   └── main.tf

terraform i ❤︎ u