Skip to content

Can dependent terraform templates reference other template inputs in mock? #911

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

Open
NathanielRose opened this issue Oct 14, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@NathanielRose
Copy link

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
}
@yorinasub17 yorinasub17 added enhancement New feature or request help wanted labels Oct 14, 2019
@yorinasub17
Copy link
Contributor

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants