terraform-linters/tflint

tflint in Docker not running the checks

samrobillard opened this issue · 0 comments

Summary

I have the following PowerShell script running in Azure DevOps. The Azure plugin gets installed but nothing else happens.

param (
[Parameter(Mandatory = $true)][string]$targetDirectory
)

Set-Location $targetDirectory

$gitRootFolder = git rev-parse --show-toplevel
$changes = git diff --name-only 'HEAD~' 'HEAD'
$filesOfInterest = $changes | Where-Object {$_ -ilike '.tf' -or $_ -ilike '.tfvars'}
$foldersToCheck = $filesOfInterest | ForEach-Object {Split-Path $_} | Sort-Object -Unique

foreach ($folder in $foldersToCheck) {
Write-Host "Running TFLint in $folder..."
$message = docker run --rm -v "$($gitRootFolder)/$($folder):/data" -v "$($env:PIPELINE_WORKSPACE)/s/Pipeline-Library/steps/tf-lint:/tflint" --entrypoint=/bin/sh ghcr.io/terraform-linters/tflint -c "tflint --init --fix --config /tflint/config.tflint.hcl";
$message

foreach ($line in $message) {
if ($line -contains "Error" -or $line -contains "Warning") {
Write-Host "##[error]TF LINT ISSUE FOUND IN $folder"
Write-Host $line -ForegroundColor DarkYellow
Write-Host "##vso[task.complete result=Failed;]"
}
}
}

Command

tflint

Terraform Configuration

# This configuration is supposed to trigger TFLINT because its missing source version. It also does not #contain the terraform version and providers.

##################################################################################
# RESOURCES
##################################################################################

module "zscaler" {
  #source = "app.terraform.io/REPO/COMPANY/azurerm//zscaler"
  #version = "2.2.13"

  product_name     = var.product_name
  zpa_domain_names = var.zpa_domain_names
  zpa_tcp_ports    = var.zpa_tcp_ports
  zpa_udp_ports    = var.zpa_udp_ports
}

TFLint Configuration

config {
  module = true
  format = "default"
  plugin_dir = "~/.tflint.d/plugins"

  call_module_type = "all"
  force = false
  disabled_by_default = false
}

plugin "terraform" {
  enabled = true
  preset  = "recommended"
}

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

Output

Running TFLint in modules/zscaler...
Unable to find image 'ghcr.io/terraform-linters/tflint:latest' locally
latest: Pulling from terraform-linters/tflint
4abcf2066143: Already exists
8a6bb7438b9b: Pulling fs layer
097a6a8a3c66: Pulling fs layer
1727a51921d4: Pulling fs layer
8a6bb7438b9b: Verifying Checksum
8a6bb7438b9b: Download complete
1727a51921d4: Verifying Checksum
1727a51921d4: Download complete
097a6a8a3c66: Verifying Checksum
097a6a8a3c66: Download complete
8a6bb7438b9b: Pull complete
097a6a8a3c66: Pull complete
1727a51921d4: Pull complete
Digest: sha256:5496858a1b091c090267a33d4e99f75ca1067b58bcfe7bb34745b222a260e1b6
Status: Downloaded newer image for ghcr.io/terraform-linters/tflint:latest
Installing "azurerm" plugin...
Installed "azurerm" (source: github.com/terraform-linters/tflint-ruleset-azurerm, version: 0.25.1)

TFLint Version

0.50.3

Terraform Version

No response

Operating System

  • Linux
  • macOS
  • Windows