SlideShare a Scribd company logo
Automatizzare la creazione
di risorse con ARM
Template e Powershell
Marco Obinu - @OmegaMadLab
Thanks to
Who am I?
Marco Obinu
@OmegaMadLab
marco.obinu@omegamadlab.com
http://www.omegamadlab.com
https://github.com/OmegaMadLab
https://www.linkedin.com/in/marco-obinu-omegamadlab/
https://www.youtube.com/channel/UCpkBeQSscC1iBvpNP4VNTKQ
• Geek to the bone 
• Azure Solution Architect Expert
Advisory Engineer
SoftJam S.p.A.
AGENDA
• Introduzione al mondo IaC in Azure con ARM Templates
• PowerShell DSC
• Deployment di una VM
L’approccio next-next-next non è più cosa…
TEST
Infrastructure as Code
• Modello dichiarativo
• Version Control
• Automazione
• CI/CD
• Evita derive di configurazione
• Traccia le dipendenze delle risorse
• Ambienti riproducibili
• Soluzione IaC di Azure
• IaaS, PaaS, Serverless
• Raggruppa risorse e gestisce
dipendenze
• Distribuisce, aggiorna, rimuove
in un’unica operazione
• Un template per più ambienti
Azure Resource Manager templates
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"functions": []
"resources": [],
"outputs": {}
}
Struttura di un template
Parametri
Schema:
"parameters": {
"<parameter-name>" : {
"type" : "<type-of-parameter-value>",
"defaultValue": "<default-value-of-parameter>",
"allowedValues": [ "<array-of-allowed-values>" ],
"minValue": <minimum-value-for-int>,
"maxValue": <maximum-value-for-int>,
"minLength": <min-length-for-string-or-array>,
"maxLength": <max-length-for-string-or-array>,
"metadata": {
"description": "<description-of-the parameter>"
}
}
}
Esempio:
"parameters": {
"storageSKU": {
"type": "string",
"allowedValues": [
"Standard_LRS",
"Premium_LRS"
],
"defaultValue": "Standard_LRS",
"metadata": {
"description": "The tier of storage account."
}
}
}
Utilizzo all’interno del template:
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "[parameters('storageSKU')]"
},
...
}
]
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-parameters
Array and object Compare Resource String
array equals listAccountSas base64 split
coalesce less listKeys base64ToJson startsWith
concat lessOrEquals listSecrets base64ToString string
contains greater list* concat substring
createArray greaterOrEquals providers contains take
empty Deployment reference dataUri toLower
first deployment resourceGroup dataUriToString toUpper
intersection environment resourceId empty trim
json parameters subscription endsWith uniqueString
last variables Numeric first uri
length Logical add format uriComponent
min and copyIndex guid uriComponentToString
max bool div indexOf utcNow
range if float last
skip not int lastIndexOf
take or min length
union max newGuid
mod padLeft
mul replace
sub skip
ARM Template functions
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"functions": []
"resources": [],
"outputs": {}
}
Struttura di un template
Variabili
Schema:
"variables": {
"<variable-name>": "<variable-value>",
"<variable-name>": {
<variable-complex-type-value>
},
"<variable-object-name>": {
"copy": [
{
"name": "<name-of-array-property>",
"count": <number-of-iterations>,
"input": {
<properties-to-repeat>
}
}
]
},
"copy": [
{
"name": "<variable-array-name>",
"count": <number-of-iterations>,
"input": {
<properties-to-repeat>
}
}
]
}
Esempio:
"variables": {
"VmName": "Server01",
"ConcatExample": [concat(parameters('size'), 'string2')]
}
Utilizzo all’interno del template:
"resources": [
{
"type": "Microsoft.Compute/VirtualMachine",
"name": [variables('VmName'),
"property": [variables('ConcatExample'),
...
}
]
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-variables
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"functions": []
"resources": [],
"outputs": {}
}
Struttura di un template
Custom functions
Utilizzo all’interno del template:
"resources": [
{
"name":
"[contoso.uniqueName(parameters('storageNamePrefix'))]",
"type": "Microsoft.Storage/storageAccounts",
…
}
]
Esempio:
"functions": [
{
"namespace": "contoso",
"members": {
"uniqueName": {
"parameters": [
{
"name": "namePrefix",
"type": "string"
}
],
"output": {
"type": "string",
"value":
"[concat(toLower(parameters('namePrefix')),
uniqueString(resourceGroup().id))]"
}
}
}
}
],
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates#functions
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"functions": []
"resources": [],
"outputs": {}
}
Struttura di un template
Risorse
Schema:
"resources": [
{
"condition": "<true-to-deploy-this-resource>",
"apiVersion": "<api-version-of-resource>",
"type": "<resource-provider-namespace/resource-type-name>",
"name": "<name-of-the-resource>",
"location": "<location-of-resource>",
"tags": {
"<tag-name1>": "<tag-value1>“
},
"comments": "<your-reference-notes>",
"copy": {
"name": "<name-of-copy-loop>",
"count": <number-of-iterations>,
"mode": "<serial-or-parallel>",
"batchSize": <number-to-deploy-serially>
},
"dependsOn": [
"<array-of-related-resource-names>"
],
"properties": {
…
}
"resources": []
}
]
Esempio:
"resources": [
{
"name": "[variables('storageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2016-01-01",
"location": "[resourceGroup().location]",
"comments": "This storage account is used to store the VM
disks.",
...
}
]
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-resources
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"functions": []
"resources": [],
"outputs": {}
}
Struttura di un template
Output
Schema:
"outputs": {
"<outputName>" : {
"type" : "<type-of-output-value>",
"value": "<output-value-expression>"
}
}
Esempio:
"outputs": {
"resourceID": {
"type": "string",
"value":
"[resourceId('Microsoft.Network/publicIPAddresses',
parameters('publicIPAddresses_name'))]"
}
}
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-outputs
Strumenti del mestiere
• Visual Studio Code
• Estensione PowerShell
• Estensione Azure Tools
• PowerShell con modulo Az o Azure Cloud Shell
• Repo per templates/artifacts
• ARM Template Reference  https://docs.microsoft.com/en-us/azure/templates/
Aiutati, che il ciel ti aiuta!
• Generazione script di automazione da portale
• Azure Quickstart Templates
• https://azure.microsoft.com/en-us/resources/templates/
• https://github.com/Azure/azure-quickstart-templates
• Reverse engineering
Deployment
• Tramite portale
• Da GitHub 
• Da PowerShell, Azure CLI, Cloud Shell…
"resources": [
{
"apiVersion": "2016-01-01",
"type": "Microsoft.Storage/storageAccounts",
"name": "mystorageaccount",
…
]
PUT
https://management.azure.com/subscriptions/{
subscriptionId}/resourceGroups/{resourceGrou
pName}/providers/Microsoft.Storage/storageAc
counts/mystorageaccount?api-version=2016-01-
01
REQUEST BODY
{
PowerShell Desired State Configuration
• Sistema di configuration management basato su PowerShell
• Funziona sia su Windows che su OSS
• Elementi chiave:
• Configurazioni  componente dichiarativa
• Risorse  componente imperativa
• Tre funzioni: Test, Get, Set
• Reperibili da PSGallery  Find-DscResource
• Local Configuration Manager
• PUSH e PULL
• Integrazione negli ARM template  https://docs.microsoft.com/en-
us/azure/virtual-machines/extensions/dsc-template
Configurazione DSC di esempio
Configuration WebsiteTest {
# Import the module that contains the resources we're using
Import-DscResource -ModuleName PsDesiredStateConfiguration
# The Node statement specifies which targets this configuration will be applied to.
Node 'localhost' {
# The first resource block ensures that the Web-Server (IIS) feature is enabled.
WindowsFeature WebServer {
Ensure = "Present"
Name = "Web-Server"
}
# The second resource block ensures that the website content copied to the website root folder.
File WebsiteContent {
Ensure = 'Present'
SourcePath = 'c:testindex.htm'
DestinationPath = 'c:inetpubwwwroot'
}
}
}
Procedura di integrazione in ARM template
Creare
configurazione DSC
Creare uno ZIP
contenente
configurazione e
risorse
Caricare lo ZIP su un
repository
Inserire estensione
nell’ARM Template
Risorsa PowerShell DSC
{
"name": "Microsoft.Powershell.DSC",
"type": " Microsoft.Compute/virtualMachines/extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2018-06-30",
"dependsOn": [],
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.77",
"autoUpgradeMinorVersion": true,
"settings": {
"configuration": {
"url": "http://validURLToConfigLocation",
"script": "ConfigurationScript.ps1",
"function": "ConfigurationFunction"
},
"configurationArguments": {
"argument1": "Value1",
"argument2": "Value2"
},
},
"protectedSettings": {
"configurationArguments": {
"parameterOfTypePSCredential1": {
"userName": "UsernameValue1",
"password": "PasswordValue1"
},
}
}
}
Custom Script Extensions
{
"apiVersion": "2018-06-01",
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "config-app",
"location": "[resourceGroup().location]",
"dependsOn": [],
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.9",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"script location"
],
"timestamp": 12345678,
},
"protectedSettings": {
"commandToExecute": "myExecutionCommand",
"storageAccountName": "myStorageAccountName",
"storageAccountKey": "myStorageAccountKey"
}
}
}
Azure Day Reloaded 2019 - ARM Template workshop
Compiti a casa 
• Demo di questa sessione
• https://github.com/OmegaMadLab/AzDayReloaded-ArmTemplateWorkshop
• StartingWithArmTemplates
• https://github.com/OmegaMadLab/StartingWithArmTemplates
• Azure Quickstart Template gallery su GitHub
• https://github.com/Azure/azure-quickstart-templates
• ARM template SQL IaaS complesso (DSC + CSE con autenticazione di dominio)
• https://github.com/OmegaMadLab/OptimizedSqlVm
• Esempi PowerShell DSC:
• https://github.com/OmegaMadLab/DSCDemo
• PowerShell DSC su Microsoft Virtual Academy
• Base: https://channel9.msdn.com/Series/Getting-Started-with-PowerShell-DSC
• Advanced: https://channel9.msdn.com/Series/Advanced-PowerShell-DSC-and-Custom-Resources?l=3DnsS2H1_1504984382
• Sessione BRK 4026 Ignite 2018 – Tips, Tricks, and real world example to build and manage ARM templates
• Video: https://www.youtube.com/watch?v=cdkDhR3HFiI
• Demo: https://github.com/vladimirjoanovic/ignite2018/tree/master/BRK4026
• Sessione BRK3233 Ignite 2019 - What’s new with Azure Resource Manager (ARM) templates for your deployments
• Video: https://medius.studios.ms/video/asset/HIGHMP4/IG19-BRK3233
Azure Day Reloaded 2019 - ARM Template workshop
Thank You!!!
Thanks to

