Terragrunt: Can dependent terraform templates reference other template inputs in mock?

Created on 14 Oct 2019  ยท  1Comment  ยท  Source: gruntwork-io/terragrunt

I have a terraform template environment that is dependent on the inputs and outputs of various modules in a separate terraform template environment.

Here is the tree structure:

โ””โ”€โ”€ multiple-cluster
    โ”œโ”€โ”€ common-infra (base)
    |    โ”œโ”€โ”€ README.md
    |    โ”œโ”€โ”€ terragrunt.hcl
    |    โ”œโ”€โ”€ -common-infra-west (deployment)
    |    โ”‚    โ”œโ”€โ”€ main.tf
    |    โ”‚    โ”œโ”€โ”€ terragrunt.hcl
    |    โ”‚    โ”œโ”€โ”€ variables.tf
    |    โ”‚    โ”œโ”€โ”€ vnet.tf
    |    โ”‚    โ”œโ”€โ”€ keyvault.tf
    โ””โ”€โ”€ single-keyvault (base)
         โ”œโ”€โ”€ README.md
         โ”œโ”€โ”€ terragrunt.hcl
         โ””โ”€โ”€ single-keyvault-west (deployment)
              โ”œโ”€โ”€ main.tf
              โ”œโ”€โ”€ terragrunt.hcl
              โ”œโ”€โ”€ variables.tf
              โ”œโ”€โ”€ acr.tf

Here the single-keyvault environment has a dependency on the modules in the common-infra environment (specifically the keyvault). I need to obtain both the input config and output from the common-infra environment before deploying. I see ther are mock_outputs blocks for dependencies in terragrunt but is there also support for mock_inputs so the configuration from the other deployment is passed to this new terraform template environment?

Here is a sample terragrunt.hcl of the single-keyvault template

inputs = {
    #--------------------------------------------------------------
    # keyvault, vnet, and subnets are created seperately by azure-common-infra
    #--------------------------------------------------------------
    keyvault_resource_group = dependency.azure-common-infra.inputs.global_resource_group_name
    keyvault_name = dependency.azure-common-infra.inputs.keyvault_name
    address_space = dependency.azure-common-infra.inputs.address_space
    subnet_prefixes = dependency.azure-common-infra.inputs.subnet_prefixes
    vnet_name = dependency.azure-common-infra.inputs.vnet_name
    vnet_subnet_id = dependency.azure-common-infra.outputs.vnet_subnet_id

    #--------------------------------------------------------------
    # Cluster variables
    #--------------------------------------------------------------
    agent_vm_count = "3"
    agent_vm_size = "Standard_D4s_v3"

    cluster_name = "single-keyvault"
    dns_prefix = "single-keyvault"

    resource_group_name = "single-keyvault-rg"

    ssh_public_key = "<ssh public key>"

    service_principal_id = "${get_env("AZURE_CLIENT_ID", "")}"
    service_principal_secret = "${get_env("AZURE_CLIENT_SECRET", "")}"
}

include {
    path = "${path_relative_to_include()}/../azure-common-infra/terragrunt.hcl"
}

dependency "common-infra" {
  config_path = "../common-infra"

  mock_outputs = {
    # keyvault_name = "mock-Vault"
    # global_resource_group_name = "mock-rg"
    # address_space = "10.39.0.0/16"
    # subnet_prefixes = "10.39.0.0/24"
    # vnet_name = "mock-Vnet"
    vnet_subnet_id = "/subscriptions/<subscriptionId>/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mock-Subnet"
  }
  mock_outputs_allowed_terraform_commands = ["validate", "plan"]
  #Dependency on vnet_subnet_id
  skip_outputs = true
}
enhancement help wanted

Most helpful comment

Hi! This is actually in our roadmap, but hasn't been implemented yet. We've had this commented in various conversations, but it is good to finally have an issue that formally proposes the need.

Here are the relevant past conversations I can recall:

>All comments

Hi! This is actually in our roadmap, but hasn't been implemented yet. We've had this commented in various conversations, but it is good to finally have an issue that formally proposes the need.

Here are the relevant past conversations I can recall:

Was this page helpful?
0 / 5 - 0 ratings