-
Notifications
You must be signed in to change notification settings - Fork 481
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
Sample code to extract variable value from hcl #41
Comments
folks , please suggest . This is blocker for me so any help would be much appreciated |
Did you look at the corresponding https://github.com/gruntwork-io/terragrunt-infrastructure-modules-example? |
Yes , i looked at the above link and now more confused !!! sorry to say that Simply, what I am looking for is, how to define the terragrunt.hcl file with all common variables and use them in all the child modules. In above example/link, haven't seen any terragrunt file (neither in root module , nor in any child module ) . in above example, all the variables are coming from variables.tf file but I am expecting to get it from terragrunt.hcl file and use in main.tf file . Like you said, we can define variables like below in terragrunt file , now can we use these variables in main.tf ? If yes, please give me example.
|
please suggest |
Terragrunt is a wrapper around terrraform where it automates machinery around passing CLI args, vars, and env vars to terraform, so you need to get the variables defined in terraform somehow. The two ways to do this are:
I suspect you are looking for the second way? |
Thanks for the reply. lets say , i have following code in my terragrunt.hcl
now my question is , can i use variable |
Yes, assuming you have the |
E.g. in your terragrunt.hcl, generate "common_vars" {
path = "common_vars.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
variable "instance_type" {}
EOF
} |
regarding generate block , let me understand more and come back regarding other option of defining variables in terraform, if i understand correctly here is what i can do : in terragrunt.hcl
and in the module's variable.tf file , i can have something like this :
and then in main.tf file , i can use this variable like : |
Yes that is correct. |
ok Thanks |
Hi,
Can we have sample code (.tf) file to understand how these variable values can be floated to terraform code. ? I see in this repo all hcl files and their structure all along the child folders . However how these variables can be easily extracted in code is not shown.
Please add couple code examples
Thanks
The text was updated successfully, but these errors were encountered: