Skip to content

Commit

Permalink
use hclmerge to merge a new tflint config file when there is override…
Browse files Browse the repository at this point in the history
… hcl config
  • Loading branch information
lonegunmanb committed Jan 24, 2024
1 parent d58350b commit 327bc56
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions avm_scripts_canary/run-tflint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@

set_tflint_config() {
local env_var=$1
local alt_file=$2
local override_file=$2
local default_url=$3
local download_file=$4
local merged_file=$5

if [ -z "${!env_var}" ]; then
if [ -f "$alt_file" ]; then
export $env_var="$alt_file"
else
curl -H 'Cache-Control: no-cache, no-store' -sSL "$default_url" -o "$download_file"
export $env_var="$download_file"
fi
# Always download the file from GitHub
curl -H 'Cache-Control: no-cache, no-store' -sSL "$default_url" -o "$download_file"

# Check if the override file exists
if [ -f "$override_file" ]; then
# If it does, merge the override file and the downloaded file
hclmerge -1 "$override_file" -2 "$download_file" -d "$merged_file"
# Set the environment variable to the path of the merged file
export $env_var="$merged_file"
else
# If it doesn't, set the environment variable to the path of the downloaded file
export $env_var="$download_file"
fi
}

set_tflint_config "TFLINT_CONFIG" ".tflint_alt.hcl" "https://raw.githubusercontent.com/Azure/tfmod-scaffold/main/avm.tflint.hcl" "avm.tflint.hcl"
set_tflint_config "TFLINT_EXAMPLE_CONFIG" ".tflint_example_alt.hcl" "https://raw.githubusercontent.com/Azure/tfmod-scaffold/main/avm.tflint_example.hcl" "avm.tflint_example.hcl"

set_tflint_config "TFLINT_CONFIG" "avm.tflint.override.hcl" "https://raw.githubusercontent.com/Azure/tfmod-scaffold/main/avm.tflint.hcl" "avm.tflint.hcl" "avm.tflint.merged.hcl"
set_tflint_config "TFLINT_EXAMPLE_CONFIG" "avm.tflint_example.override.hcl" "https://raw.githubusercontent.com/Azure/tfmod-scaffold/main/avm.tflint_example.hcl" "avm.tflint_example.hcl" "avm.tflint_example.merged.hcl"

echo "==> Checking that code complies with tflint requirements..."
tflint --init --config=$TFLINT_CONFIG
Expand Down

0 comments on commit 327bc56

Please sign in to comment.