gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.09k stars 981 forks source link

Use resource/datasource attribute from a 'generate' block as an input #3519

Open RyanW8 opened 3 weeks ago

RyanW8 commented 3 weeks ago

Hi,

So lets say our terragrunt.hcl looks like:

terraform {
  source = "${get_parent_terragrunt_dir()}//some_module"
}

inputs = {
  some_value = "${datasource.some_datasource.this}"
  another_value = "${resource.some_resource.this}"
}

generate "extra_resources" {
  path = "app_extras.tf"
  if_exists = "overwrite_terragrunt"
  contents = <<EOF
datasource "some_datasource" "this" {}
resource "some_resource" "this" {}
EOF
}

I appreciate we could put this datasource in the module but we don't want to do that. We have a generic 'application' terraform module that engineering based applications use to deploy cloud resources for their app and in some scenarios they want to provision an extra datasource or an extra resource which wouldn't fit well within the standard application module. So we have a requirement to use the generate block ontop a module and be able to reference that as a Terragrunt input.

How can we achieve this?

denis256 commented 3 weeks ago

Hello, It is possible to create a separate dependency that will generate the datasource and produce the required outputs. These outputs can then be used in other places where they are needed.

RyanW8 commented 3 weeks ago

Yeah I get that pattern but it's not clean IMO and scatters an application configuration across multiple directories. It'd be nice to be able to define it all in a single Terragrunt stack