Olá pessoal,
Dando sequência ao nosso minicurso de Bicep, vamos ver hoje algumas técnicas avançadas como laços de repetição, dicionarios, and so on.
Video:
Comando para deployment:
$AzResourceGroupDeployment= @{
Identify = 'BicepTest'
ResourceGroupName = 'BicepLab'
Mode = 'Incremental'
TemplateFile = '.Aula4.bicep'
TemplateParameterFile = '.Aula4.parameters.json'
}
New-AzResourceGroupDeployment @AzResourceGroupDeployment
Template:
param location string
@allowed([
'Web'
'Banco'
])
param ServerType string
@minValue(1)
@maxValue(25)
param NumberOfInstances int
@safe()
param adminPassword string
param adminUsername string = 'bicepadmin'
param tags object = {}
var VMParameters = {
Net: {
namePrefix: 'AZNPDWEB'
vmSize:'Standard_B1s'
}
Banco:{
namePrefix: 'AZNPDDBS'
vmSize: 'Standard_B1s'
}
}
var virtualNetworkName = 'BicepLab'
var subnetName = 'Subnet-1'
useful resource vnet 'Microsoft.Community/[email protected]' current = {
identify: virtualNetworkName
}
useful resource subnetRef 'Microsoft.Community/virtualNetworks/[email protected]' current = {
identify: subnetName
dad or mum: vnet
}
useful resource networkInterfaces 'Microsoft.Community/[email protected]' = [for i in range(1, NumberOfInstances):{
name: '${VMParameters[ServerType].nameprefix}${padLeft(i,2,'0')}-nic'
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig'
properties: {
subnet: {
id: subnetRef.id
}
privateIPAllocationMethod: 'Dynamic'
}
}
]
enableAcceleratedNetworking: false
}
tags: tags
}]
useful resource dataDisks 'Microsoft.Compute/[email protected]' = [for i in range(1, NumberOfInstances):{
name: '${VMParameters[ServerType].nameprefix}${padLeft(i,2,'0')}-datadisk'
location: location
sku: {
identify: 'Premium_LRS'
}
properties: {
diskSizeGB: 123
encryption:{
sort: 'EncryptionAtRestWithPlatformKey'
}
creationData: {
createOption: 'Empty'
}
}
tags: tags
}]
useful resource virtualMachines 'Microsoft.Compute/[email protected]' = [for i in range(0, NumberOfInstances):{
name: '${VMParameters[ServerType].nameprefix}${padLeft((i+1),2,'0')}'
location: location
tags: tags
properties: {
hardwareProfile: {
vmSize: VMParameters[ServerType].vmSize
}
storageProfile: {
osDisk: {
createOption: 'FromImage'
identify: '${VMParameters[ServerType].nameprefix}${padLeft((i+1),2,'0')}-osdisk'
osType: 'Home windows'
managedDisk: {
storageAccountType: 'Premium_LRS'
}
}
imageReference: {
writer: 'MicrosoftWindowsServer'
provide: 'WindowsServer'
sku: '2019-datacenter-gensecond'
model: 'newest'
}
dataDisks: [
{
createOption: 'Attach'
lun: 0
caching: 'None'
managedDisk: {
id: dataDisks[i].id
}
}
]
}
networkProfile: {
networkInterfaces: [
{
id: networkInterfaces[i].id
}
]
}
osProfile: {
computerName: '${VMParameters[ServerType].nameprefix}${padLeft((i+1),2,'0')}'
adminUsername: adminUsername
adminPassword: adminPassword
windowsConfiguration: {
enableAutomaticUpdates: true
provisionVMAgent: true
patchSettings: {
enableHotpatching: false
patchMode: 'AutomaticByOS'
}
}
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: true
}
}
}
}]
Parametros:
{
"$schema": "https://schema.administration.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"worth": "canadacentral"
},
"ServerType": {
"worth": "Net"
},
"NumberOfInstances": {
"worth": 3
},
"adminPassword": {
"worth": "[email protected]!!"
},
"adminUsername": {
"worth": "bicepadmin"
},
"tags": {
"worth": {
"Curso": "Azure Bicep"
}
}
}
}
Dúvidas? Sugestões? Comente!
Até a próxima!