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

Introduce validate-inputs, which can be used to check for variable alignment #1572

Merged
merged 13 commits into from
Mar 12, 2021

Conversation

yorinasub17
Copy link
Contributor

Refer to the docs for info on this new command.

@yorinasub17 yorinasub17 requested a review from brikis98 as a code owner March 4, 2021 20:13
terragruntOptions.Logger.Debugf("Skipping var-file %s as it does not exist", file)
}
}
varFiles := arg.GetVarFiles(terragruntOptions.Logger)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a refactor to have a common function that can be used to extract all the var files that terragrunt should set.

return nil
}

// ParseAndDecodeVarFile uses the HCL2 parser to parse the given varfile string into an HCL file body, and then decode it
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is a straight copy from terratest for now. In a near-future PR, I plan on refactoring the cty helpers into gruntwork-cli so we can reuse it.

@@ -124,97 +124,12 @@ const (
TERRAFORM_STATE = "terraform.tfstate"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests that were removed here were refactored out given how big this file is.

// so our override of extra_var should be the last argument.
assert.Contains(t, out.String(), fmt.Sprintf(`test = "%s"`, injectedValue))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two tests after this line are new. Everything before are from integration_test.go that needed to run in serial.

@@ -0,0 +1,209 @@
package test
Copy link
Contributor Author

@yorinasub17 yorinasub17 Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: scroll to next comment in this file that marks which test is new. Everything inbetween are straight from integration_test.go

TERRAGRUNT_DEBUG_FILE = "terragrunt-debug.tfvars.json"
)

func TestDebugGeneratedInputs(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is migrated from integration_test.go. No need to review.

_, isDefined := data["undefined_var"]
assert.False(t, isDefined)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything below this line in this file is new.

@@ -487,59 +513,6 @@ func decodeAsTerragruntConfigFile(
return &terragruntConfig, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions were refactored out into hcl_parser.go so all the HCL parsing related functions were consolidated.

cli/input_info.go Outdated Show resolved Hide resolved
cli/input_info.go Outdated Show resolved Hide resolved
@yorinasub17 yorinasub17 changed the title Introduce terragrunt-input-info, which can be used to check for variable alignment Introduce validate-inputs, which can be used to check for variable alignment Mar 5, 2021
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition!

Didn't you have a prev hackday project that could auto-generate a terragrunt.hcl file, with placeholders for all input vars in an inputs block, for a given module too?

cli/cli_app.go Show resolved Hide resolved
cli/validate_inputs.go Outdated Show resolved Hide resolved
cli/validate_inputs.go Outdated Show resolved Hide resolved
cli/validate_inputs.go Show resolved Hide resolved
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! Just a few minor sanity checks.

cli/validate_inputs.go Outdated Show resolved Hide resolved
cli/validate_inputs.go Outdated Show resolved Hide resolved
docs/_docs/04_reference/cli-options.md Outdated Show resolved Hide resolved
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yorinasub17
Copy link
Contributor Author

Thanks for review! Will merge and release!

@yorinasub17 yorinasub17 merged commit b1caafd into master Mar 12, 2021
@yorinasub17 yorinasub17 deleted the yori-var-check branch March 12, 2021 16:41
teamfighter added a commit to teamfighter/terragrunt that referenced this pull request Apr 5, 2021
* Fix dead link in multiple aws accounts docs (gruntwork-io#1563)

* Fix dead link in multiple aws accounts docs

The link to AWS docs is now 404.
The corrected link seems to most closely resemble the intended target.
Other options to consider:
https://aws.amazon.com/organizations/getting-started/best-practices/
https://docs.aws.amazon.com/controltower/latest/userguide/aws-multi-account-landing-zone.html

* Link to AWS best practices for multi account docs

* Whitespace removal (gruntwork-io#1573)

* Fix empty outputs (gruntwork-io#1568)

If stack run finished without errors, `summarizePlanAllErrors()`
receives empty buffer and outputs empty line. This change ensures that
only non-empty outputs are getting logged.

Related: gruntwork-io#1541

* doc: contributing: fix broken link to circleci (gruntwork-io#1580)

* Bump AWS SDK to version v1.37.7 to support AWS SSO (gruntwork-io#1537)

* Add TargetPrefix as config input to access bucket logging (gruntwork-io#1507)

* adding target-prefix ro access bucket logging

* Updating test & example

! Note that this needs the terratest PR (gruntwork-io/terratest#767) to be merged in to work & be tested.

* Updating Terratest dependency

* testing for target prefix

* Updating docs

* Renaming folder

* Updating to Debugf

* Adding default value

* WIP - parsing for TFstatelogs

* Updating logic & docs

* Adding a new test for default TargetPrefix in remote backend config

* Introduce validate-inputs, which can be used to check for variable alignment (gruntwork-io#1572)

* Introduce terragrunt-input-info, which can be used to check for variable alignment

* Apply suggestions from code review

Co-authored-by: Zack Proser <[email protected]>

* Tidy go modules

* Renamed input-info to validate-inputs

* Switch missing required vars to errors

* Handle -var and -var-file args

* Update cli/validate_inputs.go

Co-authored-by: Yevgeniy Brikman <[email protected]>

* Make sure to check for dynamically passed in CLI args

* Fix build

* Handle automatically loaded var files

* Remove plan args check

* Clarify difference between getTerraformInputNamesFromVarFiles and getTerraformInputNamesFromCLIArgs

* Address PR nit to move example in docs

Co-authored-by: Zack Proser <[email protected]>
Co-authored-by: Yevgeniy Brikman <[email protected]>

* Use go1.16 to build arm64 binaries (gruntwork-io#1585)

* Bump creack/pty to 1.1.11 (gruntwork-io#1582)

Co-authored-by: Andy Bohne <[email protected]>

* Add ability to specify working directory of hooks (gruntwork-io#1588)

* Add ability to specify working directory of hooks

* Fix build

* Support dynamodb_endpoint attribute of S3 backend (gruntwork-io#1586)

* Clarify non-interactive will not include external dependencies (gruntwork-io#1593)

* add getTerragruntSource helper function (gruntwork-io#1575)

* add getTerragruntSource helper function

* update docs

* update docs and tests for get_terragrunt_source_cli_flag() function

* add use cases for get_terragrunt_source_cli_flag

* Recursively extract forcedgetters until there are none (gruntwork-io#1594)

* Remove all usage of get-plugins=false which is removed in 0.15.0 (gruntwork-io#1618)

* Fix validate-inputs to support null defaults (gruntwork-io#1613)

* Clarify context of find_in_parent_folders (gruntwork-io#1623)

Co-authored-by: Paul <[email protected]>
Co-authored-by: Yoriyasu Yano <[email protected]>
Co-authored-by: amnk <[email protected]>
Co-authored-by: Marco Molteni <[email protected]>
Co-authored-by: David Wooldridge <[email protected]>
Co-authored-by: Ina Stoyanova <[email protected]>
Co-authored-by: Zack Proser <[email protected]>
Co-authored-by: Yevgeniy Brikman <[email protected]>
Co-authored-by: Andy Bohne <[email protected]>
Co-authored-by: Andy Bohne <[email protected]>
Co-authored-by: Alexey Remizov <[email protected]>
Co-authored-by: Syed Hussain <[email protected]>
Co-authored-by: David Alger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants