Skip to content

feat(INT-83): dial in configs for tflint #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Trunk Check
uses: trunk-io/trunk-action@4d5ecc89b2691705fd08c747c78652d2fc806a94 # v1.1.19
env:
# NOTE: inject the GITHUB_TOKEN for the trunk managed tflint linter
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

conventional-title:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# IDE/Editor settings
**/.idea
**/*.iml
.cursor/
.vscode/
*.orig
*.draft
Expand Down Expand Up @@ -43,4 +44,4 @@ backend.tf.json
**/*.temp
**/*.bak
**/*.*swp
**/.DS_Store
**/.DS_Store
42 changes: 42 additions & 0 deletions .trunk/configs/.tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugin "terraform" {
enabled = true
preset = "all"
}

config {
format = "compact"

# Inspect vars passed into "module" blocks. eg, lint AMI value passed into ec2 module.
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/calling-modules.md
call_module_type = "all"

# default values but keeping them here for clarity
disabled_by_default = false
force = false
}

# Installing tflint rulesets from Github requires setting a GITHUB_TOKEN
# environment variable. Without it, you'll get an error like this:
# $ tflint --init
# Installing "aws" plugin...
# Failed to install a plugin; Failed to fetch GitHub releases: GET https://api.github.com/repos/terraform-linters/tflint-ruleset-aws/releases/tags/v0.39.0: 401 Bad credentials []
#
# The solution is to provide a github PAT via a GITHUB_TOKEN env var,
# export GITHUB_TOKEN=github_pat_120abc123def456ghi789jkl123mno456pqr789stu123vwx456yz789
#
# See docs for more info: https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting
plugin "aws" {
enabled = true
version = "0.39.0"
source = "github.com/terraform-linters/tflint-ruleset-aws"
deep_check = false
}

# Allow variables to exist in more files than ONLY variables.tf
# Example use cases where we prefer for variables to exist in context,
# - context.tf (applicable to the null-label module)
# - providers.tf (when passing in secret keys from SOPs - example, github provider)
# https://github.com/terraform-linters/tflint-ruleset-terraform/blob/main/docs/rules/terraform_standard_module_structure.md
rule "terraform_standard_module_structure" {
enabled = false
}
7 changes: 7 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ lint:
- trivy@0.63.0
- trufflehog@3.88.35
- yamllint@1.37.1
# NOTE(tflint): specific override required so it uses .tflint.hcl file in .trunk/configs directory
# https://github.com/trunk-io/plugins/tree/main/linters/tflint
definitions:
- name: tflint
environment:
- name: TFLINT_CONFIG_FILE
value: ${workspace}/.trunk/configs/.tflint.hcl
Comment on lines +37 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this, do we just want to include it at the root of the project so that it can be picked up like other configs and isn't hidden in the trunk folder?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered about that.

I looked at a other linter configs in the .trunk/configs folder, and thought bending the configurations to keep the convention of storing the configs in the same place would be valuable for downstream consumers.

CleanShot 2025-05-23 at 09 02 34

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gowiem did you have an opinion on this approach? I am reviewing what else needs to be take care before merging this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this for now and ship it, but two things for us in the future to follow up on:

  1. Let's make sure this gets picked up by the OSS sync tasks we have in taskit
  2. We have config spread around and our more important configs like terraform-docs.yaml, aqua.yaml, .editorconfig and similar are top level. I like that personally because in the future we could rip out trunk and not changes to these configs would need to be made.

ignore:
- linters: [tofu]
paths:
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@

## Purpose and Functionality

This repository serves as a template for creating Terraform modules, providing a standardized structure and essential files for efficient module development. It's designed to ensure consistency and our best practices across Terraform projects.
This repository serves as a template for creating Terraform modules, providing a standardized structure and essential files for efficient module development. It is designed to ensure consistency and promote our best practices across all Terraform projects.

It comes pre-configured with Masterpoint's curation of open source tools, which our team uses to operate more effectively within Terraform and OpenTofu codebases.

- [**aqua**](https://aquaproj.github.io/): Declarative CLI tool verison manager
- **tofu + terraform test workflows**: For continuously testing our TF code
- [**terraform-docs**](https://terraform-docs.io/): Easily add terraform docs to the README
- [**trunk**](https://docs.trunk.io/references/cli/getting-started): Trunk CLI for managing code quality (linters + checks)
- **actionlint**: Linter for GitHub Actions workflows
- **checkov**: Infrastructure as Code (IaC) security scanner
- **git-diff-check**: Checks for issues in git diffs
- **markdownlint**: Linter for Markdown files
- **prettier**: Code formatter for consistent style
- **renovate**: Automated dependency updates
- **tflint**: Terraform linter for best practices and error detection
- **trivy**: Scans containers and artifacts for vulnerabilities
- **trufflehog**: Secret and sensitive data scanner
- **yamllint**: Linter for YAML files

## Usage

Expand Down
2 changes: 1 addition & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# complete.tf
# complete/main.tf
2 changes: 1 addition & 1 deletion examples/complete/outputs.tf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# complete.tf
# complete/outputs.tf
2 changes: 1 addition & 1 deletion examples/complete/variables.tf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# complete.tf
# complete/variables.tf
5 changes: 5 additions & 0 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# complete/versions.tf

terraform {
required_version = ">= 1.0.0"
}