Skip to content

init-terraform.sh dev prompts for an S3 bucket instead of using local state #60

Description

@7174Andy

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:

  1. 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.

  2. 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

  1. 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.
  2. 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.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions