Guard terraform validate on successful init and propagate failures#952
Open
phorcys420 wants to merge 1 commit into
Open
Guard terraform validate on successful init and propagate failures#952phorcys420 wants to merge 1 commit into
phorcys420 wants to merge 1 commit into
Conversation
Two related issues in validate_terraform_directory: - `terraform validate` requires modules to be installed by `terraform init` first. When init failed (e.g. a bad module source), the script still ran validate, producing misleading "Module not installed" errors that masked the real init failure. Now init failure short-circuits with a clear error and skips validate. - `popd` was the last command in the function, so its exit status masked terraform's — the function always returned 0 and real validation failures were printed but never recorded in $status (the script exited 0 despite failures). Capture terraform's exit code and return it explicitly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
scripts/terraform_validate.shhad two related issues invalidate_terraform_directory:terraform validatewas run even whenterraform initfailed.validaterequires modules to be installed byinitfirst, so an init failure (e.g. a bad module source) produced a cascade of misleadingModule not installederrors that hid the real cause.popdmasked the function's exit status. Becausepopdwas the last statement in the function, it always returned0. Realterraform validatefailures were printed but never recorded in$status, so the script exited0despite failures — validation could not actually fail CI.Fix
terraform init failederror and skipvalidate, surfacing the real problem.terraform validate's exit code andreturnit explicitly (afterpopd), so failures propagate to$statusand the script exits non-zero.Validation
bash -nandshellcheck --severity=warning(the level CI enforces) are clean.0Generated with Mux.