wasim
wasim

Reputation: 13

Where to find required properties for Bicep Azure resources

I'm trying to create resources on Azure Cloud using Bicep but im not sure where to find required properties

I'm using this link https://learn.microsoft.com/en-us/azure/templates/microsoft.compute/virtualmachines?pivots=deployment-language-bicep to look for VM resources properties but it doesn't say which one are required and which one are optional like Terraform registry

Upvotes: 0

Views: 581

Answers (1)

Jahnavi
Jahnavi

Reputation: 8018

Unlike terraform, there is no specific document for the required and optional parameters for creating a virtual machine using bicep.

One way to know is go through the terraform document and find out the required parameters and provide same in the Bicep resource properties.

Or check below few required properties for VM creation using bicep:

name, location, type, apiVersion, properties.storageProfile.imageReference.publisher,offer, sku, properties.osProfile.computerName, properties.osProfile.adminUsername, properties.osProfile.adminPassword, properties.hardwareProfile.vmSize, properties.networkProfile.networkInterfaces.id

And as suggested by @Peter Bons, look into property values for the above required properties.

I would recommend you look into below sample templates as all the required properties are provided here.

References:

  1. MSDoc template
  2. Windows VM & Linux VM

After checking above, below is the code which I tried in my environment using mandatory properties for VM creation.

param location string = resourceGroup().location
param vmName string
param adminUsername string
param adminPassword string
param vmSize string = 'Standard_B4ms'
param osVersion string = '2022-Datacenter-smalldisk'
var bastionHostName = 'bastion'
var bastionSubnet = '10.0.1.0/26'
var bastionSubnet = 'AzureBastionSubnet'
var bastionIPName = 'bastionIP'
var nsgName = 'NSG'
var computerName = '${vmName}-vm'
var nicName = '${vmName}-nic'
var osDiskName = '${vmName}-osdisk'
var vnetName = 'xxx'
var vnetPrefix = '10.0.0.0/16'
var subnetName = 'xxxx'
var subnetPrefix = '10.0.0.0/24'

resource nsg 'Microsoft.Network/networkSecurityGroups@2022-01-01' = {
  name: nsgName
  location: location
  properties: {
    securityRules: [
      {
        name: 'RDP-allow'
        properties: {
          description: ''
          protocol: 'Tcp'
          sourcePortRange: '*'
          destinationPortRange: '3389'
          sourceAddressPrefix: 'VirtualNetwork'
          destinationAddressPrefix: 'VirtualNetwork'
          access: 'Allow'
          priority: 200
          direction: 'Inbound'
        }
      }
    ]
  }
}

resource bastionIP 'Microsoft.Network/publicIPAddresses@2022-01-01' = {
  name: bastionIPName
  location: location
  sku: {
    name: 'Standard'
    tier: 'Regional'
  }
  properties: {f
    publicIPAllocationMethod: 'Static'
    publicIPAddressVersion: 'IPv4'
    idleTimeoutInMinutes: 4
  }
}

resource vnet 'Microsoft.Network/virtualNetworks@2022-01-01' = {
  name: vnetName
  location: location
  properties: {
    addressSpace: {
      addressPrefixes: [
        vnetPrefix
      ]
    }
    subnets: [
      {
        name: subnetName
        properties: {
          addressPrefix: subnetPrefix
          networkSecurityGroup: {
            id: nsg.id
          }
        }
      }
      {
        name: bastionSubnet
        properties: {
          addressPrefix: bastionSubnet
        }
      }
    ]
  }
}

resource nic 'Microsoft.Network/networkInterfaces@2022-01-01' = {
  name: nicName
  location: location
  properties: {
    networkSecurityGroup: {
      id: nsg.id
    }
    ipConfigurations: [
      {
        name: 'ipConfig1'
        properties: {
          privateIPAllocationMethod: 'Dynamic'
          subnet: {
            id: '${vnet.id}/subnets/${subnetName}'
          }
        }
      }
    ]
  }
}

resource bastionHost 'Microsoft.Network/bastionHosts@2022-01-01' = {
  name: bastionHostName
  location: location
  properties: {
    ipConfigurations: [
      {
        name: 'ipConfig'
        properties: {
          publicIPAddress: {
            id: bastionIP.id
          }
          subnet: {
            id: '${vnet.id}/subnets/${bastionSubnet}'
          }
        }
      }
    ]
  }
}

resource windowsVM 'Microsoft.Compute/virtualMachines@2022-03-01' = {
  name: computerName
  location: location
  properties: {
    hardwareProfile: {
      vmSize: vmSize
    }
    networkProfile: {
      networkInterfaces: [
        {
          id: nic.id
          properties: {
            deleteOption: 'Detach'
            primary: true
          }
        }
      ]
    }
    osProfile: {
      adminUsername: adminUsername
      adminPassword: adminPassword
      computerName: computerName
      windowsConfiguration: {
        enableAutomaticUpdates: true
        provisionVMAgent: true
      }
    }
    storageProfile: {
      imageReference: {
        publisher: 'MicrosoftWindowsServer'
        offer: 'WindowsServer'
        sku: osVersion
        version: 'latest'
      }
      osDisk: {
        name: osDiskName
        createOption: 'FromImage'
        osType: 'Windows'
        managedDisk: {
          storageAccountType: 'Standard_LRS'
        }
      }
    }
  }
}

Deployment succeeded:

enter image description here

enter image description here

Upvotes: 0

Related Questions