| .. | ||
| scripts | ||
| .terraform.lock.hcl | ||
| 000-variables.tf | ||
| 010-backend.tf | ||
| 020-provider.tf | ||
| 030-project.tf | ||
| backend.conf.example | ||
| README.md | ||
| terraform.tfvars.example | ||
Phase 1: Example Infrastructure
This module contains the core infrastructure configuration. It uses the pg backend to store state and enforce state locks via the STACKIT PostgreSQL Flex database provisioned in Phase 0.
Implementation Steps
-
Create a
backend.conffile in this directory and define the connection string using the credentials generated by the bootstrap module:conn_str = "postgres://tf_state_user:<PASSWORD>@<STACKIT_INSTANCE_HOST>:5432/terraform_state?sslmode=require" -
Initialize Terraform and bind it to the remote PostgreSQL backend
terraform init -backend-config=backend.conf -
Provision the infrastructure or run the lock validation script:
chmod +x ./scripts/validate_lock.sh ./scripts/validate_lock.sh
Log Output
➜ 01-example-project ~ ./scripts/test-state-lock.sh
[INFO] Initiating background 'terraform apply' to acquire the state lock...
[INFO] Attempting concurrent 'terraform plan'...
[INFO] ------------------------------------------------------------------
╷
│ Error: Error acquiring the state lock
│
│ Error message: Already locked for workspace creation: default
│ Lock Info:
│ ID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXXXXX
│ Path:
│ Operation: OperationTypePlan
│ Who: XXXX
│ Version: 1.14.9
│ Created: 2026-06-25 16:21:59.636986 +0000 UTC
│ Info:
│
│
│ Terraform acquires a state lock to protect the state from being written
│ by multiple users at the same time. Please resolve the issue above and try
│ again. For most commands, you can disable locking with the "-lock=false"
│ flag, but this is not recommended.
╵
[INFO] ------------------------------------------------------------------
[SUCCESS] Concurrent operation rejected. State locking is active and functional.
[INFO] Waiting for the background 'terraform apply' process to terminate...
[INFO] Evaluation complete. Cleaning up temporary logs...