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

add getTerragruntSource helper function #1575

Merged
merged 4 commits into from
Mar 24, 2021

Conversation

suhussai
Copy link
Contributor

@suhussai suhussai commented Mar 6, 2021

No description provided.

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.

Thanks for the PR! The code changes look good overall, but could you please:

  1. Describe the use case for this
  2. Update the docs

Thanks!

@suhussai
Copy link
Contributor Author

Hi brikis98, thanks for reviewing!

Regarding your questions, I added the new function to the list of internal functions in the documentation and provided some information on what the function will return. I'm not sure what the use case for this might be. I'll ask in the original issue for more clarification.

@@ -115,6 +115,7 @@ func CreateTerragruntEvalContext(
"get_terraform_commands_that_need_input": wrapStaticValueToStringSliceAsFuncImpl(TERRAFORM_COMMANDS_NEED_INPUT),
"get_terraform_commands_that_need_parallelism": wrapStaticValueToStringSliceAsFuncImpl(TERRAFORM_COMMANDS_NEED_PARALLELISM),
"sops_decrypt_file": wrapStringSliceToStringAsFuncImpl(sopsDecryptFile, extensions.Include, terragruntOptions),
"get_terragrunt_source": wrapVoidToStringAsFuncImpl(getTerragruntSource, extensions.Include, terragruntOptions),
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should rename this to get_terragrunt_source_cli_flag to make clear that this only returns values passed through with --terragrunt-source?


## get\_terragrunt\_source

`get_terragrunt_source()` returns the location of the Terraform files. This location can be provided via CLI `--terragrunt-source`, an environment variable `TERRAGRUNT_SOURCE` or in the `terragrunt.hcl` file. Calling this function will return the value of that field.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`get_terragrunt_source()` returns the location of the Terraform files. This location can be provided via CLI `--terragrunt-source`, an environment variable `TERRAGRUNT_SOURCE` or in the `terragrunt.hcl` file. Calling this function will return the value of that field.
`get_terragrunt_source()` returns the value passed in via the CLI `--terragrunt-source` or an environment variable `TERRAGRUNT_SOURCE`. Note that this will return an empty string when either of those values are not provided.
This is useful for constructing before and after hooks, or TF flags that only apply to local development (e.g., setting up debug flags, or adjusting the `iam_role` parameter).

@yorinasub17
Copy link
Contributor

@brikis98

Describe the use case for this

The main use case for this is to adjust the terragrunt configuration depending on whether its local development or not (--terragrunt-source was passed in). This came up in one of our support tickets, where a customer wanted to run terraform fmt as a before hook whenever you ran against local source during development. I can see other use cases for this as well:

  • Setting debug logging when local dev.
  • Adjusting the kubernetes provider configuration so that it targets minikube instead of real clusters.
  • Providing special mocks pulled in from the local dev source (e.g., something like mock_outputs = jsondecode(file("${get_terragrunt_source_cli_arg()}/dependency_mocks/vpc.json"))).

@brikis98
Copy link
Member

@brikis98

Describe the use case for this

The main use case for this is to adjust the terragrunt configuration depending on whether its local development or not (--terragrunt-source was passed in). This came up in one of our support tickets, where a customer wanted to run terraform fmt as a before hook whenever you ran against local source during development. I can see other use cases for this as well:

  • Setting debug logging when local dev.
  • Adjusting the kubernetes provider configuration so that it targets minikube instead of real clusters.
  • Providing special mocks pulled in from the local dev source (e.g., something like mock_outputs = jsondecode(file("${get_terragrunt_source_cli_arg()}/dependency_mocks/vpc.json"))).

Roger, thx for the explanation! May be worth adding to the docs!

@suhussai
Copy link
Contributor Author

Added use cases to the docs for get_terragrunt_source_cli_flag().

Let me know if there's anything else I can add.

Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

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

Updates LGTM! Will kick off the build momentarily.

@yorinasub17
Copy link
Contributor

Build passed, so going to merge this in! Thanks for your contribution!

@yorinasub17 yorinasub17 merged commit 6c07094 into gruntwork-io:master Mar 24, 2021
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 <zackproser@gmail.com>

* 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 <brikis98@users.noreply.github.com>

* 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 <zackproser@gmail.com>
Co-authored-by: Yevgeniy Brikman <brikis98@users.noreply.github.com>

* 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 <andrew.bohne@ring.com>

* 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 <1727604+paulvandenburg@users.noreply.github.com>
Co-authored-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com>
Co-authored-by: amnk <amnk@users.noreply.github.com>
Co-authored-by: Marco Molteni <51477941+marco-m-pix4d@users.noreply.github.com>
Co-authored-by: David Wooldridge <zombie@zombix.org>
Co-authored-by: Ina Stoyanova <ina@gruntwork.io>
Co-authored-by: Zack Proser <zackproser@gmail.com>
Co-authored-by: Yevgeniy Brikman <brikis98@users.noreply.github.com>
Co-authored-by: Andy Bohne <abohne@users.noreply.github.com>
Co-authored-by: Andy Bohne <andrew.bohne@ring.com>
Co-authored-by: Alexey Remizov <alexey@remizov.org>
Co-authored-by: Syed Hussain <suhussai@ualberta.ca>
Co-authored-by: David Alger <davidmalger@gmail.com>
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.

None yet

3 participants