Skip to main content
Knowledge Base

How can we merge inputs, when i excute the B.hcl (which has inputs init) it should also take/ merge inputs from A.hcl (which also has inputs ) without any need of additional files.

Answer

Hi there, How can we merge inputs, when i execute the B.hcl (which has inputs init) it should also take/ merge inputs from A.hcl (which also has inputs ) without any need of additional files. Here's my code for reference ``` B.hcl terraform { source = "${include.env.locals.base_source_url}?ref=v0.0.7" } include "root" { path = find_in_parent_folders() } include "env" { path = "../env/A.hcl" expose = true } inputs = merge ( include.env.inputs, { security_groups = [ { name = "ec2" description = "EC2 " } ] } ) A.HCL locals { base_source_url = "repo_URL" sg_vars = read_terragrunt_config("sg.hcl") sg_name = local.sg_vars.locals.sg } dependency "vpc" { config_path = "../../vpc" } inputs = { vpc_id = dependency.vpc.outputs.vpc_id security_groups = [ { name = "ec2${local.sg_name}_0" description = "EC2_00" }, { name = "ec2${local.sg_name}_1" description = "EC2 _01" } ] tags = { Terraform = true } } ``` --- <ins datetime="2022-04-25T10:56:22Z"> <p><a href="https://gruntwork.zendesk.com/agent/tickets/108490">Tracked in ticket #108490</a></p> </ins>

Inputs are automatically merged across includes, so there is no need for the explicit merge call with `expose`. Since I observe in your example that you have the `security_groups` key in both files, I suspect what you are looking for is deep merge. Refer to the section "What is deep merge?" in the [include blocks reference](https://terragrunt.gruntwork.io/docs/reference/config-blocks-and-attributes/#include) for more details.