Issues referencing module outputs #11148
-
Hey! I'm trying to write a bicep definition that can handle either a single or multi (2) region deployment based on the provided params. For both single and multi-region deployments, the same template that defines the infra (app service plan, app service, slot, Redis, storage) for a region is called but by two separate modules. I use an int param called 'noRegions' to check if the secondary region should be created or not and this appears to work fine. The issue occurs when I try to reference the outputs from those two modules, specifically when the second module doesn't get run because I'm only deploying a single region. The main.bicep definition uses the 'noRegions' param I mentioned:
There are also 'resourceGroupCore' and 'primaryResourceGroup' resources groups defined, but they work fine. I then have separate modules for deploying the region infra:
'region_template.bicep' has this output that will be used to create azure endpoints in traffic manager: Here's the module for the tmp:
The tmp template itself is fine I think, I define the primary endpoint in the definition of the tmp resource itself, then have an optional tmp endpoint resource with condition If I run this with the 'noRegions' param set to '2' then it's fine, it deploys everything I want, but if it's set to '1', it errors saying that the 'rg-test-eastus' resource group could not be found. That resource group isn't being deployed because I want a single region deployment. So it appears that in order to reference the outputs from a module, that module has to have been run, you can't look at it and if it doesn't exist return a 'null' value like I'm trying to? Can anyone suggest a way around this please? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Did you consider just looping over the array for the 'region_template.bicep' ? instead of maintaining the secondary parameter. I was trying to think over the answer without testing it... I believe any of these options should work as you currently have it.
|
Beta Was this translation helpful? Give feedback.
-
I originally had the region_template.bicep loop by number of elements in the 'regions' array param, which worked for deploying the region resources, but I couldn't figure out how to properly reference the outputs from each iteration of the loop and pass them into modules as params. I found examples and discussion posts about it but none of the examples seemed to work. If you have any examples you think might work for me then I'd love to try them out! |
Beta Was this translation helpful? Give feedback.
Did you consider just looping over the array for the 'region_template.bicep' ? instead of maintaining the secondary parameter.
I was trying to think over the answer without testing it... I believe any of these options should work as you currently have it.
secEndpoint: secInfraDeploy.?outputs.?appSrvId
secEndpoint: noRegions == 2 ? secInfraDeploy.outputs.appSrvId : null