terragrunt
terragrunt copied to clipboard
[Question] How can we access data from terraform module inside a terragrunt hcl file ?
Here is my hcl file:
terraform {
source = "git@...."
}
locals = {
config = templatefile("./config.yml", { environment = {NEED HELP HERE } )]])
}
Inside the terraform module, I have a data that retrieve a value from our cloud provider. I would like to know if it is possible to use this data in order to file the variable required inside the templatefile ? The only solution I have is to use an run_cmd in order to reproduce the behavior of the data block in the module.
Thanks for your help,
Have a great day.
Hi,
I was thinking about usage of dependency
and outputs
field
# terragrunt.hcl
dependency "module" {
# module where Terraform code is defined
config_path = "../module"
mock_outputs_allowed_terraform_commands = ["validate"]
mock_outputs = {
file_name = "test"
}
}
inputs = {
value = dependency.module.outputs.file_name
}
# main.tf
variable "value" {
type = string
}
resource "local_file" "file" {
content = var.value
filename = "${path.module}/txt.txt"
}
References:
https://terragrunt.gruntwork.io/docs/reference/config-blocks-and-attributes/#dependency https://github.com/denis256/terragrunt-tests/tree/master/issue-2226
This is not what I really want in fact. But I think it's not possible.
In fact, the hcl file I linked in the issue is used to manage dependency for the module between multiple others modules. This is why I was asking it the parent could use data from the terraform source but I don't think it's possible regarding your response.
I will use an run_cmd like I already did. It was just to find out if there was a better way to do it.
@axelczk -- I'm going to close this issue since it sounds like you got things working.