Skip to content
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

use hclmerge to merge a new tflint config file when there is override hcl config #25

Merged
merged 1 commit into from
Jan 24, 2024
Merged
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
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