← All insightsSecurity

Securing Terraform: least privilege and safe defaults

CodeWizard Engineering · 17 August 2026 · 3 min read · Advanced

Security with Terraform is mostly correct, boring defaults applied consistently. Here is the short list that removes most of the risk.

Safe defaults

  • Scan with tfsec/Checkov in CI to catch open security groups and public buckets
  • Pull secrets from Vault/SSM at apply time instead of committing them
  • Restrict the CI role with least-privilege IAM for the apply step

Wire it into the pipeline

Plan on every PR, apply only on main.

yaml
plan:
  stage: test
  script:
    - terraform init -input=false
    - terraform plan -input=false -out=tfplan
apply:
  stage: deploy
  script: terraform apply -input=false -auto-approve tfplan
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'

Reinforcing habits

  • Remote, locked state; separate state per environment/component
  • Pin provider and module versions; commit .terraform.lock.hcl
  • Keep modules small and composable; review plans in the PR

Want senior help putting Terraform to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult