-
Notifications
You must be signed in to change notification settings - Fork 137
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
Check version sources based on whether verison has been set #429
Conversation
Update logic for reading sources for obtaining version to read from next source explicitly if version has not been set. This handles situations where a source exists (e.g. TOML file, terraform files), but a version constraint cannot be found from the source. This avoids duplicate checks for existance of sources (such as Terragrunt file), as this was performed in GetParamters and also in the methods to read the config from the source. Issue #420
383fff9
to
627ef90
Compare
…uations where no version is available when config files are present Issue #420
I initially started looking at the, now, failing tests... |
Still reviewing... |
… overriding params Version with environment variable
…void polluting other tests
Previously, the highest priority was the TOML file, however, the new ordering means that terragrunt files have the highest precedence: #420
…suring each configuring overrides the previous
…y no longer contains any indicators of a valid version Issue #420
36ebed9
to
0ef7b9b
Compare
…tion permissions, avoiding other read/write Issue #420
Only call GetTomlParams once and update methods to unify getting base directory Issue #420
Update getTomlParams to use TOML directory attribute of Params Update tests to set TOML directory to set custom location for test TOML file. Issue #420
…ams methods. This allowstests to inject custom default params, by calling the two child methods seperately, instead of calling GetParameters Issue #420
9ccdee9
to
b9c3259
Compare
…ctory, if it exists
b9c3259
to
3630353
Compare
Co-authored-by: George L. Yermulnik <yz@yz.kiev.ua>
if test -f "${TEST_PATH}/.tfswitch.toml" | ||
then | ||
cp "${TEST_PATH}/.tfswitch.toml" ~/ | ||
else | ||
{ test -f ~/.tfswitch.toml && rm ~/.tfswitch.toml; } || true | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this if-conditional's goal is?
If test TOML exists, then copy it to HOME, otherwise delete TOML from HOME 😲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly that - it's handled the fact that a test has a TOML file, but we ignore ChDiR (CWD) now, but I wanted to keep the test... so copied to HOMEDIR so it continued to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I lean to think I got it =)
You should be good to replace { test -f ~/.tfswitch.toml && rm ~/.tfswitch.toml; } || true
with a simpler rm -f ~/.tfswitch.toml
lib/param_parsing/parameters.go
Outdated
logger.Fatalf("Failed to obtain settings from TOML config in home directory: %v", err) | ||
} | ||
} | ||
|
||
if tfSwitchFileExists(params) { | ||
params, err = GetParamsFromTfSwitch(params) | ||
} else if terraformVersionFileExists(params) { | ||
if err != nil { | ||
logger.Fatalf("Failed to obtain settings from \".tfswitch\" file: %v", err) | ||
} | ||
} | ||
|
||
if terraformVersionFileExists(params) { | ||
params, err = GetParamsFromTerraformVersion(params) | ||
} else if isTerraformModule(params) { | ||
if err != nil { | ||
logger.Fatalf("Failed to obtain settings from \".terraform-version\" file: %v", err) | ||
} | ||
} | ||
|
||
if isTerraformModule(params) { | ||
params, err = GetVersionFromVersionsTF(params) | ||
} else if terraGruntFileExists(params) { | ||
params, err = GetVersionFromTerragrunt(params) | ||
} else { | ||
params = GetParamsFromEnvironment(params) | ||
if err != nil { | ||
logger.Fatalf("Failed to obtain settings from Terraform module: %v", err) | ||
} | ||
} | ||
if err != nil { | ||
logger.Fatalf("Error parsing configuration file: %q", err) | ||
|
||
if terraGruntFileExists(params) { | ||
params, err = GetVersionFromTerragrunt(params) | ||
if err != nil { | ||
logger.Fatalf("Failed to obtain settings from Terragrunt configuration: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hardcoding and wording version sources, could we probably move those from lib/param_parsing/*.go
files to a more global place and re-use?
Update logic for reading sources for obtaining version to read from next source explicitly if version has not been set. This handles situations where a source exists (e.g. TOML file, terraform files), but a version constraint cannot be found from the source. This avoids duplicate checks for existance of sources (such as Terragrunt file), as this was performed in GetParamters and also in the methods to read the config from the source.
Issue #420