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
-**Security**: The sa_key.json file contains sensitive credentials and should never be committed to version control
93
93
-**State Management**: Consider using remote state storage for team environments
94
94
95
+
## Using the bucket as a Terraform S3 backend (optional)
96
+
97
+
If you want Terraform state to be stored in the object storage bucket, add a backend block to your root module.
98
+
Note: backend blocks cannot reference resources, so you must hardcode or pass the values via variables/partials.
99
+
100
+
### Bootstrap script (recommended)
101
+
102
+
Note: `backend "s3" {}` is already defined in `main.tf`. The bootstrap step still works because it runs `terraform init -backend=false`, which ignores the backend block.
103
+
104
+
Use the helper script to bootstrap the backend in two phases:
105
+
1) Run a local-only apply to create the bucket + credentials.
106
+
2) Generate `.backend.hcl` and migrate state to S3.
107
+
108
+
```bash
109
+
./scripts/init-backend.sh
110
+
```
111
+
112
+
This writes `infrastructure/terraform/.backend.hcl` (contains credentials) and runs `terraform init -force-copy`.
113
+
You can re-run the script at any time; it reuses the existing backend config if present.
114
+
If you want remote state from the start, run this script before your first full `terraform apply`.
0 commit comments