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

[Question] - Referencing inputs in child terragrunt.hcl #967

Closed
johanssone opened this issue Dec 3, 2019 · 3 comments
Closed

[Question] - Referencing inputs in child terragrunt.hcl #967

johanssone opened this issue Dec 3, 2019 · 3 comments

Comments

@johanssone
Copy link

Hi, I have a question I can't really wrap my head around

I have the following structure for a set of openstack resources:

../
|-- empty.yaml
|-- region-mon
|   |-- region01
|   |   |-- network-wiring
|   |   |   |-- internal
|   |   |   |   |-- net
|   |   |       |   `-- terragrunt.hcl
|   |   |   |   `-- secgroup
|   |   |       |   `-- terragrunt.hcl
|   |   |   `-- mgmt
|   |   |       |-- net
|   |   |       |   `-- terragrunt.hcl
|   |   |       `-- secgroup
|   |   |       |   `-- terragrunt.hcl
|   |   `-- region.yaml
`-- terragrunt.hcl

In my root terragrunt.hcl I have some common config for backend etc but also reference common vars for region, somewhat following this:

...
inputs = merge(
  yamldecode(
    file("${get_terragrunt_dir()}/${find_in_parent_folders("region.yaml")}"),
  ),
)
...

In region.yaml I have a couple of variables that will be sent in as input to child terragrunt.hcl files:

---
openstack_cloud: region01
external_network_name: xx
dns_nameservers: [xxx, yyy]

Question is if it's possible in a good way to reference the variables set in region.yaml i child terragrunt.hcl files.

Scenario:
In one of the terragrunt.hcl files under region01 directory, I have a input called name, but I want to prefix that name with openstack_cloud and potentially accessing other values as well, without the need to put that logic in the module(s) themselfs

Child terragrunt.hcl:

include {
  path = find_in_parent_folders()
}

terraform {
  source = "../../../../modules/os-network"
}

inputs = {
 #  Psuedo code for what I'm trying to achieve
  name = join(region_var.openstack_cloud, "mgmt-net")
}

I've tried play around with locals to no avail:

locals {
   name1 = join(get_env("TF_VAR_openstack_cloud "default"), "mgmt-net")
   name2 = join(var.name, "mgmt-net")
}

inputs = {
 
  name = local.name1
  name = local.name2
}

I'm I planning up repo structure completely wrong, trying to share variables? (in this case based in region or geographic location)

@johanssone
Copy link
Author

johanssone commented Dec 3, 2019

I just realized that putting this particular logic inside the modules makes more sense...

The question still remains though, is there a way to reference parent inputs in child terragrunt.hcl files?

@yorinasub17
Copy link
Contributor

Not currently, but this is an active feature request. See the conversation on globals (#814) and the related PR (#858) for the latest.

@yorinasub17
Copy link
Contributor

Closing as duplicate.

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

No branches or pull requests

2 participants