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.08k stars 981 forks source link

include or reuse a "dependency" block? #1633

Open bitsofinfo opened 3 years ago

bitsofinfo commented 3 years ago

I'm trying to use the DRY principles expressed in https://github.com/gruntwork-io/terragrunt-infrastructure-modules-example and https://github.com/gruntwork-io/terragrunt-infrastructure-live-example

I am constantly having to re-declare dependency blocks in my live repo for low level dependencies such as outputs from an azure vnet module that I'm using. How can I avoid re-declaring this over and over?

the include block seems useful but I'm already using that with find_in_parent_folders()... and it only takes one path so I'm out of luck there. Perhaps generate in a top level terragrunt.hcl file but that won't work either, because i don't want this in all of my files, just a certain % of them.

dependency "vnet" {
  config_path = "../vnet"

  skip_outputs = true
  mock_outputs_allowed_terraform_commands = ["validate", "plan"]
  mock_outputs = {
    azurerm_resource_group = {
      name = "test-rg"
      location = "eastus"
    },
    azurerm_virtual_network = {
      name = "test-vnet"
      id = "/subscriptions/mock/resourceGroups/mock-rg/providers/Microsoft.Network/virtualNetworks/mock-vnet-001"
    },
    azurerm_nat_gateway = {
      id = "/subscriptions/mock/resourceGroups/mock-rg/providers/Microsoft.Network/natGateways/mock-nat-001"
    },
    non_bastion_subnet_ids = ["192.168.0.0/16"]
  }
}
yorinasub17 commented 3 years ago

This use case would be addressed in the imports enhancements proposed in this ticket: https://github.com/gruntwork-io/terragrunt/issues/1566

In that world, you should be able to leverage multi-level includes to achieve DRY of dependencies without breaking run-all (which read_terragrunt_config does - https://github.com/gruntwork-io/terragrunt/issues/1128).