How to Configure GCS and azurerm Remote State in CI
The gcs and azurerm backends store state in a bucket or blob container and lock natively, so no extra lock table is required.
Use a gcs backend for Google Cloud or an azurerm backend for Azure. Both lock state without a companion table: GCS uses object generations and azurerm uses a blob lease.
gcs backend
main.tf
terraform {
backend "gcs" {
bucket = "acme-tf-state"
prefix = "prod/app"
}
}azurerm backend
main.tf
terraform {
backend "azurerm" {
resource_group_name = "tf-state-rg"
storage_account_name = "acmetfstate"
container_name = "tfstate"
key = "prod/app.tfstate"
}
}Gotchas
- Enable object versioning on the GCS bucket so you can recover a clobbered state.
- The azurerm backend holds a blob lease for the run; a killed job can leave a lease that must be broken.
Related guides
How to Authenticate Terraform to GCP and Azure With OIDCFederate GitHub Actions into GCP Workload Identity or Azure with OIDC so Terraform gets short-lived credentia…
How to Configure S3 and DynamoDB Remote State in CIStore Terraform state in an S3 backend with DynamoDB state locking so concurrent CI runs cannot corrupt state…