More Related Content

PPTX
CCI2018 - Automatizzare la creazione di risorse con ARM template e PowerShell
PPTX
Azure arm templates
PDF
GitBucket: The perfect Github clone by Scala
PDF
20151010 my sq-landjavav2a
PPTX
MWLUG 2015 - AD114 Take Your XPages Development to the Next Level
PPTX
More Cache for Less Cash (DevLink 2014)
PDF
Immutable Deployments with AWS CloudFormation and AWS Lambda
PPTX
Inside Azure Diagnostics (DevLink 2014)
CCI2018 - Automatizzare la creazione di risorse con ARM template e PowerShell
Azure arm templates
GitBucket: The perfect Github clone by Scala
20151010 my sq-landjavav2a
MWLUG 2015 - AD114 Take Your XPages Development to the Next Level
More Cache for Less Cash (DevLink 2014)
Immutable Deployments with AWS CloudFormation and AWS Lambda
Inside Azure Diagnostics (DevLink 2014)

What's hot (20)

PPTX
Infrastructure as Code in AWS using Cloudformation
PDF
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
PDF
Webpack Encore - Asset Management for the rest of us
PPTX
Architecting world class azure resource manager templates
PPTX
Deployment with Ansible Tower, management with Scalr
PPTX
Rapid API development examples for Impress Application Server / Node.js (jsfw...
PDF
High Performance Hibernate JavaZone 2016
PDF
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
PDF
JFokus 2011 - Running your Java EE 6 apps in the Cloud
PPTX
Inside Azure Diagnostics
PDF
High-Performance Hibernate - JDK.io 2018
PDF
Infinispan,Lucene,Hibername OGM
PDF
April 2010 - JBoss Web Services
PPTX
Working with PowerVC via its REST APIs
PDF
Running your Java EE 6 Applications in the Cloud
PPTX
SpringBoot with MyBatis, Flyway, QueryDSL
PPTX
Faster Java EE Builds with Gradle
PDF
Running your Java EE 6 applications in the clouds
PDF
Modular Test-driven SPAs with Spring and AngularJS
ODP
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
Infrastructure as Code in AWS using Cloudformation
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
Webpack Encore - Asset Management for the rest of us
Architecting world class azure resource manager templates
Deployment with Ansible Tower, management with Scalr
Rapid API development examples for Impress Application Server / Node.js (jsfw...
High Performance Hibernate JavaZone 2016
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JFokus 2011 - Running your Java EE 6 apps in the Cloud
Inside Azure Diagnostics
High-Performance Hibernate - JDK.io 2018
Infinispan,Lucene,Hibername OGM
April 2010 - JBoss Web Services
Working with PowerVC via its REST APIs
Running your Java EE 6 Applications in the Cloud
SpringBoot with MyBatis, Flyway, QueryDSL
Faster Java EE Builds with Gradle
Running your Java EE 6 applications in the clouds
Modular Test-driven SPAs with Spring and AngularJS
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
Ad

Similar to Azure Day Reloaded 2019 - ARM Template workshop (20)

PPTX
Deploy and Manage the Infrastructure Using Azure Resource Manager
PPTX
IaaS with ARM templates for Azure
PPTX
Azure Resource Manager - Technical Primer
PPTX
Azure Resource Manager (ARM) Template - A Beginner Guide for Developers
PPTX
Presentation ARM-Terraform DevOps Infrastructure as Code
PPTX
Global Azure Bootcamp 2018 - Azure Resource Manager (ARM)
PPTX
Azure deployments and ARM templates
PDF
Azure ARM Templates 101
PPTX
Azure ARM’d and Ready
PPTX
Azure Resource Manager Templates
PPTX
DevOps in Azure :Azure Resource Manager
PPTX
Getting Started with IaC in Azure using ARM Template
PPTX
CCI2017 - Azure Virtual Machine & Networking - Marco Gumini
PPTX
Aos canadian tour (YOW) @energizedtech - Manage AzureRM with powershell
PPTX
Azure ARM Template by Techserverglobal.pptx
PPTX
Deploying a website in Azure using ARM templates
PDF
Azure Infrastructure as Code: With ARM templates and Bicep 1st Edition Henry ...
PPTX
06_DP_300T00A_Automate.pptx
PPTX
Henry been azure resource manager - inside out
PDF
Azure Resource Manager (ARM) Templates
Deploy and Manage the Infrastructure Using Azure Resource Manager
IaaS with ARM templates for Azure
Azure Resource Manager - Technical Primer
Azure Resource Manager (ARM) Template - A Beginner Guide for Developers
Presentation ARM-Terraform DevOps Infrastructure as Code
Global Azure Bootcamp 2018 - Azure Resource Manager (ARM)
Azure deployments and ARM templates
Azure ARM Templates 101
Azure ARM’d and Ready
Azure Resource Manager Templates
DevOps in Azure :Azure Resource Manager
Getting Started with IaC in Azure using ARM Template
CCI2017 - Azure Virtual Machine & Networking - Marco Gumini
Aos canadian tour (YOW) @energizedtech - Manage AzureRM with powershell
Azure ARM Template by Techserverglobal.pptx
Deploying a website in Azure using ARM templates
Azure Infrastructure as Code: With ARM templates and Bicep 1st Edition Henry ...
06_DP_300T00A_Automate.pptx
Henry been azure resource manager - inside out
Azure Resource Manager (ARM) Templates
Ad

More from Marco Obinu (17)

PPTX
Securing an Azure full-PaaS architecture - Data saturday #0001 Pordenone
PPTX
Implement a disaster recovery solution for your on-prem SQL with Azure? Easy!
PPTX
Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...
PPTX
Infrastructure as Code on Azure: Show your Bicep!
PPTX
Sql Start! 2020 - SQL Server Lift & Shift su Azure
PPTX
SQL Server Lift & Shift on Azure - SQL Saturday 921
PPTX
SQL Server Disaster Recovery on Azure - SQL Saturday 921
PPTX
Azure VM 101 - HomeGen by CloudGen Verona - Marco Obinu
PPTX
Global Azure Virtual 2020 What's new on Azure IaaS for SQL VMs
PPTX
Azure Day Reloaded 2019 - React to infrastructure events with Azure Monitor
PPTX
Sql Saturday 895 - SQL Server e PowerShell: from Zero to Hero
PPTX
Automazione serverless con Azure Functions e PowerShell - Marco Obinu - DevOp...
PDF
Azure Saturday Pordenone 2019 - Reagire agli eventi di infrastruttura con Azu...
PPTX
SQL Saturday 871 - Sardegna 2019 - SQL Server DR on Azure
PPTX
SQL Start! 2019 - Ancona - Distribuisci ed amministra le tue istanze SQL Serv...
PPTX
Global Azure BootCamp 2019 - Verona - Ottimizzazione delle VM SQL Server su A...
PPTX
Global Azure BootCamp 2019 - Verona - Azure Cloud Shell
Securing an Azure full-PaaS architecture - Data saturday #0001 Pordenone
Implement a disaster recovery solution for your on-prem SQL with Azure? Easy!
Infrastructure as Code on Azure - Show your Bicep! v0.2 - .NetConf 2020 by Do...
Infrastructure as Code on Azure: Show your Bicep!
Sql Start! 2020 - SQL Server Lift & Shift su Azure
SQL Server Lift & Shift on Azure - SQL Saturday 921
SQL Server Disaster Recovery on Azure - SQL Saturday 921
Azure VM 101 - HomeGen by CloudGen Verona - Marco Obinu
Global Azure Virtual 2020 What's new on Azure IaaS for SQL VMs
Azure Day Reloaded 2019 - React to infrastructure events with Azure Monitor
Sql Saturday 895 - SQL Server e PowerShell: from Zero to Hero
Automazione serverless con Azure Functions e PowerShell - Marco Obinu - DevOp...
Azure Saturday Pordenone 2019 - Reagire agli eventi di infrastruttura con Azu...
SQL Saturday 871 - Sardegna 2019 - SQL Server DR on Azure
SQL Start! 2019 - Ancona - Distribuisci ed amministra le tue istanze SQL Serv...
Global Azure BootCamp 2019 - Verona - Ottimizzazione delle VM SQL Server su A...
Global Azure BootCamp 2019 - Verona - Azure Cloud Shell

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Cloud computing and distributed systems.
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
Teaching material agriculture food technology
PPTX
Spectroscopy.pptx food analysis technology
PDF
KodekX | Application Modernization Development
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
sap open course for s4hana steps from ECC to s4
Building Integrated photovoltaic BIPV_UPV.pdf
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Cloud computing and distributed systems.
The AUB Centre for AI in Media Proposal.docx
Teaching material agriculture food technology
Spectroscopy.pptx food analysis technology
KodekX | Application Modernization Development
Mobile App Security Testing_ A Comprehensive Guide.pdf
20250228 LYD VKU AI Blended-Learning.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Spectral efficient network and resource selection model in 5G networks
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Azure Day Reloaded 2019 - ARM Template workshop

  • 1. Automatizzare la creazione di risorse con ARM Template e Powershell Marco Obinu - @OmegaMadLab
  • 3. Who am I? Marco Obinu @OmegaMadLab marco.obinu@omegamadlab.com http://www.omegamadlab.com https://github.com/OmegaMadLab https://www.linkedin.com/in/marco-obinu-omegamadlab/ https://www.youtube.com/channel/UCpkBeQSscC1iBvpNP4VNTKQ • Geek to the bone  • Azure Solution Architect Expert Advisory Engineer SoftJam S.p.A.
  • 4. AGENDA • Introduzione al mondo IaC in Azure con ARM Templates • PowerShell DSC • Deployment di una VM
  • 5. L’approccio next-next-next non è più cosa… TEST
  • 6. Infrastructure as Code • Modello dichiarativo • Version Control • Automazione • CI/CD • Evita derive di configurazione • Traccia le dipendenze delle risorse • Ambienti riproducibili
  • 7. • Soluzione IaC di Azure • IaaS, PaaS, Serverless • Raggruppa risorse e gestisce dipendenze • Distribuisce, aggiorna, rimuove in un’unica operazione • Un template per più ambienti Azure Resource Manager templates
  • 9. Parametri Schema: "parameters": { "<parameter-name>" : { "type" : "<type-of-parameter-value>", "defaultValue": "<default-value-of-parameter>", "allowedValues": [ "<array-of-allowed-values>" ], "minValue": <minimum-value-for-int>, "maxValue": <maximum-value-for-int>, "minLength": <min-length-for-string-or-array>, "maxLength": <max-length-for-string-or-array>, "metadata": { "description": "<description-of-the parameter>" } } } Esempio: "parameters": { "storageSKU": { "type": "string", "allowedValues": [ "Standard_LRS", "Premium_LRS" ], "defaultValue": "Standard_LRS", "metadata": { "description": "The tier of storage account." } } } Utilizzo all’interno del template: "resources": [ { "type": "Microsoft.Storage/storageAccounts", "sku": { "name": "[parameters('storageSKU')]" }, ... } ] https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-parameters
  • 10. Array and object Compare Resource String array equals listAccountSas base64 split coalesce less listKeys base64ToJson startsWith concat lessOrEquals listSecrets base64ToString string contains greater list* concat substring createArray greaterOrEquals providers contains take empty Deployment reference dataUri toLower first deployment resourceGroup dataUriToString toUpper intersection environment resourceId empty trim json parameters subscription endsWith uniqueString last variables Numeric first uri length Logical add format uriComponent min and copyIndex guid uriComponentToString max bool div indexOf utcNow range if float last skip not int lastIndexOf take or min length union max newGuid mod padLeft mul replace sub skip ARM Template functions
  • 12. Variabili Schema: "variables": { "<variable-name>": "<variable-value>", "<variable-name>": { <variable-complex-type-value> }, "<variable-object-name>": { "copy": [ { "name": "<name-of-array-property>", "count": <number-of-iterations>, "input": { <properties-to-repeat> } } ] }, "copy": [ { "name": "<variable-array-name>", "count": <number-of-iterations>, "input": { <properties-to-repeat> } } ] } Esempio: "variables": { "VmName": "Server01", "ConcatExample": [concat(parameters('size'), 'string2')] } Utilizzo all’interno del template: "resources": [ { "type": "Microsoft.Compute/VirtualMachine", "name": [variables('VmName'), "property": [variables('ConcatExample'), ... } ] https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-variables
  • 14. Custom functions Utilizzo all’interno del template: "resources": [ { "name": "[contoso.uniqueName(parameters('storageNamePrefix'))]", "type": "Microsoft.Storage/storageAccounts", … } ] Esempio: "functions": [ { "namespace": "contoso", "members": { "uniqueName": { "parameters": [ { "name": "namePrefix", "type": "string" } ], "output": { "type": "string", "value": "[concat(toLower(parameters('namePrefix')), uniqueString(resourceGroup().id))]" } } } } ], https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates#functions
  • 16. Risorse Schema: "resources": [ { "condition": "<true-to-deploy-this-resource>", "apiVersion": "<api-version-of-resource>", "type": "<resource-provider-namespace/resource-type-name>", "name": "<name-of-the-resource>", "location": "<location-of-resource>", "tags": { "<tag-name1>": "<tag-value1>“ }, "comments": "<your-reference-notes>", "copy": { "name": "<name-of-copy-loop>", "count": <number-of-iterations>, "mode": "<serial-or-parallel>", "batchSize": <number-to-deploy-serially> }, "dependsOn": [ "<array-of-related-resource-names>" ], "properties": { … } "resources": [] } ] Esempio: "resources": [ { "name": "[variables('storageAccountName')]", "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2016-01-01", "location": "[resourceGroup().location]", "comments": "This storage account is used to store the VM disks.", ... } ] https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-resources
  • 18. Output Schema: "outputs": { "<outputName>" : { "type" : "<type-of-output-value>", "value": "<output-value-expression>" } } Esempio: "outputs": { "resourceID": { "type": "string", "value": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_name'))]" } } https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-outputs
  • 19. Strumenti del mestiere • Visual Studio Code • Estensione PowerShell • Estensione Azure Tools • PowerShell con modulo Az o Azure Cloud Shell • Repo per templates/artifacts • ARM Template Reference  https://docs.microsoft.com/en-us/azure/templates/
  • 20. Aiutati, che il ciel ti aiuta! • Generazione script di automazione da portale • Azure Quickstart Templates • https://azure.microsoft.com/en-us/resources/templates/ • https://github.com/Azure/azure-quickstart-templates • Reverse engineering
  • 21. Deployment • Tramite portale • Da GitHub  • Da PowerShell, Azure CLI, Cloud Shell… "resources": [ { "apiVersion": "2016-01-01", "type": "Microsoft.Storage/storageAccounts", "name": "mystorageaccount", … ] PUT https://management.azure.com/subscriptions/{ subscriptionId}/resourceGroups/{resourceGrou pName}/providers/Microsoft.Storage/storageAc counts/mystorageaccount?api-version=2016-01- 01 REQUEST BODY {
  • 22. PowerShell Desired State Configuration • Sistema di configuration management basato su PowerShell • Funziona sia su Windows che su OSS • Elementi chiave: • Configurazioni  componente dichiarativa • Risorse  componente imperativa • Tre funzioni: Test, Get, Set • Reperibili da PSGallery  Find-DscResource • Local Configuration Manager • PUSH e PULL • Integrazione negli ARM template  https://docs.microsoft.com/en- us/azure/virtual-machines/extensions/dsc-template
  • 23. Configurazione DSC di esempio Configuration WebsiteTest { # Import the module that contains the resources we're using Import-DscResource -ModuleName PsDesiredStateConfiguration # The Node statement specifies which targets this configuration will be applied to. Node 'localhost' { # The first resource block ensures that the Web-Server (IIS) feature is enabled. WindowsFeature WebServer { Ensure = "Present" Name = "Web-Server" } # The second resource block ensures that the website content copied to the website root folder. File WebsiteContent { Ensure = 'Present' SourcePath = 'c:testindex.htm' DestinationPath = 'c:inetpubwwwroot' } } }
  • 24. Procedura di integrazione in ARM template Creare configurazione DSC Creare uno ZIP contenente configurazione e risorse Caricare lo ZIP su un repository Inserire estensione nell’ARM Template
  • 25. Risorsa PowerShell DSC { "name": "Microsoft.Powershell.DSC", "type": " Microsoft.Compute/virtualMachines/extensions", "location": "[resourceGroup().location]", "apiVersion": "2018-06-30", "dependsOn": [], "properties": { "publisher": "Microsoft.Powershell", "type": "DSC", "typeHandlerVersion": "2.77", "autoUpgradeMinorVersion": true, "settings": { "configuration": { "url": "http://validURLToConfigLocation", "script": "ConfigurationScript.ps1", "function": "ConfigurationFunction" }, "configurationArguments": { "argument1": "Value1", "argument2": "Value2" }, }, "protectedSettings": { "configurationArguments": { "parameterOfTypePSCredential1": { "userName": "UsernameValue1", "password": "PasswordValue1" }, } } }
  • 26. Custom Script Extensions { "apiVersion": "2018-06-01", "type": "Microsoft.Compute/virtualMachines/extensions", "name": "config-app", "location": "[resourceGroup().location]", "dependsOn": [], "properties": { "publisher": "Microsoft.Compute", "type": "CustomScriptExtension", "typeHandlerVersion": "1.9", "autoUpgradeMinorVersion": true, "settings": { "fileUris": [ "script location" ], "timestamp": 12345678, }, "protectedSettings": { "commandToExecute": "myExecutionCommand", "storageAccountName": "myStorageAccountName", "storageAccountKey": "myStorageAccountKey" } } }
  • 28. Compiti a casa  • Demo di questa sessione • https://github.com/OmegaMadLab/AzDayReloaded-ArmTemplateWorkshop • StartingWithArmTemplates • https://github.com/OmegaMadLab/StartingWithArmTemplates • Azure Quickstart Template gallery su GitHub • https://github.com/Azure/azure-quickstart-templates • ARM template SQL IaaS complesso (DSC + CSE con autenticazione di dominio) • https://github.com/OmegaMadLab/OptimizedSqlVm • Esempi PowerShell DSC: • https://github.com/OmegaMadLab/DSCDemo • PowerShell DSC su Microsoft Virtual Academy • Base: https://channel9.msdn.com/Series/Getting-Started-with-PowerShell-DSC • Advanced: https://channel9.msdn.com/Series/Advanced-PowerShell-DSC-and-Custom-Resources?l=3DnsS2H1_1504984382 • Sessione BRK 4026 Ignite 2018 – Tips, Tricks, and real world example to build and manage ARM templates • Video: https://www.youtube.com/watch?v=cdkDhR3HFiI • Demo: https://github.com/vladimirjoanovic/ignite2018/tree/master/BRK4026 • Sessione BRK3233 Ignite 2019 - What’s new with Azure Resource Manager (ARM) templates for your deployments • Video: https://medius.studios.ms/video/asset/HIGHMP4/IG19-BRK3233