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

[Q] How to import output from a dependency block? #3907

Open
gleitoncampos opened this issue Feb 19, 2025 · 1 comment
Open

[Q] How to import output from a dependency block? #3907

gleitoncampos opened this issue Feb 19, 2025 · 1 comment
Labels
awaiting response Waiting for a response or more data from issue reporter

Comments

@gleitoncampos
Copy link

gleitoncampos commented Feb 19, 2025

Hello people!
I have the following structure:

_global
  - route53
    -  terragrunt.hcl (Dedicated to all AWS R53 zones)
dev
  - route53
    - terragrunt.hcl (dedicated to all dns records from dev env)
...  

After the zones creation, the terragrunt give me that output:

route53_zone_zone_id = {
"foo.bar" = "ZXXXXXXXX"
"foo.test" = "ZXXXXXXXX"
}

In terragrunt.hcl, inside the dev/route53 folder, i'm trying to create a new record to be placed in the "foo.test", the second zone created, using the following:

include "root" {
  path = find_in_parent_folders("root.hcl")
}

terraform {
  source = "terraform-aws-modules/route53/aws//modules/records?version=4.1.0"
}

dependency "r53_zones" {
  config_path = "../../_global/route53"
}

inputs = {
    records = [
        {
        name = "dev"
        zone_id = dependency.r53_zones.outputs.route53_zone_zone_id["foo.test"]
        type = "A"
        ttl = 3600
        records = "10.10.10.1"
        },
    ]

}

But I receive an error saying "The given key does not identify an element in this collection value."
Someone can point me the problem here?
Thanks :)

@yhakbar
Copy link
Collaborator

yhakbar commented Feb 20, 2025

Whenever possible, try to reproduce your issue with a minimal, simple fixture like the following:

$ eza -T
.
├── dependency
│   ├── main.tf
│   └── terragrunt.hcl
└── dependent
    ├── main.tf
    └── terragrunt.hcl
$ fd -tf -x bash -c 'echo "# {}" && cat {} && echo'
# ./dependency/main.tf
output "complex" {
  value = {
    "foo.bar" = "ZXXXXXXXX",
  }
}

# ./dependent/main.tf
variable "simple" {
  type = string
}

resource "null_resource" "simple" {
  triggers = {
    simple = var.simple
  }
}

# ./dependent/terragrunt.hcl
dependency "dependency" {
  config_path = "../dependency"
}

inputs = {
	simple = dependency.dependency.outputs.complex["foo.bar"]
}

# ./dependency/terragrunt.hcl

I'm unable to reproduce your issue with that fixture.

We also need information like Terragrunt version number, etc. if we're going to be able to help you efficiently.

@yhakbar yhakbar added the awaiting response Waiting for a response or more data from issue reporter label Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Waiting for a response or more data from issue reporter
Projects
None yet
Development

No branches or pull requests

2 participants