Open3

terraformを触るときに使うコマンドを整理する

anfangdanfangd
  • terraform init
  • terraorm fmt
  • terraform validate
  • tflint
  • terraform plan
  • terraform apply
  • terraform destroy
anfangdanfangd

pre-commit-terraform

VCSへのコミットをする前に Terraform や OpenTofu 、 Terragrant のコードを自動でチェックし、フォーマットしてくれるツール。

Install dependencies

brew install pre-commit terraform-docs tflint tfsec trivy checkov terrascan infracost tfupdate minamijoyo/hcledit/hcledit jq

Install the pre-commit hook globally

DIR=~/.git-template
git config --global init.templateDir ${DIR}
pre-commit init-templatedir -t pre-commit ${DIR}

Add configs and hooks

git init
cat <<EOF > .pre-commit-config.yaml
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
  rev: v1.97.4 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
  hooks:
    - id: terraform_fmt
    - id: terraform_docs
EOF

Run

pre-commit run -a