How to run particular NSG module in main. Bicep using azure devops yaml pipeline
Hi
My Code below.
nsg.bicep
@description('Location for all resources.')
param location string
@description('Name of the Network Security Group')
param networkSecurityGroupName string
param securityRules array = []
resource networkSecurityGroup1 'Microsoft.Network/networkSecurityGroups@2022-01-01' = {
name: networkSecurityGroupName
location: location
properties: {
securityRules: securityRules
}
}
//outputs
output nsgid string = networkSecurityGroup1.id
**vnet,bicep**
@description('Address Prefix for virtual network')
param VnetName string
@description('Address Prefixes for virtual network')
param vnetaddressPrefixes string
@description('Location of vnet')
param location string
@description('Address Prefix for virtual network')
param VMsubnet string
@description('Address Prefixes for virtual network')
param subnetnetaddressPrefixes string
//vnet decalaration
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-11-01' = {
name: VnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
vnetaddressPrefixes
]
}
subnets: [
{
name: VMsubnet
properties: {
addressPrefix: subnetnetaddressPrefixes
}
}
]
}
}
main.bicep
param location string = 'NorwayEast'
param VnetName string = 'test-vnet'
param vnetaddressprefix string = '10.0.0.0/16'
param subnetaddressprefix string = '10.0.0.0/24'
param subnetName string = 'test-subnet'
module vnet 'vnet.bicep' = {
name: 'VnetName-dep1'
params: {
location: location
VMsubnet: subnetName
VnetName: VnetName
subnetnetaddressPrefixes: subnetaddressprefix
vnetaddressPrefixes: vnetaddressprefix
}
}
module nsg1 'nsg.bicep' = if(deployNSG){
name: 'test-nsg-dep1'
params: {
location: location
networkSecurityGroupName: nsgname
securityRules: []
}
}
Can you please provide more information on what you are trying to accomplish here and what you need help with? This may be a better discussion post than an issue.
How to target particular module to deploy in azure bicep using azure devops pipeline
Like we need to run only NSG module in main bicep file
@Satishlucky Not sure if parts of your code is missing, but you have an if on the NSG module so what you should do is have a parameter named deployNSG that you can provide a value for in your deployment pipeline ...
param deployNSG bool = true
module nsg1 'nsg.bicep' = if (deployNSG) {
// ...
}
In your pipeline you'll have something like this:
az deployment create [...] --parameters deployNSG=true
And if you only want to deploy the NSG module and not the VNET module you would have to have something similar for that module:
param deployVNETbool = true
module vnet 'vnet.bicep' = if (deployVNET) {
// ...
}
Or you should just split the two modules into their own bicep files since there is no explicit dependency between them in your case.
Hi @Satishlucky, this issue has been marked as stale because it was labeled as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 3 days of this comment. Thanks for contributing to bicep! :smile: :mechanical_arm: