Can you use module deployment without referencing any parameters #6771
-
Hello everybody, since you were so helpful with my last two question here is another that has been bothering me: I have several bicep deployment files such as: Deploy_VPN_gateway.bicep Since modules provide a cool way to read Azure Key vault secrets and deploy several resources at the same time I would like have a single module file to deploy whole environment (vms, vnets, VPN etc): let say I have a
So first part is fine where I am deploying VMs which read secret from key vault. Ultimately the Idea is to deploy whole environment with just one file that reads other smaller bicep files, deploy resources concurrently, so some things get read from key vault others needed are read from parameter file.
Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 11 replies
-
@uky2019 You don't have to specify parameters if your template doesn't have any. Does your Deploy_VPN_gateway.bicep contain parameters? For example, when you want to deploy a resource group and you don't have parameters you can call this module without specifing parameters: ResourceGroup.bicep targetScope = 'subscription'
resource resNewRg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: 'my-rg'
location: 'westeurope'
} Orchestration using a module referring the ResourceGroup.bicep: targetScope = 'subscription'
module modNewRg 'ResourceGroup.bicep' = {
name: 'deploy-rg'
} |
Beta Was this translation helpful? Give feedback.
-
Ok I get it now, even though they are stated in parameters file and vpn bicep file you have to state them again in module you are using, I will test this tomorrow but thanks everybody. |
Beta Was this translation helpful? Give feedback.
-
I spoke too soon, I don't get it :D Ok I will post my exact scenario, lets say I am only trying to deploy VPN gateway with
I have stated parameters in {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"VPN": {
"value": {
"VPNVNETaddressPrefix": "XXX",
"vpngatewaysubprefix": "XXX",
"localnetworkgwprefix": "XXX",
"localnetworkgwipaddress": "XXX",
"S2SVPNsharedkey": "XXX"
}
}
}
} So my @description('VPN Gateway settings parameter input.')
param vpn object = {
VPNVNETaddressPrefix: 'XXX',
vpngatewaysubprefix: 'XXX',
localnetworkgwprefix: 'XXX',
localnetworkgwipaddress: 'XXX',
S2SVPNsharedkey: 'XXX'
}
var keyvaultname = 'KeyVault-Test'
resource keyvault 'Microsoft.KeyVault/vaults@2019-09-01' existing = {
name: keyvaultname
scope: Test-RG
}
module DeployVPNGateway 'vpngateway.bicep' = {
name: 'DeployVPNGateway'
params: {
???
???
}
} maybe it has something to do how module DeployVPNGateway 'vpngateway.bicep' = { I already state all my parameters in param vpn object
//I then use it to construct values in the bicep file
vpn.VPNVNETaddressPrefix
vpn.vpngatewaysubprefix:
vpn.localnetworkgwprefix:
vpn.localnetworkgwipaddress:
vpn.S2SVPNsharedkey:
//and so on in various parts of bicep I'm kind of clueless what needs to be done, maybe I am getting the logic of usage wrong... |
Beta Was this translation helpful? Give feedback.
-
Hi sorry to bother you all with my questions, but I am just trying to understand it. If you ask me it defeats the purpose of having one central parameter file with organized object structure, so other bicep files that read this parameter file can be more "clean" looking. @kevball2 I tried with your "Option 2" and it does work. I do not want to use "Option 1" as it bring mess into my bicep file with all that stated parameters, I want to use My goal mainly is (and why to even use "modules":
So my way of deploy looks like this: New-AzResourceGroupDeployment `
-Name 'Deploy_Environment' `
-TemplateFile '.\deployenvironment.bicep' `
-TemplateParameterFile '.\DeployEnvironment.parameters.json' `
-ResourceGroupName 'Test-RG' My param vpn object
resource vpnGateway 'Microsoft.Network/vpnGateways@2021-05-01' = {
name: 'vpngw-Name'
properties:{
connections:[
{
name:'connection1'
properties:{
sharedKey: vpn.S2SVPNsharedkey
}
}
]
}
} I would expect param vpn object
var keyvaultname = 'KeyVault-Test'
resource keyvault 'Microsoft.KeyVault/vaults@2019-09-01' existing = {
name: keyvaultname
scope: Test-RG
}
module DeployVPNGateway2 'Modules/Deploy_VPN_gateway2.bicep' = {
name: 'DeployVPNGateway2'
params: {
vpn: vpn
}
Maybe I need to rethink how I designed this whole deploy. |
Beta Was this translation helpful? Give feedback.
-
@brwilkinson just stumbled upon your project and this post. I’m new to bicep and was wondering if could explain this in more details? Basically if deploymentinfo contains sainfo store it and if not it’s an empty array var SAInfo = [for (sa, index) in storageInfo: { Here is where I get lost |
Beta Was this translation helpful? Give feedback.
@uky2019 You don't have to specify parameters if your template doesn't have any. Does your Deploy_VPN_gateway.bicep contain parameters?
For example, when you want to deploy a resource group and you don't have parameters you can call this module without specifing parameters:
ResourceGroup.bicep
Orchestration using a module referring the ResourceGroup.bicep: