Skip to main content
Knowledge Base

Mock_Outputs Not Working

Answer

I am still relatively new to Terragrunt and am having difficulty getting the `mock_outputs` function within my `Dependency` block to function correctly. We are using Terraform within a Gitlab CI/CD pipeline to deploy our code. My pipeline's file structure is below with the `gateway/terragrunt.hcl` and `keyvault/terragrunt.hcl` source their respective modules. ``` root ├── terragrunt.hcl ├── vars.yaml ├── eastus ├── services ├── sdm ├── gateways └── terragrunt.hcl ├── keyvault └── terragrunt.hcl ``` <br> I am needing to utilize outputs from the **_gateways_** module to be injected into the **_keyvault_** module during the pipeline run. Therefore, - I have set a `dependencies` block to allow the **_gateways_** module to run before the **_keyvault_** module. - I have set a `dependency` block to pass the **_gateways_** outputs to the **_keyvault_** inputs. - Since this is a completely new setup where no infrastructure has been deployed, I've elected to use `mock_outputs` to handle the dependency outputs in the **_keyvault_** module. The code for the **_keyvault_** terragrunt file is below: <br> ```terragrunt terraform { source = "...." } # Include all settings from the root terragrunt.hcl file include { path = find_in_parent_folders() } locals { environment = "snd" # Choices here are: snd, dev, prd vars = yamldecode(file(find_in_parent_folders("vars.yaml"))) } dependencies { paths = ["../gateways"] } dependency "sdmvms_depends" { config_path = "../gateways" mock_outputs = { kv_prefix = "temp-dummy-prefix" vm_pid = "temp-dummy-pid" } mock_outputs_allowed_terraform_commands = ["init", "validate", "plan"] } inputs = merge( yamldecode(file("${find_in_parent_folders("global.yaml", "empty.yaml")}")), yamldecode(file("${find_in_parent_folders("vars.yaml", "empty.yaml")}")), { region = local.region env = local.environment subpx_keyvault = dependency.sdmvms_depends.outputs.kv_prefix vm_principalid = dependency.sdmvms_depends.outputs.vm_pid tags = {....} } ) ``` <br> What's occurring is that the `run-all plan` phase errors out with the following: <br> ``` ╷ │ Error: expected "access_policy.0.object_id" to be a valid UUID, got temp-dummy-pid │ │ with azurerm_key_vault.sdm_keyvault, │ on keyvault.tf line 34, in resource "azurerm_key_vault" "sdm_keyvault": │ 34: object_id = var.vm_principalid │ ╵ ``` <br> Have done a ton of Googling on this issue and can't find what it is I'm doing wrong. I've tried utilizing several other functions within the `dependency` block (`skip_outputs = true`, `mock_outputs_merge_strategy_with_state`), but with no luck in getting things past PLAN. Any insight or suggestions would be greatly appreciated. Many thanks! --- <ins datetime="2022-05-06T18:11:43Z"> <p><a href="https://support.gruntwork.io/hc/requests/108565">Tracked in ticket #108565</a></p> </ins>

The `mock_outputs` is actually working correctly here to feed to `azurerm_key_vault`. In the error, you will see that it is properly using the mock value of `temp-dummy-pid`. However, the issue is that the terraform module you are calling can't accept the mock value for the input you are setting. This is expected if the underlying module uses a data source or has internal validation on the input value (which is what is happening in this case). You need to update the mock value to ensure it passes all the validation that the module expects. In this case, based on the error message, I believe you can resolve this if you update `temp-dummy-pid` to be a valid UUID, which you can generate using python: ``` python3 -c "import uuid; print(uuid.uuid4())" ```