Summary
scripts/init-terraform.sh dev cannot work. It is documented as using local state, but the repo has no way to produce local state, so the command prompts for an S3 bucket name and then fails.
Reproduction
On a clean checkout (no .terraform/, no terraform.tfstate), with stdin closed as in any non-interactive shell:
$ cd lablink-infrastructure && ../scripts/init-terraform.sh dev
Initializing Terraform for dev environment (local state)
Initializing the backend...
bucket
The name of the S3 bucket
Enter a value:
╷
│ Error: Error asking for input to configure backend "s3": bucket: EOF
╵
exit=1
No ./terraform.tfstate is created. In an interactive terminal it does not fail outright — it stops and prompts the operator for a bucket, which is equally not the documented behaviour.
Reproduced with Terraform v1.9.6 against main (57cfb9b). No AWS credentials are involved: backend configuration is validated before any network call.
Cause
Two things combine:
-
backend-dev.hcl contains no configuration. Every line is a comment. It advertises:
# Uses local state file for rapid development and testing
# No S3 bucket or DynamoDB table required
# State stored in: ./terraform.tfstate
but supplies no bucket, key, or any other setting.
-
backend.tf hardcodes the S3 backend unconditionally:
terraform {
required_version = ">= 1.9.0, < 2.0.0"
backend "s3" {}
}
There is no way to select local state without editing this file, and nothing in the repo does.
So init-terraform.sh's dev branch —
if [ "$ENVIRONMENT" = "dev" ]; then
echo "Initializing Terraform for dev environment (local state)"
terraform init -backend-config=backend-dev.hcl
— hands an empty backend config to an S3 backend that still requires bucket and key.
The other environments are unaffected: backend-{test,prod,ci-test}.hcl each set a real key, and the script passes bucket and region from config.yaml for those.
Impact
Low severity but user-facing: dev is the environment a newcomer is most likely to try first, and the failure mode ("Enter a value:" for a bucket the docs said was not required) is confusing rather than self-explanatory. The dev usage instructions are repeated in backend-dev.hcl's own header comment, so the docs actively point at it.
Options
- Make dev genuinely local. Requires removing the unconditional
backend "s3" {} from backend.tf — e.g. a separate dev overlay directory, or a documented -backend=false flow. Most faithful to the documented intent, biggest change.
- Give dev an S3 backend like the others. Add
key = "dev/terraform.tfstate" to backend-dev.hcl and let the script pass bucket/region as it does for other environments. Smallest change; drops the "no S3 required" promise.
- Drop
dev. Remove the special case from init-terraform.sh, delete backend-dev.hcl, and remove dev from the docs. environment still accepts dev in main.tf's validation, so that would need to narrow too.
Whichever is chosen, backend-dev.hcl's header comment and the README's dev instructions need to match the result.
Related
Summary
scripts/init-terraform.sh devcannot work. It is documented as using local state, but the repo has no way to produce local state, so the command prompts for an S3 bucket name and then fails.Reproduction
On a clean checkout (no
.terraform/, noterraform.tfstate), with stdin closed as in any non-interactive shell:No
./terraform.tfstateis created. In an interactive terminal it does not fail outright — it stops and prompts the operator for a bucket, which is equally not the documented behaviour.Reproduced with Terraform v1.9.6 against
main(57cfb9b). No AWS credentials are involved: backend configuration is validated before any network call.Cause
Two things combine:
backend-dev.hclcontains no configuration. Every line is a comment. It advertises:but supplies no
bucket,key, or any other setting.backend.tfhardcodes the S3 backend unconditionally:There is no way to select local state without editing this file, and nothing in the repo does.
So
init-terraform.sh's dev branch —— hands an empty backend config to an S3 backend that still requires
bucketandkey.The other environments are unaffected:
backend-{test,prod,ci-test}.hcleach set a realkey, and the script passesbucketandregionfromconfig.yamlfor those.Impact
Low severity but user-facing:
devis the environment a newcomer is most likely to try first, and the failure mode ("Enter a value:" for a bucket the docs said was not required) is confusing rather than self-explanatory. The dev usage instructions are repeated inbackend-dev.hcl's own header comment, so the docs actively point at it.Options
backend "s3" {}frombackend.tf— e.g. a separate dev overlay directory, or a documented-backend=falseflow. Most faithful to the documented intent, biggest change.key = "dev/terraform.tfstate"tobackend-dev.hcland let the script pass bucket/region as it does for other environments. Smallest change; drops the "no S3 required" promise.dev. Remove the special case frominit-terraform.sh, deletebackend-dev.hcl, and remove dev from the docs.environmentstill acceptsdevinmain.tf's validation, so that would need to narrow too.Whichever is chosen,
backend-dev.hcl's header comment and the README's dev instructions need to match the result.Related
lablink deploy --templatefor local deploys of a template repo lablink#444 —lablink deploy --template, which will reuseinit-terraform.sh's backend scheme and should skip or specially handledevuntil this is resolved.