Skip to content
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
69 changes: 69 additions & 0 deletions .github/workflows/terraform-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Terraform Lint

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]

jobs:
tflint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Cache plugin dir
uses: actions/cache@v3
with:
path: ~/.tflint.d/plugins
key: ${{ hashFiles('.tflint.hcl') }}

- uses: terraform-linters/setup-tflint@v4
with:
tflint_version: v0.50.3

- name: Show version
run: tflint --version

- name: Init TFLint
run: tflint --init

- name: Run TFLint
run: tflint --format compact

- name: Run TFLint on modules
run: |
find . -name "*.tf" -exec dirname {} \; | sort -u | while read dir; do
echo "Linting $dir"
(cd "$dir" && tflint --format compact)
done

terraform-fmt:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.8.0"

- name: Terraform Format Check
run: terraform fmt -check -recursive -diff

terraform-validate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.8.0"

- name: Terraform Init
run: terraform init -backend=false

- name: Terraform Validate
run: terraform validate
53 changes: 53 additions & 0 deletions .tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
plugin "terraform" {
enabled = true
preset = "recommended"
}

plugin "azurerm" {
enabled = true
version = "0.29.0"
source = "github.com/terraform-linters/tflint-ruleset-azurerm"
}

rule "terraform_deprecated_interpolation" {
enabled = true
}

rule "terraform_unused_declarations" {
enabled = true
}

rule "terraform_comment_syntax" {
enabled = true
}

rule "terraform_documented_outputs" {
enabled = true
}

rule "terraform_documented_variables" {
enabled = true
}

rule "terraform_typed_variables" {
enabled = true
}

rule "terraform_module_pinned_source" {
enabled = true
}

rule "terraform_naming_convention" {
enabled = true
format = "snake_case"
}

rule "terraform_standard_module_structure" {
enabled = true
}

# Azure-specific rules
rule "azurerm_resource_missing_tags" {
enabled = true
tags = ["Name", "Environment"]
}
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"hashicorp.terraform"
]
}
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"terraform.validation.enableEnhancedValidation": true,
"terraform.languageServer.enable": true,
"terraform.codelens.referenceCount": true,
"files.associations": {
"*.tf": "terraform",
"*.tfvars": "terraform",
"*.tfvars.example": "terraform",
".tflint.hcl": "hcl"
},
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.formatDocument": "explicit"
},
"[terraform]": {
"editor.defaultFormatter": "hashicorp.terraform",
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 2
},
"[hcl]": {
"editor.defaultFormatter": "hashicorp.terraform",
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 2
}
}
121 changes: 121 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Terraform: Format",
"type": "shell",
"command": "terraform",
"args": [
"fmt",
"-recursive"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "Terraform: Validate",
"type": "shell",
"command": "terraform",
"args": [
"validate"
],
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"dependsOn": "Terraform: Init (no backend)"
},
{
"label": "Terraform: Init (no backend)",
"type": "shell",
"command": "terraform",
"args": [
"init",
"-backend=false"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "TFLint: Initialize",
"type": "shell",
"command": "tflint",
"args": [
"--init"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "TFLint: Run",
"type": "shell",
"command": "tflint",
"args": [
"--format",
"compact"
],
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"dependsOn": "TFLint: Initialize",
"problemMatcher": [
{
"owner": "tflint",
"fileLocation": "relative",
"pattern": {
"regexp": "^([^:]+):(\\d+):(\\d+):\\s+(Error|Warning|Notice):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
]
},
{
"label": "Terraform: Full Lint Check",
"dependsOrder": "sequence",
"dependsOn": [
"Terraform: Format",
"Terraform: Validate",
"TFLint: Run"
],
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}
Loading