Terraform project structure

Terraform project structure

Explorer

  • .devcontainernew
  • devcontainer.jsonnew
  • .vscode
  • extensions.json
  • settings.jsonnew
  • bootstrapnew
  • main.tfnew
  • terraform.tfnew
  • outputs.tfnew
  • .terraform.lock.hclnew
  • README.mdnew
  • environments
  • modulesnew
  • README.mdnew
  • .editorconfignew
  • .gitignore
  • .pre-commit-config.yamlnew
  • .terraform-versionnew
  • .tflint.hclnew
  • Makefilenew
  • README.md
  1. # Pin the Terraform version for everyone (tfenv, mise and setup-terraform read it)

    echo "1.16.5" > .terraform-version
  2. # Download providers and write the lock file

    cd environments/dev && terraform init
  3. # Format and validate

    terraform fmt -recursive && terraform validate
  4. # See what would change, then apply it

    terraform plan -out=tfplan && terraform apply tfplan
  5. # Move local state into the S3 backend once backend.tf exists

    terraform init -migrate-state
  6. # Lint and run module tests

    tflint --init && tflint --recursive && terraform -chdir=modules/network test
  7. # Scan for insecure settings

    trivy config . && checkov -d .
  8. # Install the Git hooks once per clone

    pre-commit install
  9. # Same steps with OpenTofu instead (the commands mirror terraform)

    tofu init && tofu plan