{"id":15155652,"url":"https://github.com/ksatirli/code-quality-for-terraform","last_synced_at":"2025-09-30T04:31:47.163Z","repository":{"id":89714028,"uuid":"282160510","full_name":"ksatirli/code-quality-for-terraform","owner":"ksatirli","description":"🎤 local and remote code-quality options for HashiCorp Terraform","archived":true,"fork":false,"pushed_at":"2021-02-11T13:58:20.000Z","size":858,"stargazers_count":18,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-27T18:41:45.078Z","etag":null,"topics":["code-quality","github-actions","hashicorp","hashicorp-terraform","linting","pre-commit","terraform","tflint"],"latest_commit_sha":null,"homepage":"https://speakerdeck.com/ksatirli/code-quality-for-terraform","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ksatirli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-24T08:04:48.000Z","updated_at":"2024-05-28T09:32:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"26f2530e-7f12-427d-999f-bd6485b4d78f","html_url":"https://github.com/ksatirli/code-quality-for-terraform","commit_stats":{"total_commits":7,"total_committers":2,"mean_commits":3.5,"dds":0.4285714285714286,"last_synced_commit":"e61a3aaec8a4a97314ad0ad6acd812dd13d97150"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksatirli%2Fcode-quality-for-terraform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksatirli%2Fcode-quality-for-terraform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksatirli%2Fcode-quality-for-terraform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksatirli%2Fcode-quality-for-terraform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ksatirli","download_url":"https://codeload.github.com/ksatirli/code-quality-for-terraform/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234702032,"owners_count":18873820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-quality","github-actions","hashicorp","hashicorp-terraform","linting","pre-commit","terraform","tflint"],"created_at":"2024-09-26T18:41:45.310Z","updated_at":"2025-09-30T04:31:41.846Z","avatar_url":"https://github.com/ksatirli.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Code Quality for Terraform\n\n\u003e This repository contains low-quality Terraform code that uses the [Google Provider](https://www.terraform.io/docs/providers/google/index.html) to showcase a handful of ways of improving code hygiene and quality.\n\n## Table of Contents\n\n- [Code Quality for Terraform](#code-quality-for-terraform)\n  - [Table of Contents](#table-of-contents)\n  - [Important Links](#important-links)\n  - [Tools](#tools)\n  - [Usage](#usage)\n  - [Code Quality](#code-quality)\n    - [Using built-in tooling](#using-built-in-tooling)\n    - [Using pre-commit locally](#using-pre-commit-locally)\n    - [Using pre-commit via GitHub Actions](#using-pre-commit-via-github-actions)\n    - [Using TFLint](#using-tflint)\n    - [Using GitHub Actions](#using-github-actions)\n  - [Notes](#notes)\n  - [Author Information](#author-information)\n  - [License](#license)\n\n## Important Links\n\n- Slides: [speakerdeck.com/ksatirli/code-quality-for-terraform](https://speakerdeck.com/ksatirli/code-quality-for-terraform)\n- Code: [github.com/ksatirli/code-quality-for-terraform](https://github.com/ksatirli/code-quality-for-terraform)\n\n### Tools\n\n- Local options:\n  - [terraform fmt](https://www.terraform.io/docs/commands/fmt.html)\n  - [terraform validate](https://www.terraform.io/docs/commands/validate.html)\n  - [TFLint](https://github.com/terraform-linters/tflint)\n  - [pre-commit](https://pre-commit.com)\n- Remote options:\n  - [GitHub Actions](https://github.com/features/actions)\n  - [GitHub Super-Linter](https://www.terraform.io/docs/github-actions/index.html)\n  - [Terraform GitHub Actions](https://www.terraform.io/docs/github-actions/index.html)\n\n## Usage\n\nStart by copying [terraform.tfvars.sample](https://github.com/ksatirli/code-quality-for-terraform/blob/main/terraform.tfvars.sample) to `terraform.tfvars` and fill in your GCP-specific information:\n\n```hcl\nproject_id     = \"my-project-identifier\" # replace with your GCP Project Identifier\nproject_domain = \"my-domain.com\"         # replace with your GCP Project Domain\n```\n\nThen, initialize the Terraform directory (`.terraform/`) by running `terraform init`:\n\n![CLI command: terraform init](images/terraform-init.gif)\n\nThis downloads the Google Provider for Terraform (as specified in [terraform.tf](https://github.com/ksatirli/code-quality-for-terraform/blob/main/terraform.tf)) and ensures you are running the correct Terraform version.\n\n## Code Quality\n\nTerraform projects rarely exist in isolation. A repository containing Terraform files (`.tf`) will often contain related files in one or more of the following formats:\n\n- HCL (`.hcl`)\n- JSON (`.json`)\n- Markdown (`.md` and `.mdx`)\n- Shell scripts (`.sh` and `.bash`)\n- YAML (`.yaml` and `.yml`)\n\nEnsuring proper code quality for _all_ files is important, as an uncaught error in one type of file may result in a Terraform Resources not being created, correctly.\n\nWhile it is outside the scope of this repository to advise you on linting rules for all the above files, you are encouraged to check out [@operatehappy/dotfiles-org](https://github.com/operatehappy/dotfiles-org) for a collection of code quality configurations that work _well_ with Terraform-adjacent code.\n\n### Using built-in tooling\n\nTerraform includes two very useful utilities to improve the quality of your code, without the need for external applications.\n\nTo format your code, using the canonical rules, use `terraform fmt`. Then, validate your code using `terraform validate`:\n\n![CLI command: terraform fmt and terraform validate](images/terraform-fmt-and-validate-good.gif)\n\n### Using `pre-commit` locally\n\nTo use `pre-commit` locally, follow the installation instructions on [pre-commit.com](https://pre-commit.com/#install) and then initialize your repository:\n\n![CLI command: pre-commit install](images/pre-commit-install.gif)\n\nThis will configure `.git/hooks/pre-commit` to reflect your local `pre-commit` installation.\n\nOn every commit, `git` (including GUI clients) will now run all checks listed in [.pre-commit-config.yaml](https://github.com/ksatirli/code-quality-for-terraform/blob/main/.pre-commit-config.yaml).\n\nNext to automated runs, it is possible to invoke these checks manually. For this, you can use `pre-commit run --all-files`:\n\n![CLI command: pre-commit run -all-files](images/pre-commit-run-bad.gif)\n\n### Using `pre-commit` via GitHub Actions\n\nIt is _possible_ to run `pre-commit` as part of [GitHub Actions](https://github.com/features/actions). This process is involved and requires the following:\n\n- access to `pre-commit` inside of GitHub Actions\n- a check-out of the code you want to run `pre-commit` against\n\nDepending on the `pre-commit` handlers you want to run, you will need to install various applications that are then used as part of `pre-commit`.\n\nA sample implementation of this process, including checking out an organization-wide `pre-commit` configuration can be found in [@operatehappy/terraform-aws-route53-workmail-records](https://github.com/operatehappy/terraform-aws-route53-workmail-records/blob/master/.github/workflows/code-quality.yml).\n\nA simpler (but just as powerful) approach to running a large amount of linters remotely is to use [GitHub Super-Linter](https://github.com/github/super-linter).\n\n### Using TFLint\n\nTo use TFLint, follow the [installation instructions](https://github.com/terraform-linters/tflint#installation). Once installed, you can run `tflint`:\n\n![CLI command: tflint](images/tflint.gif)\n\nThis repository includes a sample [.tflint.hcl](https://github.com/ksatirli/code-quality-for-terraform/blob/main/.tflint.hcl) configuration that may serve as a starting point for your own ruleset.\n\n### Using GitHub Actions\n\nGitHub Actions are enabled by default on any GitHub Repository.\n\nThis repository includes two workflow definition files in [.github/workflows/](https://github.com/ksatirli/code-quality-for-terraform/tree/expands-readme/.github/workflows) that may serve as a starting point for your own workflows.\n\n## Notes\n\n- The [main](https://github.com/ksatirli/code-quality-for-terraform/tree/main) branch includes a working example of code quality tools and some GCP-specific Terraform resources. This branch is best used to understand how things work together\n- The [unlinted](https://github.com/ksatirli/code-quality-for-terraform/tree/unlinted) branch includes a handful of misconfigurations (in the `.tf` files) to test the various code quality tools.\n- The [tools-only](https://github.com/ksatirli/code-quality-for-terraform/tree/tools-only) branch includes _just_ the configuration of `pre-commit`, `tflint` and GitHub Actions for Terraform as well as GitHub Super-Linter. This branch is best used as a starting point: just add your own `.tf` files and go!\n\n## Author Information\n\nThis repository is maintained by [Kerim Satirli](https://github.com/ksatirli).\n\n## License\n\nLicensed under the Apache License, Version 2.0 (the \"License\").\n\nYou may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an _\"AS IS\"_ basis, without WARRANTIES or conditions of any kind, either express or implied.\n\nSee the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksatirli%2Fcode-quality-for-terraform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksatirli%2Fcode-quality-for-terraform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksatirli%2Fcode-quality-for-terraform/lists"}