Azure/BICEP - Please suggest me how can I can accomplish below scenarios. #4168
-
I have main.bicep calling two modules. The first module is for creating an RG and the rg name should have a proper naming standard. I have created a variable and created the custom name for that based on our standard. Since I need to use the same rg name again in other modules I haven't found any straightforward option so I declared it as output. Q1. Is that the right approach or is there any better way of doing the same?. Please find the code here ### main.bicep
### azresourcegroup.bicep
The next module which I am calling is to create a network watcher resource and the previously created rg.name must be an input for the same. But I am unable to switch the scope here to resource group context as bicep is not accepting first module output as an input parameter for it. It is only accepting if I declare another variable in the naming ### This is the error "This expression is being used in an assignment to the "scope" property of the "module" type, which requires a value that can be calculated at the start of the deployment. You are referencing a variable which cannot be calculated at the start ("hubrgnameout" -> "hubresourcegroup"). Properties of hubresourcegroup which can be calculated at the start include "name".bicep(BCP120)" Here is the code for the same
This code is working, if I define hubrgname as below. But it is not a clean way of doing that.
} I have two questions here. Q2. How I can do this more elegantly? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
I would recommend to simply bring the variable to your main.bicep var rgname = '${resourcerole}-${environmentName}-${rglocation}-rg' That way you can easily reference it where you need it. or what I prefer is: var deployment = '${resourcerole}-${environmentName}-${rglocation}'
var rgName = '${deployment}-rg' Here your deployment states your naming standard that will be the base for naming other resources. So it's easily to derive the rgname if you know the deployment. This is something you can view in these templates, however look for: var Deployment = '${Prefix}-${Global.OrgName}-${Global.Appname}-${Environment}${DeploymentID}' |
Beta Was this translation helpful? Give feedback.
-
Hi, Could you please help me with this scenario and thanks. From main. bicep I am calling many modules and my plan is to create a vnet and then subnet using a loop but I can't emit provisioned vnet as a resource in the module output. I am getting this error "The property "parent" expected a value of type "resource" but the provided value is of type "object".bicep(BCP036)". Please let me is there any way I can declare the output as a resource-type object , currently it only supports string, array, object, etc.. MAIN.BICEP
var vnetout = primaryhubvnet.outputs.vnetresource** Please pay attention to this vnetout which is the output of the below module. Basically, I need to reference the provisioned vnet resource as an input of another module call for provisioning subnet. the called aznetworking.bicep is below
output vnetresource object = vnet Now in the main. bicep file, I am calling a module to create subnets.
Here it won't accept the provisioned vnet as a resource and gives the below error. Is that something planning to release or the way I conceptualize it wrong? thanks The property "parent" expected a value of type "resource" but the provided value is of type "object".bicep(BCP036) ` |
Beta Was this translation helpful? Give feedback.
I would recommend to simply bring the variable to your main.bicep
That way you can easily reference it where you need it.
or what I prefer is:
Here your deployment states your naming standard that will be the base for naming other resources. So it's easily to derive the rgname if you know the deployment.
This is something you can view in these templates, however look for: