├── Chapter02 ├── chapter-2 - listing1.txt ├── chapter-2 - listing2.txt ├── chapter-2 - listing3.txt ├── chapter-2 - listing4.txt ├── chapter-2 - listing5.txt ├── chapter-2 - listing6.txt └── chapter-2 - listing7.txt ├── Chapter03 ├── chapter-3 - listing1.txt ├── chapter-3 - listing2.txt ├── chapter-3 - listing3.txt ├── chapter-3 - listing4.txt └── chapter-3 - listing5.txt ├── Chapter04 ├── chapter-4 - listing1.txt ├── chapter-4 - listing10.txt ├── chapter-4 - listing11.txt ├── chapter-4 - listing12.txt ├── chapter-4 - listing13.txt ├── chapter-4 - listing14.txt ├── chapter-4 - listing15.txt ├── chapter-4 - listing2.txt ├── chapter-4 - listing3.json ├── chapter-4 - listing4.txt ├── chapter-4 - listing5.txt ├── chapter-4 - listing6.txt ├── chapter-4 - listing7.txt ├── chapter-4 - listing8.txt └── chapter-4 - listing9.txt ├── Chapter05 ├── CustomScriptExtension-outputs.json ├── DSC-ConfigData.json ├── Dsc-Basic.json ├── Install-IIS.ps1 ├── Linux-CSA.json ├── Seperateresource.json ├── WindowsVirtualMachine-Protected.json ├── WindowsVirtualMachine-ProtectedSettings.json ├── WindowsVirtualMachine.json ├── chapter-5 - listing1.txt ├── chapter-5 - listing10.txt ├── chapter-5 - listing11.txt ├── chapter-5 - listing12.txt ├── chapter-5 - listing13.txt ├── chapter-5 - listing14.txt ├── chapter-5 - listing15.txt ├── chapter-5 - listing16.txt ├── chapter-5 - listing17.txt ├── chapter-5 - listing18.txt ├── chapter-5 - listing19.txt ├── chapter-5 - listing2.txt ├── chapter-5 - listing20.txt ├── chapter-5 - listing21.txt ├── chapter-5 - listing3.txt ├── chapter-5 - listing4.txt ├── chapter-5 - listing5.txt ├── chapter-5 - listing6.txt ├── chapter-5 - listing7.txt ├── chapter-5 - listing8.txt ├── chapter-5 - listing9.txt ├── configdata.psd1 ├── first.sh ├── psdsc-configdata.ps1 └── psdsc.ps1 ├── Chapter06 ├── chapter-6 - listing1.txt ├── chapter-6 - listing10.txt ├── chapter-6 - listing11.txt ├── chapter-6 - listing2.txt ├── chapter-6 - listing3.txt ├── chapter-6 - listing4.txt ├── chapter-6 - listing5.txt ├── chapter-6 - listing6.txt ├── chapter-6 - listing7.txt ├── chapter-6 - listing8.txt └── chapter-6 - listing9.txt ├── Chapter07 ├── RedefiningProperties.json ├── SharedServicesSQL-1.0.0.0.json ├── appserviceplan-1.0.0.0.json ├── azuredeploy.json ├── azuredeploy.parameters.json └── webappsimple-1.0.0.0.json ├── LICENSE └── README.md /Chapter02/chapter-2 - listing1.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | }, 6 | "variables": { 7 | }, 8 | "resources": [ 9 | ], 10 | "outputs": { 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter02/chapter-2 - listing2.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "storageAccountName": { 6 | "type": "string" 7 | } 8 | 9 | }, 10 | "variables": { 11 | "storageAccountType": "Standard_LRS" 12 | }, 13 | "resources": [ 14 | { 15 | "type": "Microsoft.Storage/storageAccounts", 16 | "name": "[parameters('storageAccountName')]", 17 | "apiVersion": "2018-02-01", 18 | "location": "[resourceGroup().location]", 19 | "sku": { 20 | "name": "[variables('storageAccountType')]" 21 | }, 22 | "kind": "Storage" 23 | } 24 | 25 | 26 | ], 27 | "outputs": { 28 | "storageDetails": { 29 | "type": "string", 30 | "value": "[concat(parameters('storageAccountName'), '-', variables('storageAccountType'))]" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter02/chapter-2 - listing3.txt: -------------------------------------------------------------------------------- 1 | az group create --name CLIDeployment --location "West Europe" -------------------------------------------------------------------------------- /Chapter02/chapter-2 - listing4.txt: -------------------------------------------------------------------------------- 1 | az group deployment create --name CLIDeploy1 --resource-group CLIDeployment --template-file C:\Users\rites\source\repos\MyFirstTemplate\MyFirstTemplate\azuredeploy.json --parameters storageAccountName=unique824798 -------------------------------------------------------------------------------- /Chapter02/chapter-2 - listing5.txt: -------------------------------------------------------------------------------- 1 | Test-AzureRmResourceGroupDeployment -ResourceGroupName "TestRG" -Mode Incremental -TemplateFile "C:\myARMTemple.json" -TemplateParameterFile "C:\myARMTemplateParameters.json" -Verbose -------------------------------------------------------------------------------- /Chapter02/chapter-2 - listing6.txt: -------------------------------------------------------------------------------- 1 | New-AzureRmResourceGroupDeployment -Name "TestDeploy1" -ResourceGroupName "TestRG" -Mode Incremental -TemplateFile "C:\myARMTemple.json" -TemplateParameterFile "C:\myARMTemplateParameters.json" -Verbose -------------------------------------------------------------------------------- /Chapter02/chapter-2 - listing7.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "storageAccountConfiguration": { 6 | "type" : "object", 7 | "defaultValue" : { 8 | "name" : "sdw543fggsdfsd", 9 | "apiVersion" : "2018-02-01", 10 | "sku" : { 11 | "name" : "Standard_LRS" 12 | } 13 | } 14 | } 15 | }, 16 | "variables": { 17 | 18 | }, 19 | "resources": [ 20 | { 21 | "type": "Microsoft.Storage/storageAccounts", 22 | "name": "[parameters('storageAccountConfiguration').name]", 23 | "apiVersion": "[parameters('storageAccountConfiguration').apiVersion]", 24 | "location": "[resourceGroup().location]", 25 | "sku": { 26 | "name": "[parameters('storageAccountConfiguration').sku.name]", 27 | }, 28 | "kind": "Storage" 29 | } 30 | ], 31 | "outputs": { 32 | "storageDetails": { 33 | "type": "string", 34 | "value": "[concat(parameters('storageAccountConfiguration').name, parameters('storageAccountConfiguration').sku.name)]" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter03/chapter-3 - listing1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Azure-Resource-Manager-Templates-Quick-Start-Guide/16916bfcf527d5a1c5f486388a2c7965a0d340b2/Chapter03/chapter-3 - listing1.txt -------------------------------------------------------------------------------- /Chapter03/chapter-3 - listing2.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "skuName": { 6 | "type": "string", 7 | "defaultValue": "F1" 8 | }, 9 | "skuCapacity": { 10 | "type": "int", 11 | "defaultValue": 1, 12 | "minValue": 1, 13 | "metadata": { 14 | "description": "Describes plan's instance count" 15 | } 16 | } 17 | }, 18 | "variables": { 19 | "hostingPlanName": "[concat('hostingplan', uniqueString(resourceGroup().id))]", 20 | "webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]" 21 | }, 22 | "resources": [ 23 | { 24 | "apiVersion": "2016-03-01", 25 | "name": "[variables('hostingPlanName')]", 26 | "type": "Microsoft.Web/serverfarms", 27 | "location": "[parameters('location')]", 28 | "tags": { 29 | "displayName": "HostingPlan" 30 | }, 31 | "sku": { 32 | "name": "[parameters('skuName')]", 33 | "capacity": "[parameters('skuCapacity')]" 34 | }, 35 | "properties": { 36 | "name": "[variables('hostingPlanName')]" 37 | } 38 | }, 39 | { 40 | "apiVersion": "2016-03-01", 41 | "name": "[variables('webSiteName')]", 42 | "type": "Microsoft.Web/sites", 43 | "location": "[parameters('location')]", 44 | "dependsOn": [ 45 | "[variables('hostingPlanName')]" 46 | ], 47 | "properties": { 48 | "name": "[variables('webSiteName')]", 49 | "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]" 50 | }, 51 | "resources": [ 52 | { 53 | "apiVersion": "2016-03-01", 54 | "type": "config", 55 | "name": "connectionstrings", 56 | "dependsOn": [ 57 | "[variables('webSiteName')]" 58 | ], 59 | "properties": { 60 | "DefaultConnection": { 61 | "value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('databaseName'), ';User Id=', parameters('sqlAdministratorLogin'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName, ';Password=', parameters('sqlAdministratorLoginPassword'), ';')]", 62 | "type": "SQLAzure" 63 | } 64 | } 65 | } 66 | ] 67 | } 68 | 69 | ], 70 | "outputs": { 71 | "siteUri": { 72 | "type": "string", 73 | "value": "[reference(concat('Microsoft.Web/sites/', variables('webSiteName'))).hostnames[0]]" 74 | } 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Chapter03/chapter-3 - listing3.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "skuName": { 6 | "type": "string", 7 | "defaultValue": "F1" 8 | }, 9 | "skuCapacity": { 10 | "type": "int", 11 | "defaultValue": 1, 12 | "minValue": 1 13 | } 14 | }, 15 | "variables": { 16 | "hostingPlanName": "[concat('hostingplan', uniqueString(resourceGroup().id))]", 17 | "webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]" 18 | }, 19 | "resources": [ 20 | { 21 | "apiVersion": "2016-03-01", 22 | "name": "[variables('hostingPlanName')]", 23 | "type": "Microsoft.Web/serverfarms", 24 | "location": "[resourceGroup().location]", 25 | "tags": { 26 | "displayName": "HostingPlan" 27 | }, 28 | "sku": { 29 | "name": "[parameters('skuName')]", 30 | "capacity": "[parameters('skuCapacity')]" 31 | }, 32 | "properties": { 33 | "name": "[variables('hostingPlanName')]" 34 | } 35 | }, 36 | { 37 | "apiVersion": "2016-03-01", 38 | "name": "[variables('webSiteName')]", 39 | "type": "Microsoft.Web/sites", 40 | "location": "[resourceGroup().location]", 41 | "dependsOn": [ 42 | "[variables('hostingPlanName')]" 43 | ], 44 | "properties": { 45 | "name": "[variables('webSiteName')]", 46 | "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]" 47 | } 48 | } 49 | ], 50 | "outputs": { 51 | "siteUri": { 52 | "type": "string", 53 | "value": "[reference(concat('Microsoft.Web/sites/', variables('webSiteName'))).hostnames[0]]" 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Chapter03/chapter-3 - listing4.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "sqlServerName": { 6 | "type": "string", 7 | "defaultValue": "riteshsrvunq01" 8 | }, 9 | "sqlServerAdministratorLoginName": { 10 | "type": "string", 11 | "defaultValue": "citynextadmin" 12 | }, 13 | "sqlServerAdministratorLoginPassword": { 14 | "type": "securestring", 15 | "defaultValue": "Password!1234" 16 | }, 17 | "sqlDatabaseCollation": { 18 | "type": "string", 19 | "defaultValue": "SQL_Latin1_General_CP1_CI_AS" 20 | }, 21 | "sqlDatabaseEdition": { 22 | "type": "string", 23 | "defaultValue": "Standard" 24 | }, 25 | "sqlDatabaseMaxSizeBytes": { 26 | "type": "string", 27 | "defaultValue": "107374182400" 28 | }, 29 | "sqlDatabaseName": { 30 | "type": "string", 31 | "defaultValue": "riteshdbunq01" 32 | }, 33 | "sqlDatabaseRequestedServiceObjectiveName": { 34 | "type": "string", 35 | "defaultValue": "S2" 36 | } 37 | }, 38 | "variables": { 39 | }, 40 | "resources": [ 41 | { 42 | "type": "Microsoft.Sql/servers", 43 | "kind": "v12.0", 44 | "name": "[parameters('sqlServerName')]", 45 | "location": "[resourceGroup().location]", 46 | "apiVersion": "2015-05-01-preview", 47 | 48 | "properties": { 49 | "administratorLogin": "[parameters('sqlServerAdministratorLoginName')]", 50 | "administratorLoginPassword": "[parameters('sqlServerAdministratorLoginPassword')]", 51 | "version": "12.0" 52 | }, 53 | "resources": [ 54 | { 55 | "type": "Microsoft.Sql/servers/databases", 56 | "name": "[concat(parameters('sqlServerName'),'/',parameters('sqlDatabaseName'))]", 57 | "location": "[resourceGroup().location]", 58 | "apiVersion": "2017-10-01-preview", 59 | "dependsOn": [ 60 | "[parameters('sqlServerName')]" 61 | ], 62 | "properties": { 63 | "edition": "[parameters('sqlDatabaseEdition')]", 64 | "collation": "[parameters('sqlDatabaseCollation')]", 65 | "maxSizeBytes": "[parameters('sqlDatabaseMaxSizeBytes')]", 66 | "requestedServiceObjectiveName": "[parameters('sqlDatabaseRequestedServiceObjectiveName')]" 67 | } 68 | } 69 | ] 70 | } 71 | ], 72 | "outputs": { 73 | "SQLServer1": { 74 | "type": "string", 75 | "value": "[reference(parameters('sqlServerName')).fullyQualifiedDomainName]" 76 | }, 77 | "SQLServer": { 78 | "type": "object", 79 | "value": "[reference(parameters('sqlServerName'))]" 80 | }, 81 | "SQLDatabase": { 82 | "type": "object", 83 | "value": "[reference(resourceid('Microsoft.SQL/servers/databases', parameters('sqlServerName'), parameters('sqlDatabaseName')),'2017-10-01-preview', 'full')]" 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Chapter03/chapter-3 - listing5.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "sqlServerName": { 6 | "type": "string", 7 | "defaultValue": "riteshsrvunq01" 8 | }, 9 | "sqlServerAdministratorLoginName": { 10 | "type": "string", 11 | "defaultValue": "citynextadmin" 12 | }, 13 | "sqlServerAdministratorLoginPassword": { 14 | "type": "securestring", 15 | "defaultValue": "Password!1234" 16 | }, 17 | "sqlDatabaseCollation": { 18 | "type": "string", 19 | "defaultValue": "SQL_Latin1_General_CP1_CI_AS" 20 | }, 21 | "sqlDatabaseEdition": { 22 | "type": "string", 23 | "defaultValue": "Standard" 24 | }, 25 | "sqlDatabaseMaxSizeBytes": { 26 | "type": "string", 27 | "defaultValue": "107374182400" 28 | }, 29 | "sqlDatabaseName": { 30 | "type": "string", 31 | "defaultValue": "riteshdbunq01" 32 | }, 33 | "sqlDatabaseRequestedServiceObjectiveName": { 34 | "type": "string", 35 | "defaultValue": "S2" 36 | } 37 | }, 38 | "variables": { 39 | "storagekey": "?sv=2017-11-09&ss=bfqt&srt=sco&sp=rwdlacup&se=2018-08-20T19:22:51Z&st=2018-08-20T11:22:51Z&spr=https&sig=4oGQeTncirZHxyyiMv%2Bhx1A4Tmx7%2FF4Xbp64i9ATpd4%3D", 40 | "nestedTemplateLocation": "https://sta2usc1esvpnvhddev.blob.core.windows.net/templates/nestedSQLTemplate.json", 41 | "completeNestedTemplateURL": "[concat(variables('nestedTemplateLocation'), variables('storagekey'))]" 42 | 43 | }, 44 | "resources": [ 45 | { 46 | "type": "Microsoft.Resources/deployments", 47 | "apiVersion": "2017-05-10", 48 | "name": "DeploySQLResources", 49 | "properties": { 50 | "mode": "Incremental", 51 | "templateLink": { 52 | "uri": "[variables('completeNestedTemplateURL')]", 53 | "contentVersion": "1.0.0.0" 54 | }, 55 | "parameters": { 56 | "sqlServerName": { 57 | "value": "[parameters('sqlServerName')]" 58 | }, 59 | "sqlServerAdministratorLoginName": { 60 | "value": "[parameters('sqlServerAdministratorLoginName')]" 61 | }, 62 | "sqlServerAdministratorLoginPassword": { 63 | "value": "[parameters('sqlServerAdministratorLoginPassword')]" 64 | }, 65 | "sqlDatabaseCollation": { 66 | "value": "[parameters('sqlDatabaseCollation')]" 67 | }, 68 | "sqlDatabaseEdition": { 69 | "value": "[parameters('sqlDatabaseEdition')]" 70 | }, 71 | "sqlDatabaseMaxSizeBytes": { 72 | "value": "[parameters('sqlDatabaseMaxSizeBytes')]" 73 | }, 74 | "sqlDatabaseName": { 75 | "value": "[parameters('sqlDatabaseName')]" 76 | }, 77 | "sqlDatabaseRequestedServiceObjectiveName": { 78 | "value": "[parameters('sqlDatabaseRequestedServiceObjectiveName')]" 79 | } 80 | } 81 | } 82 | } 83 | ], 84 | "outputs": { 85 | "DatabaseResourceID": { 86 | "type": "string", 87 | "value": "[reference('DeploySQLResources').outputs.SQLDatabaseResourceIDfromDiffernetSubscription.value]" 88 | }, 89 | "SQLDatabaseObject": { 90 | "type": "object", 91 | "value": "[reference('DeploySQLResources').outputs.SQLDatabase.value]" 92 | }, 93 | "SQLServerObject": { 94 | "type": "object", 95 | "value": "[reference('DeploySQLResources').outputs.SQLServer.value]" 96 | }, 97 | "SQLServerDomain": { 98 | "type": "string", 99 | "value": "[reference('DeploySQLResources').outputs.SQLServer1.value]" 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing1.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "storageAccountName" : {"type": "string", "minLength": 5} 6 | 7 | }, 8 | "variables": { 9 | 10 | "storageAccountNameVar": "[tolower(concat(parameters('storageAccountName'), uniqueString(resourceGroup().id)))]" 11 | }, 12 | "resources": [ 13 | { 14 | "apiVersion": "2018-02-01", 15 | "name": "[concat(variables('storageAccountNameVar'), copyindex())]", 16 | "location": "[resourceGroup().location]", 17 | "type": "Microsoft.Storage/storageAccounts", 18 | "sku": { 19 | "name": "Standard_LRS" 20 | }, 21 | "copy": { 22 | "name": "storages", 23 | "count": 2 24 | }, 25 | "kind": "StorageV2", 26 | "properties": { 27 | "encryption": { 28 | "services": { 29 | "blob": { 30 | "enabled": true 31 | }, 32 | "file": null 33 | }, 34 | "keySource": "Microsoft.Storage" 35 | } 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing10.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "Locations": { 6 | "type": "array", 7 | "defaultValue": [ "east us", "west us" ], 8 | "metadata": { 9 | "description": "Deployment locations" 10 | } 11 | } 12 | }, 13 | "variables": { 14 | }, 15 | "resources": [ 16 | { 17 | "type": "Microsoft.Resources/resourceGroups", 18 | "location": "[parameters('Locations')[copyIndex()]]", 19 | "name": "[concat('location',copyIndex())]", 20 | "apiVersion": "2018-05-01", 21 | "copy": { 22 | "name": "allResourceGroups", 23 | "count": "[length(parameters('Locations'))]" 24 | }, 25 | "properties": {} 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing11.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "clientId": { "type": "string" }, 6 | "tenantId": { "type": "string" }, 7 | "enabledForDeployment": { "type": "string" }, 8 | "enabledForTemplateDeployment": { "type": "string" }, 9 | "enableVaultForVolumeEncryption": { "type": "string" }, 10 | "vaultSku": { "type": "string" }, 11 | "vaultName": { "type": "string" }, 12 | "permissions": { "type": "object" } 13 | }, 14 | "variables": { 15 | 16 | }, 17 | "resources": [ 18 | { 19 | "type": "Microsoft.KeyVault/vaults", 20 | "name": "[concat(parameters('vaultName'), resourceGroup().location)]", 21 | "apiVersion": "2015-06-01", 22 | "location": "[resourceGroup().location]", 23 | "properties": { 24 | "enabledForDeployment": "[parameters('enabledForDeployment')]", 25 | "enabledForTemplateDeployment": "[parameters('enabledForTemplateDeployment')]", 26 | "enabledForVolumeEncryption": "[parameters('enableVaultForVolumeEncryption')]", 27 | "tenantId": "[parameters('tenantId')]", 28 | "accessPolicies": [ 29 | { 30 | "tenantId": "[parameters('tenantId')]", 31 | "objectId": "[parameters('clientId')]", 32 | "permissions": "[parameters('permissions')]" 33 | } 34 | ], 35 | "sku": { 36 | "name": "[parameters('vaultSku')]", 37 | "family": "A" 38 | } 39 | } 40 | } 41 | ], 42 | "outputs": { 43 | "keyVaultName": { 44 | "type": "string", 45 | "value": "[concat(parameters('vaultName'), resourceGroup().location)]" 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing12.txt: -------------------------------------------------------------------------------- 1 | $app = New-AzureRmADApplication -DisplayName "ARMtemplateBook" -IdentifierUris "http://ARMtemplateBook" -ReplyUrls "http://ARMtemplateBook/callback" 2 | 3 | $principal = New-AzureRmADServicePrincipal -ApplicationId $app.ApplicationId -Password (ConvertTo-SecureString -String Pa55w0rd -AsPlainText -Force) 4 | 5 | $assignment = New-AzureRmRoleAssignment -RoleDefinitionName owner -ServicePrincipalName $app.ApplicationId.Guid 6 | 7 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing13.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "Locations": { 6 | "type": "array", 7 | "defaultValue": [ "east us", "west us" ], 8 | "metadata": { 9 | "description": "Deployment locations" 10 | } 11 | } 12 | }, 13 | "variables": { 14 | "enabledForDeployment": "true", 15 | "enabledForTemplateDeployment": "true", 16 | "enableVaultForVolumeEncryption": "true", 17 | "tenantId": "771f1cf4-b1ac-4f2e-ad21-de39ea201e7e", 18 | "objectId": "5ecc2085-c985-4dec-a4ce-1108a252833b", 19 | "permissions": { 20 | "keys": [ "all" ], 21 | "secrets": [ "all" ] 22 | }, 23 | "vaultSku": "Standard", 24 | "vaultName": "myVault" 25 | }, 26 | "resources": [ 27 | { 28 | "type": "Microsoft.Resources/resourceGroups", 29 | "location": "[parameters('Locations')[copyIndex()]]", 30 | "name": "[concat('location',copyIndex())]", 31 | "apiVersion": "2018-05-01", 32 | "copy": { 33 | "name": "allResourceGroups", 34 | "count": "[length(parameters('Locations'))]" 35 | }, 36 | "properties": {} 37 | }, 38 | { 39 | "apiVersion": "2017-05-10", 40 | "name": "[concat('nestedTemplate', copyindex())]", 41 | "type": "Microsoft.Resources/deployments", 42 | "resourceGroup": "[concat('location',copyIndex())]", 43 | "copy": { 44 | "name": "keyVaults", 45 | "count": "[length(parameters('Locations'))]" 46 | }, 47 | "dependsOn": [ "allResourceGroups" ], 48 | "properties": { 49 | "mode": "Incremental", 50 | "templateLink": { 51 | "uri": "https://tempssdfsdf.blob.core.windows.net/temps/Keyvault.json", 52 | "contentVersion": "1.0.0.0" 53 | }, 54 | "parameters": { 55 | "clientId": { "value": "[variables('objectId')]" }, 56 | "tenantId": { "value": "[variables('tenantId')]" }, 57 | "enabledForDeployment": { "value": "[variables('enabledForDeployment')]" }, 58 | "enabledForTemplateDeployment": { "value": "[variables('enabledForTemplateDeployment')]" }, 59 | "enableVaultForVolumeEncryption": { "value": "[variables('enableVaultForVolumeEncryption')]" }, 60 | "vaultSku": { "value": "[variables('vaultSku')]" }, 61 | "vaultName": { "value": "[variables('vaultName')]" }, 62 | "permissions": { "value": "[variables('permissions')]" } 63 | } 64 | } 65 | } 66 | ], 67 | "outputs": { 68 | "keyvaultdetails": { "type": "string", 69 | "value": "[reference('nestedTemplate0').outputs.keyVaultName.value]" 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing14.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "Locations": { 6 | "type": "array", 7 | "defaultValue": [ "east us", "west us" ], 8 | "metadata": { 9 | "description": "Deployment locations" 10 | } 11 | }, 12 | "subscriptions": { 13 | "type": "array", 14 | "defaultValue": [ "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx" ], 15 | "metadata": { 16 | "description": "subscriptions identifiers" 17 | } 18 | } 19 | }, 20 | "variables": { 21 | "enabledForDeployment": "true", 22 | "enabledForTemplateDeployment": "true", 23 | "enableVaultForVolumeEncryption": "true", 24 | "tenantId": "771f1cf4-b1ac-4f2e-ad21-de39ea201e7e", 25 | "objectId": "5ecc2085-c985-4dec-a4ce-1108a252833b", 26 | "permissions": { 27 | "keys": [ "all" ], 28 | "secrets": [ "all" ] 29 | }, 30 | "vaultSku": "Standard", 31 | "vaultName": "myVault" 32 | }, 33 | "resources": [ 34 | { 35 | "apiVersion": "2017-05-10", 36 | "name": "[concat('nestedTemplate', copyindex())]", 37 | "type": "Microsoft.Resources/deployments", 38 | "resourceGroup": "[parameters('location')[copyIndex()]]", 39 | "subscriptionId": "[parameters('subscriptions')[copyIndex()]]", 40 | "copy": { 41 | "name": "keyVaults", 42 | "count": "[length(parameters('Locations'))]", 43 | "mode": "Serial", 44 | "batchSize": 2 45 | }, 46 | "dependsOn": [ "allResourceGroups" ], 47 | "properties": { 48 | "mode": "Incremental", 49 | "templateLink": { 50 | "uri": "https://tempssdfsdf.blob.core.windows.net/temps/Keyvault.json", 51 | "contentVersion": "1.0.0.0" 52 | }, 53 | "parameters": { 54 | "clientId": { "value": "[variables('objectId')]" }, 55 | "tenantId": { "value": "[variables('tenantId')]" }, 56 | "enabledForDeployment": { "value": "[variables('enabledForDeployment')]" }, 57 | "enabledForTemplateDeployment": { "value": "[variables('enabledForTemplateDeployment')]" }, 58 | "enableVaultForVolumeEncryption": { "value": "[variables('enableVaultForVolumeEncryption')]" }, 59 | "vaultSku": { "value": "[variables('vaultSku')]" }, 60 | "vaultName": { "value": "[variables('vaultName')]" }, 61 | "permissions": { "value": "[variables('permissions')]" } 62 | } 63 | } 64 | } 65 | ], 66 | "outputs": { 67 | "keyvaultdetails": { 68 | "type": "string", 69 | "value": "[reference('nestedTemplate0').outputs.keyVaultName.value]" 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing15.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "Locations": { 6 | "type": "array", 7 | "defaultValue": [ "east us", "west us" ], 8 | "metadata": { 9 | "description": "Deployment locations" 10 | } 11 | } 12 | 13 | }, 14 | "variables": { 15 | "enabledForDeployment": "true", 16 | "enabledForTemplateDeployment": "true", 17 | "enableVaultForVolumeEncryption": "true", 18 | "tenantId": "771f1cf4-b1ac-4f2e-ad21-de39ea201e7e", 19 | "clientId": "5ecc2085-c985-4dec-a4ce-1108a252833b", 20 | "permissions": { 21 | "keys": [ "all" ], 22 | "secrets": [ "all" ] 23 | }, 24 | "vaultSku": "Standard", 25 | "vaultName": "gyftdrj" 26 | }, 27 | "resources": [ 28 | { 29 | "type": "Microsoft.Resources/resourceGroups", 30 | "location": "[parameters('Locations')[copyIndex()]]", 31 | "name": "[concat('location',copyIndex())]", 32 | "apiVersion": "2018-05-01", 33 | "copy": { 34 | "name": "allResourceGroups", 35 | "count": "[length(parameters('Locations'))]" 36 | }, 37 | "properties": {} 38 | }, 39 | { 40 | "apiVersion": "2017-05-10", 41 | "name": "[concat('nestedTemplate', copyindex())]", 42 | "type": "Microsoft.Resources/deployments", 43 | "resourceGroup": "[concat('location',copyIndex())]", 44 | "copy": { 45 | "name": "keyVaults", 46 | "count": "[length(parameters('Locations'))]" 47 | }, 48 | "dependsOn": [ "allResourceGroups" ], 49 | "properties": { 50 | "mode": "Incremental", 51 | "template": { 52 | 53 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 54 | "contentVersion": "1.0.0.0", 55 | "parameters": { 56 | }, 57 | "variables": { 58 | 59 | }, 60 | "resources": [ 61 | { 62 | "type": "Microsoft.KeyVault/vaults", 63 | "name": "[concat(variables('vaultName'), string(copyindex()))]", 64 | "location": "[parameters('Locations')[copyIndex()]]", 65 | "apiVersion": "2015-06-01", 66 | "properties": { 67 | "enabledForDeployment": "[variables('enabledForDeployment')]", 68 | "enabledForTemplateDeployment": "[variables('enabledForTemplateDeployment')]", 69 | "enabledForVolumeEncryption": "[variables('enableVaultForVolumeEncryption')]", 70 | "tenantId": "[variables('tenantId')]", 71 | "accessPolicies": [ 72 | { 73 | "tenantId": "[variables('tenantId')]", 74 | "objectId": "[variables('clientId')]", 75 | "permissions": "[variables('permissions')]" 76 | } 77 | ], 78 | "sku": { 79 | "name": "[variables('vaultSku')]", 80 | "family": "A" 81 | } 82 | } 83 | } 84 | 85 | ] 86 | 87 | } 88 | 89 | 90 | } 91 | } 92 | ] 93 | } 94 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing2.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "storageAccountName": { 6 | "type": "string", 7 | "minLength": 5 8 | } 9 | }, 10 | "variables": { 11 | "storageAccountNameVar": "[tolower(concat(parameters('storageAccountName'), uniqueString(resourceGroup().id)))]" 12 | }, 13 | "resources": [ 14 | { 15 | "apiVersion": "2018-02-01", 16 | "name": "[concat(variables('storageAccountNameVar'), copyindex())]", 17 | "location": "[resourceGroup().location]", 18 | "type": "Microsoft.Storage/storageAccounts", 19 | "sku": { 20 | "name": "Standard_LRS" 21 | }, 22 | "copy": { 23 | "name": "storages", 24 | "count": 2, 25 | "mode": "Serial" 26 | }, 27 | "kind": "StorageV2", 28 | "properties": { 29 | "encryption": { 30 | "services": { 31 | "blob": { 32 | "enabled": true 33 | }, 34 | "file": null 35 | }, 36 | "keySource": "Microsoft.Storage" 37 | } 38 | } 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing3.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "adminUsername": { 6 | "type": "string", 7 | "metadata": { 8 | "description": "Username for the Virtual Machine." 9 | } 10 | }, 11 | "adminPassword": { 12 | "type": "securestring", 13 | "metadata": { 14 | "description": "Password for the Virtual Machine." 15 | } 16 | }, 17 | "dnsLabelPrefix": { 18 | "type": "string", 19 | "metadata": { 20 | "description": "Unique DNS Name for the Public IP used to access the Virtual Machine." 21 | } 22 | }, 23 | "windowsOSVersion": { 24 | "type": "string", 25 | "defaultValue": "2016-Datacenter", 26 | "allowedValues": [ 27 | "2008-R2-SP1", 28 | "2012-Datacenter", 29 | "2012-R2-Datacenter", 30 | "2016-Nano-Server", 31 | "2016-Datacenter-with-Containers", 32 | "2016-Datacenter" 33 | ], 34 | "metadata": { 35 | "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version." 36 | } 37 | }, 38 | "location": { 39 | "type": "string", 40 | "defaultValue": "[resourceGroup().location]", 41 | "metadata": { 42 | "description": "Location for all resources." 43 | } 44 | } 45 | }, 46 | "variables": { 47 | "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'sawinvm')]", 48 | "imagePublisher": "MicrosoftWindowsServer", 49 | "imageOffer": "WindowsServer", 50 | "nicName": "myVMNic", 51 | "addressPrefix": "10.0.0.0/16", 52 | "subnetName": "Subnet", 53 | "subnetPrefix": "10.0.0.0/24", 54 | "publicIPAddressName": "myPublicIP", 55 | "OSDiskName": "osdiskforwindowssimple", 56 | "vhdStorageContainerName": "vhds", 57 | "vmName": "MyWindowsVM", 58 | "vmSize": "Standard_A2", 59 | "virtualNetworkName": "MyVNET", 60 | "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]" 61 | }, 62 | "resources": [ 63 | { 64 | "type": "Microsoft.Storage/storageAccounts", 65 | "name": "[variables('storageAccountName')]", 66 | "apiVersion": "2016-01-01", 67 | "location": "[parameters('location')]", 68 | "sku": { 69 | "name": "Standard_LRS" 70 | }, 71 | "kind": "Storage", 72 | "properties": {} 73 | }, 74 | { 75 | "apiVersion": "2016-03-30", 76 | "type": "Microsoft.Network/publicIPAddresses", 77 | "name": "[variables('publicIPAddressName')]", 78 | "location": "[parameters('location')]", 79 | "properties": { 80 | "publicIPAllocationMethod": "Dynamic", 81 | "dnsSettings": { 82 | "domainNameLabel": "[parameters('dnsLabelPrefix')]" 83 | } 84 | } 85 | }, 86 | { 87 | "apiVersion": "2016-03-30", 88 | "type": "Microsoft.Network/virtualNetworks", 89 | "name": "[variables('virtualNetworkName')]", 90 | "location": "[parameters('location')]", 91 | "properties": { 92 | "addressSpace": { 93 | "addressPrefixes": [ 94 | "[variables('addressPrefix')]" 95 | ] 96 | }, 97 | "subnets": [ 98 | { 99 | "name": "[variables('subnetName')]", 100 | "properties": { 101 | "addressPrefix": "[variables('subnetPrefix')]" 102 | } 103 | } 104 | ] 105 | } 106 | }, 107 | { 108 | "apiVersion": "2016-03-30", 109 | "type": "Microsoft.Network/networkInterfaces", 110 | "name": "[variables('nicName')]", 111 | "location": "[parameters('location')]", 112 | "dependsOn": [ 113 | "[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 114 | "[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 115 | ], 116 | "properties": { 117 | "ipConfigurations": [ 118 | { 119 | "name": "ipconfig1", 120 | "properties": { 121 | "privateIPAllocationMethod": "Dynamic", 122 | "publicIPAddress": { 123 | "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]" 124 | }, 125 | "subnet": { 126 | "id": "[variables('subnetRef')]" 127 | } 128 | } 129 | } 130 | ] 131 | } 132 | }, 133 | { 134 | "apiVersion": "2017-03-30", 135 | "type": "Microsoft.Compute/virtualMachines", 136 | "name": "[variables('vmName')]", 137 | "location": "[resourceGroup().location]", 138 | "tags": { 139 | "displayName": "VirtualMachine" 140 | }, 141 | "dependsOn": [ 142 | "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]", 143 | "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 144 | ], 145 | "properties": { 146 | "hardwareProfile": { 147 | "vmSize": "[variables('vmSize')]" 148 | }, 149 | "osProfile": { 150 | "computerName": "[variables('vmName')]", 151 | "adminUsername": "[parameters('adminUsername')]", 152 | "adminPassword": "[parameters('adminPassword')]" 153 | }, 154 | "storageProfile": { 155 | "imageReference": { 156 | "publisher": "[variables('imagePublisher')]", 157 | "offer": "[variables('imageOffer')]", 158 | "sku": "[parameters('windowsOSVersion')]", 159 | "version": "latest" 160 | }, 161 | "osDisk": { 162 | "createOption": "FromImage" 163 | }, 164 | "copy": [ 165 | { 166 | "name": "dataDisks", 167 | "count": 3, 168 | "input": { 169 | "lun": "[copyIndex('dataDisks')]", 170 | "createOption": "Empty", 171 | "diskSizeGB": "1023", 172 | "name": "[concat(variables('vmName'), '-datadisk', copyIndex('dataDisks'))]" 173 | } 174 | } 175 | ] 176 | 177 | }, 178 | "networkProfile": { 179 | "networkInterfaces": [ 180 | { 181 | "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 182 | } 183 | ] 184 | } 185 | } 186 | } 187 | ], 188 | "outputs": { 189 | "storageAccount": { 190 | "type": "object", 191 | "value": "[reference(variables('storageAccountName'))]" 192 | }, 193 | "publicIPAddressName": { 194 | "type": "object", 195 | "value": "[reference(variables('publicIPAddressName'))]" 196 | }, 197 | "virtualNetworkName": { 198 | "type": "object", 199 | "value": "[reference(variables('virtualNetworkName'))]" 200 | }, 201 | "nicName": { 202 | "type": "object", 203 | "value": "[reference(variables('nicName'))]" 204 | }, 205 | "vmName": { 206 | "type": "object", 207 | "value": "[reference(variables('vmName'))]" 208 | } 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing4.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | }, 6 | "variables": { 7 | "virtualPath": [ 8 | "/myapp/api", 9 | "/myapp/api/internal/login", 10 | "/myapp/api/external/login" 11 | ], 12 | "physicalPath": [ 13 | "site\\wwwroot\\armwebsite", 14 | "site\\wwwroot\\armwebsite\\internal\\login", 15 | "site\\wwwroot\\armwebsite\\internal\\login" 16 | ], 17 | "copy": [ 18 | { 19 | "name": "virtualDirectories", 20 | "count": "[length(variables('physicalPath'))]", 21 | "input": { 22 | "virtualPath": "[variables('virtualPath')[copyIndex('virtualDirectories')]]", 23 | "physicalPath": "[variables('physicalPath')[copyIndex('virtualDirectories')]]", 24 | "preloadEnabled": false, 25 | "virtualDirectories": null 26 | } 27 | } 28 | ] 29 | }, 30 | "resources": [ 31 | ], 32 | "outputs": { 33 | "arrayOutput": { 34 | "type": "array", 35 | "value": "[variables('virtualDirectories')]" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing5.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | }, 6 | "variables": { 7 | "virtualPath": [ 8 | "/myapp/api", 9 | "/myapp/api/internal/login", 10 | "/myapp/api/external/login" 11 | ], 12 | "physicalPath": [ 13 | "site\\wwwroot\\armwebsite", 14 | "site\\wwwroot\\armwebsite\\internal\\login", 15 | "site\\wwwroot\\armwebsite\\internal\\login" 16 | ], 17 | "myVirtualDirectories": { 18 | "copy": [ 19 | { 20 | "name": "virtualDirectories", 21 | "count": "[length(variables('physicalPath'))]", 22 | "input": { 23 | "virtualPath": "[variables('virtualPath')[copyIndex('virtualDirectories')]]", 24 | "physicalPath": "[variables('physicalPath')[copyIndex('virtualDirectories')]]", 25 | "preloadEnabled": false, 26 | "virtualDirectories": null 27 | } 28 | } 29 | ] 30 | } 31 | }, 32 | "resources": [ 33 | ], 34 | "outputs": { 35 | "arrayOutput": { 36 | "type": "object", 37 | "value": "[variables('myVirtualDirectories')]" 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing6.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "storageAccountName": { 6 | "type": "string", 7 | "minLength": 5 8 | } 9 | }, 10 | "variables": { 11 | "storageAccountNameVar": "[tolower(concat(parameters('storageAccountName'), uniqueString(resourceGroup().id)))]" 12 | }, 13 | "resources": [ 14 | { 15 | "condition": "[equals(mod(copyindex(),2),1)]", 16 | "apiVersion": "2018-02-01", 17 | "name": "[concat(variables('storageAccountNameVar'), copyindex())]", 18 | "location": "[resourceGroup().location]", 19 | "type": "Microsoft.Storage/storageAccounts", 20 | "sku": { 21 | "name": "Standard_LRS" 22 | }, 23 | "copy": { 24 | "name": "storages", 25 | "count": 4 26 | }, 27 | "kind": "StorageV2", 28 | "properties": { 29 | "encryption": { 30 | "services": { 31 | "blob": { 32 | "enabled": true 33 | }, 34 | "file": null 35 | }, 36 | "keySource": "Microsoft.Storage" 37 | } 38 | } 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing7.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "storageAccountName": { 6 | "type": "string", 7 | "minLength": 5 8 | }, 9 | "HighDurability": { 10 | "type": "string", 11 | "defaultValue": "true" 12 | }, 13 | "isVersion2": { 14 | "type": "string", 15 | "defaultValue": "false" 16 | } 17 | }, 18 | "variables": { 19 | "storageAccountNameVar": "[tolower(concat(parameters('storageAccountName'), uniqueString(resourceGroup().id)))]" 20 | }, 21 | "resources": [ 22 | { 23 | "condition": "[equals(mod(copyindex(),2),1)]", 24 | "apiVersion": "2018-02-01", 25 | "name": "[concat(variables('storageAccountNameVar'), copyindex())]", 26 | "location": "[resourceGroup().location]", 27 | "type": "Microsoft.Storage/storageAccounts", 28 | "sku": { 29 | "name": "[concat( if(equals(parameters('HighDurability'), 'true'), 'Premium_LRS','Standard_GRS') )]" 30 | }, 31 | "copy": { 32 | "name": "storages", 33 | "count": 4 34 | }, 35 | "kind": "[concat( if(equals(parameters('isVersion2'), 'true'), 'StorageV2','Storage') )]", 36 | "properties": { 37 | "encryption": { 38 | "services": { 39 | "blob": { 40 | "enabled": true 41 | }, 42 | "file": null 43 | }, 44 | "keySource": "Microsoft.Storage" 45 | } 46 | } 47 | } 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing8.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "storageAccountName": { 6 | "type": "string", 7 | "minLength": 5 8 | } 9 | }, 10 | "variables": { 11 | "storageAccountNameVar": "[tolower(concat(parameters('storageAccountName'), uniqueString(resourceGroup().id)))]" 12 | }, 13 | "resources": [ 14 | { 15 | "apiVersion": "2018-02-01", 16 | "name": "[concat(variables('storageAccountNameVar'), copyindex())]", 17 | "location": "[resourceGroup().location]", 18 | "type": "Microsoft.Storage/storageAccounts", 19 | "sku": { 20 | "name": "Standard_LRS" 21 | }, 22 | "copy": { 23 | "name": "storages", 24 | "count": 2, 25 | "mode": "Serial" 26 | }, 27 | "kind": "StorageV2", 28 | "properties": { 29 | "encryption": { 30 | "services": { 31 | "blob": { 32 | "enabled": true 33 | }, 34 | "file": null 35 | }, 36 | "keySource": "Microsoft.Storage" 37 | } 38 | } 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /Chapter04/chapter-4 - listing9.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "storageAccountName": { 6 | "type": "string", 7 | "minLength": 5 8 | } 9 | }, 10 | "variables": { 11 | 12 | }, 13 | "resources": [ 14 | { 15 | "apiVersion": "2017-05-10", 16 | "name": "[concat('nestedTemplate', copyindex())]", 17 | "type": "Microsoft.Resources/deployments", 18 | "copy": { 19 | "name": "looping", 20 | "count": 2 21 | }, 22 | "properties": { 23 | "mode": "Incremental", 24 | "templateLink": { 25 | "uri": "https://myarmtemplates.blob.core.windows.net/temps/Serial-Copy.json", 26 | "contentVersion": "1.0.0.0" 27 | }, 28 | "parameters": { 29 | "storageAccountName": { 30 | "value": "[parameters('storageAccountName')]" 31 | } 32 | } 33 | } 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /Chapter05/CustomScriptExtension-outputs.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "adminUsername": { 6 | "type": "string", 7 | "minLength": 1, 8 | "metadata": { 9 | "description": "Username for the Virtual Machine." 10 | } 11 | }, 12 | "adminPassword": { 13 | "type": "securestring", 14 | "metadata": { 15 | "description": "Password for the Virtual Machine." 16 | } 17 | }, 18 | "dnsNameForPublicIP": { 19 | "type": "string", 20 | "minLength": 1, 21 | "metadata": { 22 | "description": "Globally unique DNS Name for the Public IP used to access the Virtual Machine." 23 | } 24 | }, 25 | "windowsOSVersion": { 26 | "type": "string", 27 | "defaultValue": "2012-R2-Datacenter", 28 | "allowedValues": [ 29 | "2008-R2-SP1", 30 | "2012-Datacenter", 31 | "2012-R2-Datacenter" 32 | ], 33 | "metadata": { 34 | "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter." 35 | } 36 | }, 37 | "storageAccountName": { 38 | "type": "string", 39 | "metadata": { 40 | "description": "Auto-generated container in staging storage account to receive post-build staging folder upload" 41 | } 42 | } 43 | 44 | }, 45 | "variables": { 46 | "imagePublisher": "MicrosoftWindowsServer", 47 | "imageOffer": "WindowsServer", 48 | "OSDiskName": "osdiskforwindowssimple", 49 | "nicName": "myVMNic", 50 | "addressPrefix": "10.0.0.0/16", 51 | "subnetName": "Subnet", 52 | "subnetPrefix": "10.0.0.0/24", 53 | "vhdStorageType": "Standard_LRS", 54 | "publicIPAddressName": "myPublicIP", 55 | "publicIPAddressType": "Dynamic", 56 | "vhdStorageContainerName": "vhds", 57 | "vmName": "MyWindowsVM", 58 | "vmSize": "Standard_A2", 59 | "virtualNetworkName": "MyVNET", 60 | "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]", 61 | "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]", 62 | "vhdStorageAccountName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]", 63 | "diagnosticsStorageAccountName": "[variables('vhdStorageAccountName')]", 64 | "wadmetricsresourceid": "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]", 65 | "firstCustomScriptExtensionScriptStorageContainer": "templates", 66 | "firstCustomScriptExtensionScriptFileName": "install-IIS.ps1" 67 | }, 68 | "resources": [ 69 | { 70 | "type": "Microsoft.Storage/storageAccounts", 71 | "name": "[variables('vhdStorageAccountName')]", 72 | "apiVersion": "2016-01-01", 73 | "location": "[resourceGroup().location]", 74 | "tags": { 75 | "displayName": "StorageAccount" 76 | }, 77 | "sku": { 78 | "name": "[variables('vhdStorageType')]" 79 | }, 80 | "kind": "Storage" 81 | }, 82 | { 83 | "apiVersion": "2016-03-30", 84 | "type": "Microsoft.Network/publicIPAddresses", 85 | "name": "[variables('publicIPAddressName')]", 86 | "location": "[resourceGroup().location]", 87 | "tags": { 88 | "displayName": "PublicIPAddress" 89 | }, 90 | "properties": { 91 | "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 92 | "dnsSettings": { 93 | "domainNameLabel": "[parameters('dnsNameForPublicIP')]" 94 | } 95 | } 96 | }, 97 | { 98 | "apiVersion": "2016-03-30", 99 | "type": "Microsoft.Network/virtualNetworks", 100 | "name": "[variables('virtualNetworkName')]", 101 | "location": "[resourceGroup().location]", 102 | "tags": { 103 | "displayName": "VirtualNetwork" 104 | }, 105 | "properties": { 106 | "addressSpace": { 107 | "addressPrefixes": [ 108 | "[variables('addressPrefix')]" 109 | ] 110 | }, 111 | "subnets": [ 112 | { 113 | "name": "[variables('subnetName')]", 114 | "properties": { 115 | "addressPrefix": "[variables('subnetPrefix')]" 116 | } 117 | } 118 | ] 119 | } 120 | }, 121 | { 122 | "apiVersion": "2016-03-30", 123 | "type": "Microsoft.Network/networkInterfaces", 124 | "name": "[variables('nicName')]", 125 | "location": "[resourceGroup().location]", 126 | "tags": { 127 | "displayName": "NetworkInterface" 128 | }, 129 | "dependsOn": [ 130 | "[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 131 | "[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 132 | ], 133 | "properties": { 134 | "ipConfigurations": [ 135 | { 136 | "name": "ipconfig1", 137 | "properties": { 138 | "privateIPAllocationMethod": "Dynamic", 139 | "publicIPAddress": { 140 | "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 141 | }, 142 | "subnet": { 143 | "id": "[variables('subnetRef')]" 144 | } 145 | } 146 | } 147 | ] 148 | } 149 | }, 150 | { 151 | "apiVersion": "2015-06-15", 152 | "type": "Microsoft.Compute/virtualMachines", 153 | "name": "[variables('vmName')]", 154 | "location": "[resourceGroup().location]", 155 | "tags": { 156 | "displayName": "VirtualMachine" 157 | }, 158 | "dependsOn": [ 159 | "[resourceId('Microsoft.Storage/storageAccounts/', variables('vhdStorageAccountName'))]", 160 | "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 161 | ], 162 | "properties": { 163 | "hardwareProfile": { 164 | "vmSize": "[variables('vmSize')]" 165 | }, 166 | "osProfile": { 167 | "computerName": "[variables('vmName')]", 168 | "adminUsername": "[parameters('adminUsername')]", 169 | "adminPassword": "[parameters('adminPassword')]" 170 | }, 171 | "storageProfile": { 172 | "imageReference": { 173 | "publisher": "[variables('imagePublisher')]", 174 | "offer": "[variables('imageOffer')]", 175 | "sku": "[parameters('windowsOSVersion')]", 176 | "version": "latest" 177 | }, 178 | "osDisk": { 179 | "name": "osdisk", 180 | "vhd": { 181 | "uri": "[concat(reference(resourceId('Microsoft.Storage/storageAccounts', variables('vhdStorageAccountName')), '2016-01-01').primaryEndpoints.blob, variables('vhdStorageContainerName'), '/', variables('OSDiskName'), '.vhd')]" 182 | }, 183 | "caching": "ReadWrite", 184 | "createOption": "FromImage" 185 | } 186 | }, 187 | "networkProfile": { 188 | "networkInterfaces": [ 189 | { 190 | "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 191 | } 192 | ] 193 | }, 194 | "diagnosticsProfile": { 195 | "bootDiagnostics": { 196 | "enabled": true, 197 | "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('vhdStorageAccountName')), '2016-01-01').primaryEndpoints.blob]" 198 | } 199 | } 200 | }, 201 | "resources": [ 202 | { 203 | "type": "extensions", 204 | "name": "Microsoft.Insights.VMDiagnosticsSettings", 205 | "apiVersion": "2016-03-30", 206 | "location": "[resourceGroup().location]", 207 | "tags": { 208 | "displayName": "AzureDiagnostics" 209 | }, 210 | "dependsOn": [ 211 | "[resourceId('Microsoft.Compute/virtualMachines/', variables('vmName'))]" 212 | ], 213 | "properties": { 214 | "publisher": "Microsoft.Azure.Diagnostics", 215 | "type": "IaaSDiagnostics", 216 | "typeHandlerVersion": "1.5", 217 | "autoUpgradeMinorVersion": true, 218 | "settings": { 219 | "WadCfg": { 220 | "DiagnosticMonitorConfiguration": { 221 | "overallQuotaInMB": "4096", 222 | "DiagnosticInfrastructureLogs": { 223 | "scheduledTransferLogLevelFilter": "Error" 224 | }, 225 | "WindowsEventLog": { 226 | "scheduledTransferPeriod": "PT1M", 227 | "DataSource": [ 228 | { 229 | "name": "Application!*[System[(Level = 1) or (Level = 2)]]" 230 | }, 231 | { 232 | "name": "Security!*[System[(Level = 1 or Level = 2)]]" 233 | }, 234 | { 235 | "name": "System!*[System[(Level = 1 or Level = 2)]]" 236 | } 237 | ] 238 | }, 239 | "PerformanceCounters": { 240 | "scheduledTransferPeriod": "PT1M", 241 | "PerformanceCounterConfiguration": [ 242 | { 243 | "counterSpecifier": "\\Processor(_Total)\\% Processor Time", 244 | "sampleRate": "PT15S", 245 | "unit": "Percent", 246 | "annotation": [ 247 | { 248 | "displayName": "CPU utilization", 249 | "locale": "en-us" 250 | } 251 | ] 252 | }, 253 | { 254 | "counterSpecifier": "\\Processor(_Total)\\% Privileged Time", 255 | "sampleRate": "PT15S", 256 | "unit": "Percent", 257 | "annotation": [ 258 | { 259 | "displayName": "CPU privileged time", 260 | "locale": "en-us" 261 | } 262 | ] 263 | }, 264 | { 265 | "counterSpecifier": "\\Processor(_Total)\\% User Time", 266 | "sampleRate": "PT15S", 267 | "unit": "Percent", 268 | "annotation": [ 269 | { 270 | "displayName": "CPU user time", 271 | "locale": "en-us" 272 | } 273 | ] 274 | }, 275 | { 276 | "counterSpecifier": "\\Processor Information(_Total)\\Processor Frequency", 277 | "sampleRate": "PT15S", 278 | "unit": "Count", 279 | "annotation": [ 280 | { 281 | "displayName": "CPU frequency", 282 | "locale": "en-us" 283 | } 284 | ] 285 | }, 286 | { 287 | "counterSpecifier": "\\System\\Processes", 288 | "sampleRate": "PT15S", 289 | "unit": "Count", 290 | "annotation": [ 291 | { 292 | "displayName": "Processes", 293 | "locale": "en-us" 294 | } 295 | ] 296 | }, 297 | { 298 | "counterSpecifier": "\\Process(_Total)\\Thread Count", 299 | "sampleRate": "PT15S", 300 | "unit": "Count", 301 | "annotation": [ 302 | { 303 | "displayName": "Threads", 304 | "locale": "en-us" 305 | } 306 | ] 307 | }, 308 | { 309 | "counterSpecifier": "\\Process(_Total)\\Handle Count", 310 | "sampleRate": "PT15S", 311 | "unit": "Count", 312 | "annotation": [ 313 | { 314 | "displayName": "Handles", 315 | "locale": "en-us" 316 | } 317 | ] 318 | }, 319 | { 320 | "counterSpecifier": "\\Memory\\% Committed Bytes In Use", 321 | "sampleRate": "PT15S", 322 | "unit": "Percent", 323 | "annotation": [ 324 | { 325 | "displayName": "Memory usage", 326 | "locale": "en-us" 327 | } 328 | ] 329 | }, 330 | { 331 | "counterSpecifier": "\\Memory\\Available Bytes", 332 | "sampleRate": "PT15S", 333 | "unit": "Bytes", 334 | "annotation": [ 335 | { 336 | "displayName": "Memory available", 337 | "locale": "en-us" 338 | } 339 | ] 340 | }, 341 | { 342 | "counterSpecifier": "\\Memory\\Committed Bytes", 343 | "sampleRate": "PT15S", 344 | "unit": "Bytes", 345 | "annotation": [ 346 | { 347 | "displayName": "Memory committed", 348 | "locale": "en-us" 349 | } 350 | ] 351 | }, 352 | { 353 | "counterSpecifier": "\\Memory\\Commit Limit", 354 | "sampleRate": "PT15S", 355 | "unit": "Bytes", 356 | "annotation": [ 357 | { 358 | "displayName": "Memory commit limit", 359 | "locale": "en-us" 360 | } 361 | ] 362 | }, 363 | { 364 | "counterSpecifier": "\\PhysicalDisk(_Total)\\% Disk Time", 365 | "sampleRate": "PT15S", 366 | "unit": "Percent", 367 | "annotation": [ 368 | { 369 | "displayName": "Disk active time", 370 | "locale": "en-us" 371 | } 372 | ] 373 | }, 374 | { 375 | "counterSpecifier": "\\PhysicalDisk(_Total)\\% Disk Read Time", 376 | "sampleRate": "PT15S", 377 | "unit": "Percent", 378 | "annotation": [ 379 | { 380 | "displayName": "Disk active read time", 381 | "locale": "en-us" 382 | } 383 | ] 384 | }, 385 | { 386 | "counterSpecifier": "\\PhysicalDisk(_Total)\\% Disk Write Time", 387 | "sampleRate": "PT15S", 388 | "unit": "Percent", 389 | "annotation": [ 390 | { 391 | "displayName": "Disk active write time", 392 | "locale": "en-us" 393 | } 394 | ] 395 | }, 396 | { 397 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Transfers/sec", 398 | "sampleRate": "PT15S", 399 | "unit": "CountPerSecond", 400 | "annotation": [ 401 | { 402 | "displayName": "Disk operations", 403 | "locale": "en-us" 404 | } 405 | ] 406 | }, 407 | { 408 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Reads/sec", 409 | "sampleRate": "PT15S", 410 | "unit": "CountPerSecond", 411 | "annotation": [ 412 | { 413 | "displayName": "Disk read operations", 414 | "locale": "en-us" 415 | } 416 | ] 417 | }, 418 | { 419 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Writes/sec", 420 | "sampleRate": "PT15S", 421 | "unit": "CountPerSecond", 422 | "annotation": [ 423 | { 424 | "displayName": "Disk write operations", 425 | "locale": "en-us" 426 | } 427 | ] 428 | }, 429 | { 430 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Bytes/sec", 431 | "sampleRate": "PT15S", 432 | "unit": "BytesPerSecond", 433 | "annotation": [ 434 | { 435 | "displayName": "Disk speed", 436 | "locale": "en-us" 437 | } 438 | ] 439 | }, 440 | { 441 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Read Bytes/sec", 442 | "sampleRate": "PT15S", 443 | "unit": "BytesPerSecond", 444 | "annotation": [ 445 | { 446 | "displayName": "Disk read speed", 447 | "locale": "en-us" 448 | } 449 | ] 450 | }, 451 | { 452 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Write Bytes/sec", 453 | "sampleRate": "PT15S", 454 | "unit": "BytesPerSecond", 455 | "annotation": [ 456 | { 457 | "displayName": "Disk write speed", 458 | "locale": "en-us" 459 | } 460 | ] 461 | }, 462 | { 463 | "counterSpecifier": "\\LogicalDisk(_Total)\\% Free Space", 464 | "sampleRate": "PT15S", 465 | "unit": "Percent", 466 | "annotation": [ 467 | { 468 | "displayName": "Disk free space (percentage)", 469 | "locale": "en-us" 470 | } 471 | ] 472 | } 473 | ] 474 | }, 475 | "Metrics": { 476 | "resourceId": "[variables('wadmetricsresourceid')]", 477 | "MetricAggregation": [ 478 | { 479 | "scheduledTransferPeriod": "PT1H" 480 | }, 481 | { 482 | "scheduledTransferPeriod": "PT1M" 483 | } 484 | ] 485 | } 486 | } 487 | } 488 | }, 489 | "protectedSettings": { 490 | "storageAccountName": "[variables('diagnosticsStorageAccountName')]", 491 | "storageAccountKey": "[listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('diagnosticsStorageAccountName')), '2016-01-01').keys[0].value]" 492 | } 493 | } 494 | } 495 | 496 | 497 | ] 498 | }, 499 | { 500 | "name": "[concat(variables('vmName'),'/','firstCustomScriptExtension')]", 501 | "type": "Microsoft.Compute/virtualMachines/extensions", 502 | "location": "[resourceGroup().location]", 503 | "apiVersion": "2016-03-30", 504 | "dependsOn": [ 505 | "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]" 506 | ], 507 | "tags": { 508 | "displayName": "firstCustomScriptExtension" 509 | }, 510 | "properties": { 511 | "publisher": "Microsoft.Compute", 512 | "type": "CustomScriptExtension", 513 | "typeHandlerVersion": "1.4", 514 | "autoUpgradeMinorVersion": true, 515 | "settings": { 516 | "fileUris": [ 517 | "[concat(parameters('storageAccountName'), '/', variables('firstCustomScriptExtensionScriptStorageContainer'), '/', variables('firstCustomScriptExtensionScriptFileName'))]" 518 | ], 519 | "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstCustomScriptExtensionScriptFileName'), ' -featureName web-server -serviceName w3svc')]" 520 | } 521 | 522 | } 523 | } 524 | ], 525 | "outputs": { 526 | "customScriptOutput": { 527 | "type": "string", 528 | "value": "[reference('firstCustomScriptExtension').instanceView.substatuses[0].message]" 529 | } 530 | } 531 | } 532 | -------------------------------------------------------------------------------- /Chapter05/DSC-ConfigData.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "adminUsername": { 6 | "type": "string", 7 | "defaultValue": "citynextadmin", 8 | "minLength": 1, 9 | "metadata": { 10 | "description": "Username for the Virtual Machine." 11 | } 12 | }, 13 | "adminPassword": { 14 | "type": "securestring", 15 | "defaultValue": "citynext!1234", 16 | "metadata": { 17 | "description": "Password for the Virtual Machine." 18 | } 19 | }, 20 | "dnsNameForPublicIP": { 21 | "type": "string", 22 | "minLength": 1, 23 | "defaultValue": "jhunjhunbaba", 24 | "metadata": { 25 | "description": "Globally unique DNS Name for the Public IP used to access the Virtual Machine." 26 | } 27 | }, 28 | "windowsOSVersion": { 29 | "type": "string", 30 | "defaultValue": "2012-R2-Datacenter", 31 | "allowedValues": [ 32 | "2008-R2-SP1", 33 | "2012-Datacenter", 34 | "2012-R2-Datacenter" 35 | ], 36 | "metadata": { 37 | "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter." 38 | } 39 | }, 40 | "storageAccountName": { 41 | "type": "string" 42 | }, 43 | "containerName": { 44 | "type": "string" 45 | }, 46 | "zipfileName": { 47 | "type": "string" 48 | }, 49 | "fileName": { 50 | "type": "string" 51 | } 52 | }, 53 | "variables": { 54 | "imagePublisher": "MicrosoftWindowsServer", 55 | "imageOffer": "WindowsServer", 56 | "OSDiskName": "osdiskforwindowssimple", 57 | "nicName": "myVMNic", 58 | "addressPrefix": "10.0.0.0/16", 59 | "subnetName": "Subnet", 60 | "subnetPrefix": "10.0.0.0/24", 61 | "vhdStorageType": "Standard_LRS", 62 | "publicIPAddressName": "myPublicIP", 63 | "publicIPAddressType": "Dynamic", 64 | "vhdStorageContainerName": "vhds", 65 | "vmName": "MyWindowsVM", 66 | "vmSize": "Standard_A2", 67 | "virtualNetworkName": "MyVNET", 68 | "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]", 69 | "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]", 70 | "vhdStorageName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]", 71 | "diagnosticsStorageAccountName": "[variables('vhdStorageName')]", 72 | "diagnosticsStorageAccountResourceGroup": "[resourcegroup().name]", 73 | "accountid": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', variables('diagnosticsStorageAccountResourceGroup'), '/providers/', 'Microsoft.Storage/storageAccounts/', variables('diagnosticsStorageAccountName'))]", 74 | "wadmetricsresourceid": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', variables('diagnosticsStorageAccountResourceGroup'), '/providers/', 'Microsoft.Compute/virtualMachines/', variables('vmName'))]" 75 | }, 76 | "resources": [ 77 | { 78 | "type": "Microsoft.Storage/storageAccounts", 79 | "name": "[variables('vhdStorageName')]", 80 | "apiVersion": "2015-06-15", 81 | "location": "[resourceGroup().location]", 82 | "tags": { 83 | "displayName": "StorageAccount" 84 | }, 85 | "properties": { 86 | "accountType": "[variables('vhdStorageType')]" 87 | } 88 | }, 89 | { 90 | "apiVersion": "2015-06-15", 91 | "type": "Microsoft.Network/publicIPAddresses", 92 | "name": "[variables('publicIPAddressName')]", 93 | "location": "[resourceGroup().location]", 94 | "tags": { 95 | "displayName": "PublicIPAddress" 96 | }, 97 | "properties": { 98 | "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 99 | "dnsSettings": { 100 | "domainNameLabel": "[parameters('dnsNameForPublicIP')]" 101 | } 102 | } 103 | }, 104 | { 105 | "apiVersion": "2015-06-15", 106 | "type": "Microsoft.Network/virtualNetworks", 107 | "name": "[variables('virtualNetworkName')]", 108 | "location": "[resourceGroup().location]", 109 | "tags": { 110 | "displayName": "VirtualNetwork" 111 | }, 112 | "properties": { 113 | "addressSpace": { 114 | "addressPrefixes": [ 115 | "[variables('addressPrefix')]" 116 | ] 117 | }, 118 | "subnets": [ 119 | { 120 | "name": "[variables('subnetName')]", 121 | "properties": { 122 | "addressPrefix": "[variables('subnetPrefix')]" 123 | } 124 | } 125 | ] 126 | } 127 | }, 128 | { 129 | "apiVersion": "2015-06-15", 130 | "type": "Microsoft.Network/networkInterfaces", 131 | "name": "[variables('nicName')]", 132 | "location": "[resourceGroup().location]", 133 | "tags": { 134 | "displayName": "NetworkInterface" 135 | }, 136 | "dependsOn": [ 137 | "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 138 | "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 139 | ], 140 | "properties": { 141 | "ipConfigurations": [ 142 | { 143 | "name": "ipconfig1", 144 | "properties": { 145 | "privateIPAllocationMethod": "Dynamic", 146 | "publicIPAddress": { 147 | "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 148 | }, 149 | "subnet": { 150 | "id": "[variables('subnetRef')]" 151 | } 152 | } 153 | } 154 | ] 155 | } 156 | }, 157 | { 158 | "apiVersion": "2015-06-15", 159 | "type": "Microsoft.Compute/virtualMachines", 160 | "name": "[variables('vmName')]", 161 | "location": "[resourceGroup().location]", 162 | "tags": { 163 | "displayName": "VirtualMachine" 164 | }, 165 | "dependsOn": [ 166 | "[concat('Microsoft.Storage/storageAccounts/', variables('vhdStorageName'))]", 167 | "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 168 | ], 169 | "properties": { 170 | "hardwareProfile": { 171 | "vmSize": "[variables('vmSize')]" 172 | }, 173 | "osProfile": { 174 | "computerName": "[variables('vmName')]", 175 | "adminUsername": "[parameters('adminUsername')]", 176 | "adminPassword": "[parameters('adminPassword')]" 177 | }, 178 | "storageProfile": { 179 | "imageReference": { 180 | "publisher": "[variables('imagePublisher')]", 181 | "offer": "[variables('imageOffer')]", 182 | "sku": "[parameters('windowsOSVersion')]", 183 | "version": "latest" 184 | }, 185 | "osDisk": { 186 | "name": "osdisk", 187 | "vhd": { 188 | "uri": "[concat('https://', variables('vhdStorageName'), '.blob.core.windows.net/', variables('vhdStorageContainerName'), '/', variables('OSDiskName'), '.vhd')]" 189 | }, 190 | "caching": "ReadWrite", 191 | "createOption": "FromImage" 192 | } 193 | }, 194 | "networkProfile": { 195 | "networkInterfaces": [ 196 | { 197 | "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 198 | } 199 | ] 200 | } 201 | }, 202 | "resources": [ 203 | { 204 | "type": "extensions", 205 | "apiVersion": "2015-06-15", 206 | "name": "Microsoft.Powershell.DSC", 207 | "location": "[resourceGroup().location]", 208 | "dependsOn": [ 209 | "[resourceId('Microsoft.Compute/virtualMachines',variables('vmName'))]" 210 | ], 211 | "properties": { 212 | "publisher": "Microsoft.Powershell", 213 | "type": "DSC", 214 | "typeHandlerVersion": "2.9", 215 | "autoUpgradeMinorVersion": true, 216 | "settings": { 217 | "Configuration": { 218 | "url": "https://armtfiles.blob.core.windows.net/templates/psdsc-configdata.ps1.zip", 219 | "script": "psdsc-configdata.ps1", 220 | "function": "Main" 221 | }, 222 | "configurationArguments": { 223 | "serviceName": "XPS-Viewer" 224 | 225 | }, 226 | "configurationData": { 227 | "url": "https://armtfiles.blob.core.windows.net/templates/configdata.psd1" 228 | } 229 | } 230 | 231 | } 232 | } 233 | ] 234 | } 235 | ] 236 | } 237 | -------------------------------------------------------------------------------- /Chapter05/Dsc-Basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "adminUsername": { 6 | "type": "string", 7 | "defaultValue": "citynextadmin", 8 | "minLength": 1, 9 | "metadata": { 10 | "description": "Username for the Virtual Machine." 11 | } 12 | }, 13 | "adminPassword": { 14 | "type": "securestring", 15 | "defaultValue": "citynext!1234", 16 | "metadata": { 17 | "description": "Password for the Virtual Machine." 18 | } 19 | }, 20 | "dnsNameForPublicIP": { 21 | "type": "string", 22 | "minLength": 1, 23 | "defaultValue": "jhunjhunbaba", 24 | "metadata": { 25 | "description": "Globally unique DNS Name for the Public IP used to access the Virtual Machine." 26 | } 27 | }, 28 | "windowsOSVersion": { 29 | "type": "string", 30 | "defaultValue": "2012-R2-Datacenter", 31 | "allowedValues": [ 32 | "2008-R2-SP1", 33 | "2012-Datacenter", 34 | "2012-R2-Datacenter" 35 | ], 36 | "metadata": { 37 | "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter." 38 | } 39 | }, 40 | "storageAccountName": { 41 | "type": "string" 42 | }, 43 | "containerName": { 44 | "type": "string" 45 | }, 46 | "zipfileName": { 47 | "type": "string" 48 | }, 49 | "fileName": { 50 | "type": "string" 51 | } 52 | }, 53 | "variables": { 54 | "imagePublisher": "MicrosoftWindowsServer", 55 | "imageOffer": "WindowsServer", 56 | "OSDiskName": "osdiskforwindowssimple", 57 | "nicName": "myVMNic", 58 | "addressPrefix": "10.0.0.0/16", 59 | "subnetName": "Subnet", 60 | "subnetPrefix": "10.0.0.0/24", 61 | "vhdStorageType": "Standard_LRS", 62 | "publicIPAddressName": "myPublicIP", 63 | "publicIPAddressType": "Dynamic", 64 | "vhdStorageContainerName": "vhds", 65 | "vmName": "MyWindowsVM", 66 | "vmSize": "Standard_A2", 67 | "virtualNetworkName": "MyVNET", 68 | "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]", 69 | "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]", 70 | "vhdStorageName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]", 71 | "diagnosticsStorageAccountName": "[variables('vhdStorageName')]", 72 | "diagnosticsStorageAccountResourceGroup": "[resourcegroup().name]", 73 | "accountid": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', variables('diagnosticsStorageAccountResourceGroup'), '/providers/', 'Microsoft.Storage/storageAccounts/', variables('diagnosticsStorageAccountName'))]", 74 | "wadmetricsresourceid": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', variables('diagnosticsStorageAccountResourceGroup'), '/providers/', 'Microsoft.Compute/virtualMachines/', variables('vmName'))]" 75 | }, 76 | "resources": [ 77 | { 78 | "type": "Microsoft.Storage/storageAccounts", 79 | "name": "[variables('vhdStorageName')]", 80 | "apiVersion": "2015-06-15", 81 | "location": "[resourceGroup().location]", 82 | "tags": { 83 | "displayName": "StorageAccount" 84 | }, 85 | "properties": { 86 | "accountType": "[variables('vhdStorageType')]" 87 | } 88 | }, 89 | { 90 | "apiVersion": "2015-06-15", 91 | "type": "Microsoft.Network/publicIPAddresses", 92 | "name": "[variables('publicIPAddressName')]", 93 | "location": "[resourceGroup().location]", 94 | "tags": { 95 | "displayName": "PublicIPAddress" 96 | }, 97 | "properties": { 98 | "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 99 | "dnsSettings": { 100 | "domainNameLabel": "[parameters('dnsNameForPublicIP')]" 101 | } 102 | } 103 | }, 104 | { 105 | "apiVersion": "2015-06-15", 106 | "type": "Microsoft.Network/virtualNetworks", 107 | "name": "[variables('virtualNetworkName')]", 108 | "location": "[resourceGroup().location]", 109 | "tags": { 110 | "displayName": "VirtualNetwork" 111 | }, 112 | "properties": { 113 | "addressSpace": { 114 | "addressPrefixes": [ 115 | "[variables('addressPrefix')]" 116 | ] 117 | }, 118 | "subnets": [ 119 | { 120 | "name": "[variables('subnetName')]", 121 | "properties": { 122 | "addressPrefix": "[variables('subnetPrefix')]" 123 | } 124 | } 125 | ] 126 | } 127 | }, 128 | { 129 | "apiVersion": "2015-06-15", 130 | "type": "Microsoft.Network/networkInterfaces", 131 | "name": "[variables('nicName')]", 132 | "location": "[resourceGroup().location]", 133 | "tags": { 134 | "displayName": "NetworkInterface" 135 | }, 136 | "dependsOn": [ 137 | "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 138 | "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 139 | ], 140 | "properties": { 141 | "ipConfigurations": [ 142 | { 143 | "name": "ipconfig1", 144 | "properties": { 145 | "privateIPAllocationMethod": "Dynamic", 146 | "publicIPAddress": { 147 | "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 148 | }, 149 | "subnet": { 150 | "id": "[variables('subnetRef')]" 151 | } 152 | } 153 | } 154 | ] 155 | } 156 | }, 157 | { 158 | "apiVersion": "2015-06-15", 159 | "type": "Microsoft.Compute/virtualMachines", 160 | "name": "[variables('vmName')]", 161 | "location": "[resourceGroup().location]", 162 | "tags": { 163 | "displayName": "VirtualMachine" 164 | }, 165 | "dependsOn": [ 166 | "[concat('Microsoft.Storage/storageAccounts/', variables('vhdStorageName'))]", 167 | "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 168 | ], 169 | "properties": { 170 | "hardwareProfile": { 171 | "vmSize": "[variables('vmSize')]" 172 | }, 173 | "osProfile": { 174 | "computerName": "[variables('vmName')]", 175 | "adminUsername": "[parameters('adminUsername')]", 176 | "adminPassword": "[parameters('adminPassword')]" 177 | }, 178 | "storageProfile": { 179 | "imageReference": { 180 | "publisher": "[variables('imagePublisher')]", 181 | "offer": "[variables('imageOffer')]", 182 | "sku": "[parameters('windowsOSVersion')]", 183 | "version": "latest" 184 | }, 185 | "osDisk": { 186 | "name": "osdisk", 187 | "vhd": { 188 | "uri": "[concat('https://', variables('vhdStorageName'), '.blob.core.windows.net/', variables('vhdStorageContainerName'), '/', variables('OSDiskName'), '.vhd')]" 189 | }, 190 | "caching": "ReadWrite", 191 | "createOption": "FromImage" 192 | } 193 | }, 194 | "networkProfile": { 195 | "networkInterfaces": [ 196 | { 197 | "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 198 | } 199 | ] 200 | } 201 | }, 202 | "resources": [ 203 | { 204 | "type": "extensions", 205 | "apiVersion": "2015-06-15", 206 | "name": "Microsoft.Powershell.DSC", 207 | "location": "[resourceGroup().location]", 208 | "dependsOn": [ 209 | "[resourceId('Microsoft.Compute/virtualMachines',variables('vmName'))]" 210 | ], 211 | "properties": { 212 | "publisher": "Microsoft.Powershell", 213 | "type": "DSC", 214 | "typeHandlerVersion": "2.9", 215 | "autoUpgradeMinorVersion": true, 216 | "settings": { 217 | "Configuration": { 218 | "url": "[concat(parameters('storageAccountName'),'/',parameters('containerName'),'/',parameters('zipfileName'))]", 219 | "script": "[parameters('fileName')]", 220 | "function": "Main" 221 | } 222 | } 223 | } 224 | } 225 | ] 226 | } 227 | ] 228 | } 229 | -------------------------------------------------------------------------------- /Chapter05/Install-IIS.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param 3 | 4 | ( [Parameter(Mandatory = $true)] 5 | [string] 6 | $featureName, [Parameter(Mandatory = $true)] 7 | [string] 8 | $serviceName 9 | ) 10 | 11 | Install-WindowsFeature -name $featureName -IncludeManagementTools -Verbose 12 | $service = Get-Service -Name $serviceName -ErrorAction Stop 13 | 14 | if ($service.StartType -ne 'Automatic') 15 | { 16 | Write-Verbose -Message "Setting startup type for $serviceName to automatic" 17 | Set-Service -Name $serviceName -StartupType Automatic 18 | } 19 | 20 | if ($service.Status -ne 'Running') 21 | { 22 | Write-Verbose -Message "Starting service $serviceName" 23 | Start-Service-Name$serviceName 24 | } 25 | -------------------------------------------------------------------------------- /Chapter05/Linux-CSA.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "adminUsername": { 6 | "type": "string", 7 | "defaultValue": "citynextadmin", 8 | "minLength": 1, 9 | "metadata": { 10 | "description": "Username for the Virtual Machine." 11 | } 12 | }, 13 | "adminPassword": { 14 | "type": "securestring", 15 | "defaultValue": "citynext!1234", 16 | "metadata": { 17 | "description": "Password for the Virtual Machine." 18 | } 19 | }, 20 | "dnsNameForPublicIP": { 21 | "type": "string", 22 | "minLength": 1, 23 | "defaultValue": "jhunjhunbaba", 24 | "metadata": { 25 | "description": "Globally unique DNS Name for the Public IP used to access the Virtual Machine." 26 | } 27 | }, 28 | "windowsOSVersion": { 29 | "type": "string", 30 | "defaultValue": "2012-R2-Datacenter", 31 | "allowedValues": [ 32 | "2008-R2-SP1", 33 | "2012-Datacenter", 34 | "2012-R2-Datacenter" 35 | ], 36 | "metadata": { 37 | "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter." 38 | } 39 | }, 40 | "storageAccountName": { 41 | "type": "string" 42 | }, 43 | "containerName": { 44 | "type": "string" 45 | }, 46 | "zipfileName": { 47 | "type": "string" 48 | }, 49 | "fileName": { 50 | "type": "string" 51 | } 52 | }, 53 | "variables": { 54 | "imagePublisher": "MicrosoftWindowsServer", 55 | "imageOffer": "WindowsServer", 56 | "OSDiskName": "osdiskforwindowssimple", 57 | "nicName": "myVMNic", 58 | "addressPrefix": "10.0.0.0/16", 59 | "subnetName": "Subnet", 60 | "subnetPrefix": "10.0.0.0/24", 61 | "vhdStorageType": "Standard_LRS", 62 | "publicIPAddressName": "myPublicIP", 63 | "publicIPAddressType": "Dynamic", 64 | "vhdStorageContainerName": "vhds", 65 | "vmName": "MyWindowsVM", 66 | "vmSize": "Standard_A2", 67 | "virtualNetworkName": "MyVNET", 68 | "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]", 69 | "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]", 70 | "vhdStorageName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]", 71 | "diagnosticsStorageAccountName": "[variables('vhdStorageName')]", 72 | "diagnosticsStorageAccountResourceGroup": "[resourcegroup().name]", 73 | "accountid": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', variables('diagnosticsStorageAccountResourceGroup'), '/providers/', 'Microsoft.Storage/storageAccounts/', variables('diagnosticsStorageAccountName'))]", 74 | "wadmetricsresourceid": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', variables('diagnosticsStorageAccountResourceGroup'), '/providers/', 'Microsoft.Compute/virtualMachines/', variables('vmName'))]" 75 | }, 76 | "resources": [ 77 | { 78 | "type": "Microsoft.Storage/storageAccounts", 79 | "name": "[variables('vhdStorageName')]", 80 | "apiVersion": "2015-06-15", 81 | "location": "[resourceGroup().location]", 82 | "tags": { 83 | "displayName": "StorageAccount" 84 | }, 85 | "properties": { 86 | "accountType": "[variables('vhdStorageType')]" 87 | } 88 | }, 89 | { 90 | "apiVersion": "2015-06-15", 91 | "type": "Microsoft.Network/publicIPAddresses", 92 | "name": "[variables('publicIPAddressName')]", 93 | "location": "[resourceGroup().location]", 94 | "tags": { 95 | "displayName": "PublicIPAddress" 96 | }, 97 | "properties": { 98 | "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 99 | "dnsSettings": { 100 | "domainNameLabel": "[parameters('dnsNameForPublicIP')]" 101 | } 102 | } 103 | }, 104 | { 105 | "apiVersion": "2015-06-15", 106 | "type": "Microsoft.Network/virtualNetworks", 107 | "name": "[variables('virtualNetworkName')]", 108 | "location": "[resourceGroup().location]", 109 | "tags": { 110 | "displayName": "VirtualNetwork" 111 | }, 112 | "properties": { 113 | "addressSpace": { 114 | "addressPrefixes": [ 115 | "[variables('addressPrefix')]" 116 | ] 117 | }, 118 | "subnets": [ 119 | { 120 | "name": "[variables('subnetName')]", 121 | "properties": { 122 | "addressPrefix": "[variables('subnetPrefix')]" 123 | } 124 | } 125 | ] 126 | } 127 | }, 128 | { 129 | "apiVersion": "2015-06-15", 130 | "type": "Microsoft.Network/networkInterfaces", 131 | "name": "[variables('nicName')]", 132 | "location": "[resourceGroup().location]", 133 | "tags": { 134 | "displayName": "NetworkInterface" 135 | }, 136 | "dependsOn": [ 137 | "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 138 | "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 139 | ], 140 | "properties": { 141 | "ipConfigurations": [ 142 | { 143 | "name": "ipconfig1", 144 | "properties": { 145 | "privateIPAllocationMethod": "Dynamic", 146 | "publicIPAddress": { 147 | "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 148 | }, 149 | "subnet": { 150 | "id": "[variables('subnetRef')]" 151 | } 152 | } 153 | } 154 | ] 155 | } 156 | }, 157 | { 158 | "apiVersion": "2015-06-15", 159 | "type": "Microsoft.Compute/virtualMachines", 160 | "name": "[variables('vmName')]", 161 | "location": "[resourceGroup().location]", 162 | "tags": { 163 | "displayName": "VirtualMachine" 164 | }, 165 | "dependsOn": [ 166 | "[concat('Microsoft.Storage/storageAccounts/', variables('vhdStorageName'))]", 167 | "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 168 | ], 169 | "properties": { 170 | "hardwareProfile": { 171 | "vmSize": "[variables('vmSize')]" 172 | }, 173 | "osProfile": { 174 | "computerName": "[variables('vmName')]", 175 | "adminUsername": "[parameters('adminUsername')]", 176 | "adminPassword": "[parameters('adminPassword')]" 177 | }, 178 | "storageProfile": { 179 | "imageReference": { 180 | "publisher": "[variables('imagePublisher')]", 181 | "offer": "[variables('imageOffer')]", 182 | "sku": "[parameters('windowsOSVersion')]", 183 | "version": "latest" 184 | }, 185 | "osDisk": { 186 | "name": "osdisk", 187 | "vhd": { 188 | "uri": "[concat('https://', variables('vhdStorageName'), '.blob.core.windows.net/', variables('vhdStorageContainerName'), '/', variables('OSDiskName'), '.vhd')]" 189 | }, 190 | "caching": "ReadWrite", 191 | "createOption": "FromImage" 192 | } 193 | }, 194 | "networkProfile": { 195 | "networkInterfaces": [ 196 | { 197 | "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 198 | } 199 | ] 200 | } 201 | }, 202 | "resources": [ 203 | { 204 | "apiVersion": "2015-06-15", 205 | "type": "Microsoft.Compute/virtualMachines/extensions", 206 | "name": "[concat(variables('vmName'), '/', 'linuxscripts')]", 207 | "location": "[resourceGroup().location]", 208 | "dependsOn": [ 209 | "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]" 210 | ], 211 | "tags": { 212 | "displayName": "config-app" 213 | }, 214 | "properties": { 215 | "publisher": "Microsoft.OSTCExtensions", 216 | "type": "CustomScriptForLinux", 217 | "typeHandlerVersion": "1.2", 218 | "autoUpgradeMinorVersion": true, 219 | "settings": { 220 | "fileUris": [ 221 | "https://allarmfiles.blob.core.windows.net/armfiles/first.sh" 222 | ], 223 | "commandToExecute": "[concat('sh first.sh ','argument1 ','argument2 ', 'argument 3 ')]" 224 | } 225 | } 226 | } 227 | ] 228 | } 229 | ] 230 | } 231 | -------------------------------------------------------------------------------- /Chapter05/Seperateresource.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "adminUsername": { 6 | "type": "string", 7 | "minLength": 1, 8 | "metadata": { 9 | "description": "Username for the Virtual Machine." 10 | } 11 | }, 12 | "adminPassword": { 13 | "type": "securestring", 14 | "metadata": { 15 | "description": "Password for the Virtual Machine." 16 | } 17 | }, 18 | "dnsNameForPublicIP": { 19 | "type": "string", 20 | "minLength": 1, 21 | "metadata": { 22 | "description": "Globally unique DNS Name for the Public IP used to access the Virtual Machine." 23 | } 24 | }, 25 | "windowsOSVersion": { 26 | "type": "string", 27 | "defaultValue": "2012-R2-Datacenter", 28 | "allowedValues": [ 29 | "2008-R2-SP1", 30 | "2012-Datacenter", 31 | "2012-R2-Datacenter" 32 | ], 33 | "metadata": { 34 | "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter." 35 | } 36 | }, 37 | "storageAccountName": { 38 | "type": "string", 39 | "metadata": { 40 | "description": "Auto-generated container in staging storage account to receive post-build staging folder upload" 41 | } 42 | } 43 | 44 | }, 45 | "variables": { 46 | "imagePublisher": "MicrosoftWindowsServer", 47 | "imageOffer": "WindowsServer", 48 | "OSDiskName": "osdiskforwindowssimple", 49 | "nicName": "myVMNic", 50 | "addressPrefix": "10.0.0.0/16", 51 | "subnetName": "Subnet", 52 | "subnetPrefix": "10.0.0.0/24", 53 | "vhdStorageType": "Standard_LRS", 54 | "publicIPAddressName": "myPublicIP", 55 | "publicIPAddressType": "Dynamic", 56 | "vhdStorageContainerName": "vhds", 57 | "vmName": "MyWindowsVM", 58 | "vmSize": "Standard_A2", 59 | "virtualNetworkName": "MyVNET", 60 | "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]", 61 | "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]", 62 | "vhdStorageAccountName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]", 63 | "diagnosticsStorageAccountName": "[variables('vhdStorageAccountName')]", 64 | "wadmetricsresourceid": "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]", 65 | "firstCustomScriptExtensionScriptStorageContainer": "templates", 66 | "firstCustomScriptExtensionScriptFileName": "install-IIS.ps1" 67 | }, 68 | "resources": [ 69 | { 70 | "type": "Microsoft.Storage/storageAccounts", 71 | "name": "[variables('vhdStorageAccountName')]", 72 | "apiVersion": "2016-01-01", 73 | "location": "[resourceGroup().location]", 74 | "tags": { 75 | "displayName": "StorageAccount" 76 | }, 77 | "sku": { 78 | "name": "[variables('vhdStorageType')]" 79 | }, 80 | "kind": "Storage" 81 | }, 82 | { 83 | "apiVersion": "2016-03-30", 84 | "type": "Microsoft.Network/publicIPAddresses", 85 | "name": "[variables('publicIPAddressName')]", 86 | "location": "[resourceGroup().location]", 87 | "tags": { 88 | "displayName": "PublicIPAddress" 89 | }, 90 | "properties": { 91 | "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 92 | "dnsSettings": { 93 | "domainNameLabel": "[parameters('dnsNameForPublicIP')]" 94 | } 95 | } 96 | }, 97 | { 98 | "apiVersion": "2016-03-30", 99 | "type": "Microsoft.Network/virtualNetworks", 100 | "name": "[variables('virtualNetworkName')]", 101 | "location": "[resourceGroup().location]", 102 | "tags": { 103 | "displayName": "VirtualNetwork" 104 | }, 105 | "properties": { 106 | "addressSpace": { 107 | "addressPrefixes": [ 108 | "[variables('addressPrefix')]" 109 | ] 110 | }, 111 | "subnets": [ 112 | { 113 | "name": "[variables('subnetName')]", 114 | "properties": { 115 | "addressPrefix": "[variables('subnetPrefix')]" 116 | } 117 | } 118 | ] 119 | } 120 | }, 121 | { 122 | "apiVersion": "2016-03-30", 123 | "type": "Microsoft.Network/networkInterfaces", 124 | "name": "[variables('nicName')]", 125 | "location": "[resourceGroup().location]", 126 | "tags": { 127 | "displayName": "NetworkInterface" 128 | }, 129 | "dependsOn": [ 130 | "[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 131 | "[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 132 | ], 133 | "properties": { 134 | "ipConfigurations": [ 135 | { 136 | "name": "ipconfig1", 137 | "properties": { 138 | "privateIPAllocationMethod": "Dynamic", 139 | "publicIPAddress": { 140 | "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 141 | }, 142 | "subnet": { 143 | "id": "[variables('subnetRef')]" 144 | } 145 | } 146 | } 147 | ] 148 | } 149 | }, 150 | { 151 | "apiVersion": "2015-06-15", 152 | "type": "Microsoft.Compute/virtualMachines", 153 | "name": "[variables('vmName')]", 154 | "location": "[resourceGroup().location]", 155 | "tags": { 156 | "displayName": "VirtualMachine" 157 | }, 158 | "dependsOn": [ 159 | "[resourceId('Microsoft.Storage/storageAccounts/', variables('vhdStorageAccountName'))]", 160 | "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 161 | ], 162 | "properties": { 163 | "hardwareProfile": { 164 | "vmSize": "[variables('vmSize')]" 165 | }, 166 | "osProfile": { 167 | "computerName": "[variables('vmName')]", 168 | "adminUsername": "[parameters('adminUsername')]", 169 | "adminPassword": "[parameters('adminPassword')]" 170 | }, 171 | "storageProfile": { 172 | "imageReference": { 173 | "publisher": "[variables('imagePublisher')]", 174 | "offer": "[variables('imageOffer')]", 175 | "sku": "[parameters('windowsOSVersion')]", 176 | "version": "latest" 177 | }, 178 | "osDisk": { 179 | "name": "osdisk", 180 | "vhd": { 181 | "uri": "[concat(reference(resourceId('Microsoft.Storage/storageAccounts', variables('vhdStorageAccountName')), '2016-01-01').primaryEndpoints.blob, variables('vhdStorageContainerName'), '/', variables('OSDiskName'), '.vhd')]" 182 | }, 183 | "caching": "ReadWrite", 184 | "createOption": "FromImage" 185 | } 186 | }, 187 | "networkProfile": { 188 | "networkInterfaces": [ 189 | { 190 | "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 191 | } 192 | ] 193 | }, 194 | "diagnosticsProfile": { 195 | "bootDiagnostics": { 196 | "enabled": true, 197 | "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('vhdStorageAccountName')), '2016-01-01').primaryEndpoints.blob]" 198 | } 199 | } 200 | }, 201 | "resources": [ 202 | { 203 | "type": "extensions", 204 | "name": "Microsoft.Insights.VMDiagnosticsSettings", 205 | "apiVersion": "2016-03-30", 206 | "location": "[resourceGroup().location]", 207 | "tags": { 208 | "displayName": "AzureDiagnostics" 209 | }, 210 | "dependsOn": [ 211 | "[resourceId('Microsoft.Compute/virtualMachines/', variables('vmName'))]" 212 | ], 213 | "properties": { 214 | "publisher": "Microsoft.Azure.Diagnostics", 215 | "type": "IaaSDiagnostics", 216 | "typeHandlerVersion": "1.5", 217 | "autoUpgradeMinorVersion": true, 218 | "settings": { 219 | "WadCfg": { 220 | "DiagnosticMonitorConfiguration": { 221 | "overallQuotaInMB": "4096", 222 | "DiagnosticInfrastructureLogs": { 223 | "scheduledTransferLogLevelFilter": "Error" 224 | }, 225 | "WindowsEventLog": { 226 | "scheduledTransferPeriod": "PT1M", 227 | "DataSource": [ 228 | { 229 | "name": "Application!*[System[(Level = 1) or (Level = 2)]]" 230 | }, 231 | { 232 | "name": "Security!*[System[(Level = 1 or Level = 2)]]" 233 | }, 234 | { 235 | "name": "System!*[System[(Level = 1 or Level = 2)]]" 236 | } 237 | ] 238 | }, 239 | "PerformanceCounters": { 240 | "scheduledTransferPeriod": "PT1M", 241 | "PerformanceCounterConfiguration": [ 242 | { 243 | "counterSpecifier": "\\Processor(_Total)\\% Processor Time", 244 | "sampleRate": "PT15S", 245 | "unit": "Percent", 246 | "annotation": [ 247 | { 248 | "displayName": "CPU utilization", 249 | "locale": "en-us" 250 | } 251 | ] 252 | }, 253 | { 254 | "counterSpecifier": "\\Processor(_Total)\\% Privileged Time", 255 | "sampleRate": "PT15S", 256 | "unit": "Percent", 257 | "annotation": [ 258 | { 259 | "displayName": "CPU privileged time", 260 | "locale": "en-us" 261 | } 262 | ] 263 | }, 264 | { 265 | "counterSpecifier": "\\Processor(_Total)\\% User Time", 266 | "sampleRate": "PT15S", 267 | "unit": "Percent", 268 | "annotation": [ 269 | { 270 | "displayName": "CPU user time", 271 | "locale": "en-us" 272 | } 273 | ] 274 | }, 275 | { 276 | "counterSpecifier": "\\Processor Information(_Total)\\Processor Frequency", 277 | "sampleRate": "PT15S", 278 | "unit": "Count", 279 | "annotation": [ 280 | { 281 | "displayName": "CPU frequency", 282 | "locale": "en-us" 283 | } 284 | ] 285 | }, 286 | { 287 | "counterSpecifier": "\\System\\Processes", 288 | "sampleRate": "PT15S", 289 | "unit": "Count", 290 | "annotation": [ 291 | { 292 | "displayName": "Processes", 293 | "locale": "en-us" 294 | } 295 | ] 296 | }, 297 | { 298 | "counterSpecifier": "\\Process(_Total)\\Thread Count", 299 | "sampleRate": "PT15S", 300 | "unit": "Count", 301 | "annotation": [ 302 | { 303 | "displayName": "Threads", 304 | "locale": "en-us" 305 | } 306 | ] 307 | }, 308 | { 309 | "counterSpecifier": "\\Process(_Total)\\Handle Count", 310 | "sampleRate": "PT15S", 311 | "unit": "Count", 312 | "annotation": [ 313 | { 314 | "displayName": "Handles", 315 | "locale": "en-us" 316 | } 317 | ] 318 | }, 319 | { 320 | "counterSpecifier": "\\Memory\\% Committed Bytes In Use", 321 | "sampleRate": "PT15S", 322 | "unit": "Percent", 323 | "annotation": [ 324 | { 325 | "displayName": "Memory usage", 326 | "locale": "en-us" 327 | } 328 | ] 329 | }, 330 | { 331 | "counterSpecifier": "\\Memory\\Available Bytes", 332 | "sampleRate": "PT15S", 333 | "unit": "Bytes", 334 | "annotation": [ 335 | { 336 | "displayName": "Memory available", 337 | "locale": "en-us" 338 | } 339 | ] 340 | }, 341 | { 342 | "counterSpecifier": "\\Memory\\Committed Bytes", 343 | "sampleRate": "PT15S", 344 | "unit": "Bytes", 345 | "annotation": [ 346 | { 347 | "displayName": "Memory committed", 348 | "locale": "en-us" 349 | } 350 | ] 351 | }, 352 | { 353 | "counterSpecifier": "\\Memory\\Commit Limit", 354 | "sampleRate": "PT15S", 355 | "unit": "Bytes", 356 | "annotation": [ 357 | { 358 | "displayName": "Memory commit limit", 359 | "locale": "en-us" 360 | } 361 | ] 362 | }, 363 | { 364 | "counterSpecifier": "\\PhysicalDisk(_Total)\\% Disk Time", 365 | "sampleRate": "PT15S", 366 | "unit": "Percent", 367 | "annotation": [ 368 | { 369 | "displayName": "Disk active time", 370 | "locale": "en-us" 371 | } 372 | ] 373 | }, 374 | { 375 | "counterSpecifier": "\\PhysicalDisk(_Total)\\% Disk Read Time", 376 | "sampleRate": "PT15S", 377 | "unit": "Percent", 378 | "annotation": [ 379 | { 380 | "displayName": "Disk active read time", 381 | "locale": "en-us" 382 | } 383 | ] 384 | }, 385 | { 386 | "counterSpecifier": "\\PhysicalDisk(_Total)\\% Disk Write Time", 387 | "sampleRate": "PT15S", 388 | "unit": "Percent", 389 | "annotation": [ 390 | { 391 | "displayName": "Disk active write time", 392 | "locale": "en-us" 393 | } 394 | ] 395 | }, 396 | { 397 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Transfers/sec", 398 | "sampleRate": "PT15S", 399 | "unit": "CountPerSecond", 400 | "annotation": [ 401 | { 402 | "displayName": "Disk operations", 403 | "locale": "en-us" 404 | } 405 | ] 406 | }, 407 | { 408 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Reads/sec", 409 | "sampleRate": "PT15S", 410 | "unit": "CountPerSecond", 411 | "annotation": [ 412 | { 413 | "displayName": "Disk read operations", 414 | "locale": "en-us" 415 | } 416 | ] 417 | }, 418 | { 419 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Writes/sec", 420 | "sampleRate": "PT15S", 421 | "unit": "CountPerSecond", 422 | "annotation": [ 423 | { 424 | "displayName": "Disk write operations", 425 | "locale": "en-us" 426 | } 427 | ] 428 | }, 429 | { 430 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Bytes/sec", 431 | "sampleRate": "PT15S", 432 | "unit": "BytesPerSecond", 433 | "annotation": [ 434 | { 435 | "displayName": "Disk speed", 436 | "locale": "en-us" 437 | } 438 | ] 439 | }, 440 | { 441 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Read Bytes/sec", 442 | "sampleRate": "PT15S", 443 | "unit": "BytesPerSecond", 444 | "annotation": [ 445 | { 446 | "displayName": "Disk read speed", 447 | "locale": "en-us" 448 | } 449 | ] 450 | }, 451 | { 452 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Write Bytes/sec", 453 | "sampleRate": "PT15S", 454 | "unit": "BytesPerSecond", 455 | "annotation": [ 456 | { 457 | "displayName": "Disk write speed", 458 | "locale": "en-us" 459 | } 460 | ] 461 | }, 462 | { 463 | "counterSpecifier": "\\LogicalDisk(_Total)\\% Free Space", 464 | "sampleRate": "PT15S", 465 | "unit": "Percent", 466 | "annotation": [ 467 | { 468 | "displayName": "Disk free space (percentage)", 469 | "locale": "en-us" 470 | } 471 | ] 472 | } 473 | ] 474 | }, 475 | "Metrics": { 476 | "resourceId": "[variables('wadmetricsresourceid')]", 477 | "MetricAggregation": [ 478 | { 479 | "scheduledTransferPeriod": "PT1H" 480 | }, 481 | { 482 | "scheduledTransferPeriod": "PT1M" 483 | } 484 | ] 485 | } 486 | } 487 | } 488 | }, 489 | "protectedSettings": { 490 | "storageAccountName": "[variables('diagnosticsStorageAccountName')]", 491 | "storageAccountKey": "[listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('diagnosticsStorageAccountName')), '2016-01-01').keys[0].value]" 492 | } 493 | } 494 | } 495 | 496 | 497 | ] 498 | }, 499 | { 500 | "name": "[concat(variables('vmName'),'/','firstCustomScriptExtension')]", 501 | "type": "Microsoft.Compute/virtualMachines/extensions", 502 | "location": "[resourceGroup().location]", 503 | "apiVersion": "2016-03-30", 504 | "dependsOn": [ 505 | "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]" 506 | ], 507 | "tags": { 508 | "displayName": "firstCustomScriptExtension" 509 | }, 510 | "properties": { 511 | "publisher": "Microsoft.Compute", 512 | "type": "CustomScriptExtension", 513 | "typeHandlerVersion": "1.4", 514 | "autoUpgradeMinorVersion": true, 515 | "settings": { 516 | "fileUris": [ 517 | "[concat(parameters('storageAccountName'), '/', variables('firstCustomScriptExtensionScriptStorageContainer'), '/', variables('firstCustomScriptExtensionScriptFileName'))]" 518 | ], 519 | "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstCustomScriptExtensionScriptFileName'), ' -featureName web-server -serviceName w3svc')]" 520 | } 521 | 522 | } 523 | } 524 | ] 525 | 526 | } 527 | -------------------------------------------------------------------------------- /Chapter05/WindowsVirtualMachine.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "adminUsername": { 6 | "type": "string", 7 | "minLength": 1, 8 | "metadata": { 9 | "description": "Username for the Virtual Machine." 10 | } 11 | }, 12 | "adminPassword": { 13 | "type": "securestring", 14 | "metadata": { 15 | "description": "Password for the Virtual Machine." 16 | } 17 | }, 18 | "dnsNameForPublicIP": { 19 | "type": "string", 20 | "minLength": 1, 21 | "metadata": { 22 | "description": "Globally unique DNS Name for the Public IP used to access the Virtual Machine." 23 | } 24 | }, 25 | "windowsOSVersion": { 26 | "type": "string", 27 | "defaultValue": "2012-R2-Datacenter", 28 | "allowedValues": [ 29 | "2008-R2-SP1", 30 | "2012-Datacenter", 31 | "2012-R2-Datacenter" 32 | ], 33 | "metadata": { 34 | "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter." 35 | } 36 | }, 37 | "storageAccountName": { 38 | "type": "string", 39 | "metadata": { 40 | "description": "Auto-generated container in staging storage account to receive post-build staging folder upload" 41 | } 42 | } 43 | 44 | }, 45 | "variables": { 46 | "imagePublisher": "MicrosoftWindowsServer", 47 | "imageOffer": "WindowsServer", 48 | "OSDiskName": "osdiskforwindowssimple", 49 | "nicName": "myVMNic", 50 | "addressPrefix": "10.0.0.0/16", 51 | "subnetName": "Subnet", 52 | "subnetPrefix": "10.0.0.0/24", 53 | "vhdStorageType": "Standard_LRS", 54 | "publicIPAddressName": "myPublicIP", 55 | "publicIPAddressType": "Dynamic", 56 | "vhdStorageContainerName": "vhds", 57 | "vmName": "MyWindowsVM", 58 | "vmSize": "Standard_A2", 59 | "virtualNetworkName": "MyVNET", 60 | "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]", 61 | "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]", 62 | "vhdStorageAccountName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]", 63 | "diagnosticsStorageAccountName": "[variables('vhdStorageAccountName')]", 64 | "wadmetricsresourceid": "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]", 65 | "firstCustomScriptExtensionScriptStorageContainer": "templates", 66 | "firstCustomScriptExtensionScriptFileName": "install-IIS.ps1" 67 | }, 68 | "resources": [ 69 | { 70 | "type": "Microsoft.Storage/storageAccounts", 71 | "name": "[variables('vhdStorageAccountName')]", 72 | "apiVersion": "2016-01-01", 73 | "location": "[resourceGroup().location]", 74 | "tags": { 75 | "displayName": "StorageAccount" 76 | }, 77 | "sku": { 78 | "name": "[variables('vhdStorageType')]" 79 | }, 80 | "kind": "Storage" 81 | }, 82 | { 83 | "apiVersion": "2016-03-30", 84 | "type": "Microsoft.Network/publicIPAddresses", 85 | "name": "[variables('publicIPAddressName')]", 86 | "location": "[resourceGroup().location]", 87 | "tags": { 88 | "displayName": "PublicIPAddress" 89 | }, 90 | "properties": { 91 | "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 92 | "dnsSettings": { 93 | "domainNameLabel": "[parameters('dnsNameForPublicIP')]" 94 | } 95 | } 96 | }, 97 | { 98 | "apiVersion": "2016-03-30", 99 | "type": "Microsoft.Network/virtualNetworks", 100 | "name": "[variables('virtualNetworkName')]", 101 | "location": "[resourceGroup().location]", 102 | "tags": { 103 | "displayName": "VirtualNetwork" 104 | }, 105 | "properties": { 106 | "addressSpace": { 107 | "addressPrefixes": [ 108 | "[variables('addressPrefix')]" 109 | ] 110 | }, 111 | "subnets": [ 112 | { 113 | "name": "[variables('subnetName')]", 114 | "properties": { 115 | "addressPrefix": "[variables('subnetPrefix')]" 116 | } 117 | } 118 | ] 119 | } 120 | }, 121 | { 122 | "apiVersion": "2016-03-30", 123 | "type": "Microsoft.Network/networkInterfaces", 124 | "name": "[variables('nicName')]", 125 | "location": "[resourceGroup().location]", 126 | "tags": { 127 | "displayName": "NetworkInterface" 128 | }, 129 | "dependsOn": [ 130 | "[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 131 | "[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 132 | ], 133 | "properties": { 134 | "ipConfigurations": [ 135 | { 136 | "name": "ipconfig1", 137 | "properties": { 138 | "privateIPAllocationMethod": "Dynamic", 139 | "publicIPAddress": { 140 | "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 141 | }, 142 | "subnet": { 143 | "id": "[variables('subnetRef')]" 144 | } 145 | } 146 | } 147 | ] 148 | } 149 | }, 150 | { 151 | "apiVersion": "2015-06-15", 152 | "type": "Microsoft.Compute/virtualMachines", 153 | "name": "[variables('vmName')]", 154 | "location": "[resourceGroup().location]", 155 | "tags": { 156 | "displayName": "VirtualMachine" 157 | }, 158 | "dependsOn": [ 159 | "[resourceId('Microsoft.Storage/storageAccounts/', variables('vhdStorageAccountName'))]", 160 | "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 161 | ], 162 | "properties": { 163 | "hardwareProfile": { 164 | "vmSize": "[variables('vmSize')]" 165 | }, 166 | "osProfile": { 167 | "computerName": "[variables('vmName')]", 168 | "adminUsername": "[parameters('adminUsername')]", 169 | "adminPassword": "[parameters('adminPassword')]" 170 | }, 171 | "storageProfile": { 172 | "imageReference": { 173 | "publisher": "[variables('imagePublisher')]", 174 | "offer": "[variables('imageOffer')]", 175 | "sku": "[parameters('windowsOSVersion')]", 176 | "version": "latest" 177 | }, 178 | "osDisk": { 179 | "name": "osdisk", 180 | "vhd": { 181 | "uri": "[concat(reference(resourceId('Microsoft.Storage/storageAccounts', variables('vhdStorageAccountName')), '2016-01-01').primaryEndpoints.blob, variables('vhdStorageContainerName'), '/', variables('OSDiskName'), '.vhd')]" 182 | }, 183 | "caching": "ReadWrite", 184 | "createOption": "FromImage" 185 | } 186 | }, 187 | "networkProfile": { 188 | "networkInterfaces": [ 189 | { 190 | "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 191 | } 192 | ] 193 | }, 194 | "diagnosticsProfile": { 195 | "bootDiagnostics": { 196 | "enabled": true, 197 | "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('vhdStorageAccountName')), '2016-01-01').primaryEndpoints.blob]" 198 | } 199 | } 200 | }, 201 | "resources": [ 202 | { 203 | "type": "extensions", 204 | "name": "Microsoft.Insights.VMDiagnosticsSettings", 205 | "apiVersion": "2016-03-30", 206 | "location": "[resourceGroup().location]", 207 | "tags": { 208 | "displayName": "AzureDiagnostics" 209 | }, 210 | "dependsOn": [ 211 | "[resourceId('Microsoft.Compute/virtualMachines/', variables('vmName'))]" 212 | ], 213 | "properties": { 214 | "publisher": "Microsoft.Azure.Diagnostics", 215 | "type": "IaaSDiagnostics", 216 | "typeHandlerVersion": "1.5", 217 | "autoUpgradeMinorVersion": true, 218 | "settings": { 219 | "WadCfg": { 220 | "DiagnosticMonitorConfiguration": { 221 | "overallQuotaInMB": "4096", 222 | "DiagnosticInfrastructureLogs": { 223 | "scheduledTransferLogLevelFilter": "Error" 224 | }, 225 | "WindowsEventLog": { 226 | "scheduledTransferPeriod": "PT1M", 227 | "DataSource": [ 228 | { 229 | "name": "Application!*[System[(Level = 1) or (Level = 2)]]" 230 | }, 231 | { 232 | "name": "Security!*[System[(Level = 1 or Level = 2)]]" 233 | }, 234 | { 235 | "name": "System!*[System[(Level = 1 or Level = 2)]]" 236 | } 237 | ] 238 | }, 239 | "PerformanceCounters": { 240 | "scheduledTransferPeriod": "PT1M", 241 | "PerformanceCounterConfiguration": [ 242 | { 243 | "counterSpecifier": "\\Processor(_Total)\\% Processor Time", 244 | "sampleRate": "PT15S", 245 | "unit": "Percent", 246 | "annotation": [ 247 | { 248 | "displayName": "CPU utilization", 249 | "locale": "en-us" 250 | } 251 | ] 252 | }, 253 | { 254 | "counterSpecifier": "\\Processor(_Total)\\% Privileged Time", 255 | "sampleRate": "PT15S", 256 | "unit": "Percent", 257 | "annotation": [ 258 | { 259 | "displayName": "CPU privileged time", 260 | "locale": "en-us" 261 | } 262 | ] 263 | }, 264 | { 265 | "counterSpecifier": "\\Processor(_Total)\\% User Time", 266 | "sampleRate": "PT15S", 267 | "unit": "Percent", 268 | "annotation": [ 269 | { 270 | "displayName": "CPU user time", 271 | "locale": "en-us" 272 | } 273 | ] 274 | }, 275 | { 276 | "counterSpecifier": "\\Processor Information(_Total)\\Processor Frequency", 277 | "sampleRate": "PT15S", 278 | "unit": "Count", 279 | "annotation": [ 280 | { 281 | "displayName": "CPU frequency", 282 | "locale": "en-us" 283 | } 284 | ] 285 | }, 286 | { 287 | "counterSpecifier": "\\System\\Processes", 288 | "sampleRate": "PT15S", 289 | "unit": "Count", 290 | "annotation": [ 291 | { 292 | "displayName": "Processes", 293 | "locale": "en-us" 294 | } 295 | ] 296 | }, 297 | { 298 | "counterSpecifier": "\\Process(_Total)\\Thread Count", 299 | "sampleRate": "PT15S", 300 | "unit": "Count", 301 | "annotation": [ 302 | { 303 | "displayName": "Threads", 304 | "locale": "en-us" 305 | } 306 | ] 307 | }, 308 | { 309 | "counterSpecifier": "\\Process(_Total)\\Handle Count", 310 | "sampleRate": "PT15S", 311 | "unit": "Count", 312 | "annotation": [ 313 | { 314 | "displayName": "Handles", 315 | "locale": "en-us" 316 | } 317 | ] 318 | }, 319 | { 320 | "counterSpecifier": "\\Memory\\% Committed Bytes In Use", 321 | "sampleRate": "PT15S", 322 | "unit": "Percent", 323 | "annotation": [ 324 | { 325 | "displayName": "Memory usage", 326 | "locale": "en-us" 327 | } 328 | ] 329 | }, 330 | { 331 | "counterSpecifier": "\\Memory\\Available Bytes", 332 | "sampleRate": "PT15S", 333 | "unit": "Bytes", 334 | "annotation": [ 335 | { 336 | "displayName": "Memory available", 337 | "locale": "en-us" 338 | } 339 | ] 340 | }, 341 | { 342 | "counterSpecifier": "\\Memory\\Committed Bytes", 343 | "sampleRate": "PT15S", 344 | "unit": "Bytes", 345 | "annotation": [ 346 | { 347 | "displayName": "Memory committed", 348 | "locale": "en-us" 349 | } 350 | ] 351 | }, 352 | { 353 | "counterSpecifier": "\\Memory\\Commit Limit", 354 | "sampleRate": "PT15S", 355 | "unit": "Bytes", 356 | "annotation": [ 357 | { 358 | "displayName": "Memory commit limit", 359 | "locale": "en-us" 360 | } 361 | ] 362 | }, 363 | { 364 | "counterSpecifier": "\\PhysicalDisk(_Total)\\% Disk Time", 365 | "sampleRate": "PT15S", 366 | "unit": "Percent", 367 | "annotation": [ 368 | { 369 | "displayName": "Disk active time", 370 | "locale": "en-us" 371 | } 372 | ] 373 | }, 374 | { 375 | "counterSpecifier": "\\PhysicalDisk(_Total)\\% Disk Read Time", 376 | "sampleRate": "PT15S", 377 | "unit": "Percent", 378 | "annotation": [ 379 | { 380 | "displayName": "Disk active read time", 381 | "locale": "en-us" 382 | } 383 | ] 384 | }, 385 | { 386 | "counterSpecifier": "\\PhysicalDisk(_Total)\\% Disk Write Time", 387 | "sampleRate": "PT15S", 388 | "unit": "Percent", 389 | "annotation": [ 390 | { 391 | "displayName": "Disk active write time", 392 | "locale": "en-us" 393 | } 394 | ] 395 | }, 396 | { 397 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Transfers/sec", 398 | "sampleRate": "PT15S", 399 | "unit": "CountPerSecond", 400 | "annotation": [ 401 | { 402 | "displayName": "Disk operations", 403 | "locale": "en-us" 404 | } 405 | ] 406 | }, 407 | { 408 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Reads/sec", 409 | "sampleRate": "PT15S", 410 | "unit": "CountPerSecond", 411 | "annotation": [ 412 | { 413 | "displayName": "Disk read operations", 414 | "locale": "en-us" 415 | } 416 | ] 417 | }, 418 | { 419 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Writes/sec", 420 | "sampleRate": "PT15S", 421 | "unit": "CountPerSecond", 422 | "annotation": [ 423 | { 424 | "displayName": "Disk write operations", 425 | "locale": "en-us" 426 | } 427 | ] 428 | }, 429 | { 430 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Bytes/sec", 431 | "sampleRate": "PT15S", 432 | "unit": "BytesPerSecond", 433 | "annotation": [ 434 | { 435 | "displayName": "Disk speed", 436 | "locale": "en-us" 437 | } 438 | ] 439 | }, 440 | { 441 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Read Bytes/sec", 442 | "sampleRate": "PT15S", 443 | "unit": "BytesPerSecond", 444 | "annotation": [ 445 | { 446 | "displayName": "Disk read speed", 447 | "locale": "en-us" 448 | } 449 | ] 450 | }, 451 | { 452 | "counterSpecifier": "\\PhysicalDisk(_Total)\\Disk Write Bytes/sec", 453 | "sampleRate": "PT15S", 454 | "unit": "BytesPerSecond", 455 | "annotation": [ 456 | { 457 | "displayName": "Disk write speed", 458 | "locale": "en-us" 459 | } 460 | ] 461 | }, 462 | { 463 | "counterSpecifier": "\\LogicalDisk(_Total)\\% Free Space", 464 | "sampleRate": "PT15S", 465 | "unit": "Percent", 466 | "annotation": [ 467 | { 468 | "displayName": "Disk free space (percentage)", 469 | "locale": "en-us" 470 | } 471 | ] 472 | } 473 | ] 474 | }, 475 | "Metrics": { 476 | "resourceId": "[variables('wadmetricsresourceid')]", 477 | "MetricAggregation": [ 478 | { 479 | "scheduledTransferPeriod": "PT1H" 480 | }, 481 | { 482 | "scheduledTransferPeriod": "PT1M" 483 | } 484 | ] 485 | } 486 | } 487 | } 488 | }, 489 | "protectedSettings": { 490 | "storageAccountName": "[variables('diagnosticsStorageAccountName')]", 491 | "storageAccountKey": "[listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('diagnosticsStorageAccountName')), '2016-01-01').keys[0].value]" 492 | } 493 | } 494 | }, 495 | { 496 | "name": "firstCustomScriptExtension", 497 | "type": "extensions", 498 | "location": "[resourceGroup().location]", 499 | "apiVersion": "2016-03-30", 500 | "dependsOn": [ 501 | "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]" 502 | ], 503 | "tags": { 504 | "displayName": "firstCustomScriptExtension" 505 | }, 506 | "properties": { 507 | "publisher": "Microsoft.Compute", 508 | "type": "CustomScriptExtension", 509 | "typeHandlerVersion": "1.4", 510 | "autoUpgradeMinorVersion": true, 511 | "settings": { 512 | "fileUris": [ 513 | "[concat(parameters('storageAccountName'), '/', variables('firstCustomScriptExtensionScriptStorageContainer'), '/', variables('firstCustomScriptExtensionScriptFileName'))]" 514 | ], 515 | "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstCustomScriptExtensionScriptFileName'), ' -featureName web-server -serviceName w3svc')]" 516 | } 517 | } 518 | } 519 | 520 | ] 521 | } 522 | ] 523 | } 524 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing1.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test", 3 | "type": "extensions", 4 | "location": "[resourceGroup().location]", 5 | "apiVersion": "2016-03-30", 6 | "dependsOn": [ 7 | "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]" 8 | ], 9 | "tags": { 10 | "displayName": "test" 11 | }, 12 | "properties": { 13 | "publisher": "Microsoft.Compute", 14 | "type": "CustomScriptExtension", 15 | "typeHandlerVersion": "1.4", 16 | "autoUpgradeMinorVersion": true, 17 | "settings": { 18 | "fileUris": [ 19 | "[concat(parameters('_artifactsLocation'), '/', variables('testScriptFolder'), '/', variables('testScriptFileName'), parameters('_artifactsLocationSasToken'))]" 20 | ], 21 | "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('testScriptFolder'), '/', variables('testScriptFileName'))]" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing10.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | var="FOOsball" 4 | echo $var 5 | echo "Ritesh Modi" 6 | echo $1 7 | echo $2 8 | date +"%T" 9 | echo $RANDOM 10 | $RANDOM 11 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing11.txt: -------------------------------------------------------------------------------- 1 | { 2 | "apiVersion": "2015-06-15", 3 | "type": "Microsoft.Compute/virtualMachines/extensions", 4 | "name": "[concat(variables('vmName'), '/', 'linuxscripts')]", 5 | "location": "[resourceGroup().location]", 6 | "dependsOn": [ 7 | "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]" 8 | ], 9 | "tags": { 10 | "displayName": "config-app" 11 | }, 12 | "properties": { 13 | "publisher": "Microsoft.OSTCExtensions", 14 | "type": "CustomScriptForLinux", 15 | "typeHandlerVersion": "1.2", 16 | "autoUpgradeMinorVersion": true, 17 | "settings": { 18 | "fileUris": [ 19 | "https://allarmfiles.blob.core.windows.net/armfiles/first.sh" 20 | ], 21 | "commandToExecute": "[concat('sh first.sh ','argument1 ','argument2 ', 'argument 3 ')]" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing12.txt: -------------------------------------------------------------------------------- 1 | { 2 | "type": "extensions", 3 | "apiVersion": "2015-06-15", 4 | "name": "Microsoft.Powershell.DSC", 5 | "location": "[resourceGroup().location]", 6 | "dependsOn": [ 7 | "[resourceId('Microsoft.Compute/virtualMachines',variables('vmName'))]" 8 | ], 9 | "properties": { 10 | "publisher": "Microsoft.Powershell", 11 | "type": "DSC", 12 | "typeHandlerVersion": "2.9", 13 | "autoUpgradeMinorVersion": true, 14 | "settings": { 15 | "Configuration": { 16 | "url": "https://allarmfiles.blob.core.windows.net/dscfiles/psdsc.ps1.zip", 17 | "script": "psdsc.ps1", 18 | "function": "Main" 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing13.txt: -------------------------------------------------------------------------------- 1 | Configuration Main 2 | { 3 | Import-DscResource -ModuleName PSDesiredStateConfiguration 4 | 5 | node localhost 6 | { 7 | WindowsFeature iis 8 | { 9 | Name = "Web-Server" 10 | Ensure = "present" 11 | 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing14.txt: -------------------------------------------------------------------------------- 1 | Publish-AzureRmVMDscConfiguration -ResourceGroupName armfiles -ConfigurationPath "C:\Users\rites\psdsc.ps1" ` 2 | -ContainerName templates -StorageAccountName armtfiles -Force -Verbose 3 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing15.txt: -------------------------------------------------------------------------------- 1 | "storageAccountName": { 2 | "type": "string" 3 | }, 4 | "containerName": { 5 | "type": "string" 6 | }, 7 | "zipfileName": { 8 | "type": "string" 9 | }, 10 | "fileName": { 11 | "type": "string" 12 | } 13 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing16.txt: -------------------------------------------------------------------------------- 1 | { 2 | "type": "extensions", 3 | "apiVersion": "2015-06-15", 4 | "name": "Microsoft.Powershell.DSC", 5 | "location": "[resourceGroup().location]", 6 | "dependsOn": [ 7 | "[resourceId('Microsoft.Compute/virtualMachines',variables('vmName'))]" 8 | ], 9 | "properties": { 10 | "publisher": "Microsoft.Powershell", 11 | "type": "DSC", 12 | "typeHandlerVersion": "2.9", 13 | "autoUpgradeMinorVersion": true, 14 | "settings": { 15 | "Configuration": { 16 | "url": "[concat(parameters('storageAccountName'),'/',parameters('containerName'),'/',parameters('zipfileName'))]", 17 | "script": "[parameters('fileName')]", 18 | "function": "Main" 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing17.txt: -------------------------------------------------------------------------------- 1 | New-AzureRmResourceGroupDeployment -Name "csa01" -ResourceGroupName test01 -Mode Incremental -TemplateFile "c:\users\rites\source\repos\AzureResourceGroup19\Dsc-Basic.json" -adminUsername "superadmin" -adminPassword $(ConvertTo-SecureString -String Pa55w0rdPa55w0rd -AsPlainText -Force) -dnsNameForPublicIP armtemplateunique -storageAccountName "https://armtfiles.blob.core.windows.net" -containerName templates -zipfileName psdsc.ps1.zip -fileName psdsc.ps1 -Verbose -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing18.txt: -------------------------------------------------------------------------------- 1 | Configuration Main 2 | { 3 | 4 | [CmdletBinding()] 5 | Param ( 6 | [string]$serviceName 7 | ) 8 | 9 | Import-DscResource -ModuleName PSDesiredStateConfiguration 10 | 11 | node $AllNodes.Where{$_.Role -eq "WebServer"}.Nodename 12 | { 13 | 14 | WindowsFeature iis 15 | { 16 | Name = $serviceName 17 | Ensure = $AllNodes.Where{$_.Role -eq "WebServer"}.IsPresent 18 | 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing19.txt: -------------------------------------------------------------------------------- 1 | # Configuration Data for AD 2 | @{ 3 | AllNodes = @( 4 | @{ 5 | NodeName="*" 6 | RetryCount = 20 7 | RetryIntervalSec = 30 8 | PSDscAllowPlainTextPassword=$true 9 | PSDscAllowDomainUser = $true 10 | }, 11 | @{ 12 | Nodename = "localhost" 13 | Role = "WebServer" 14 | IsPresent = "present" 15 | } 16 | ) 17 | } 18 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing2.txt: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param 3 | ( 4 | [Parameter(Mandatory = $true)] 5 | [string] 6 | $featureName, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [string] 10 | $serviceName 11 | ) 12 | 13 | Install-WindowsFeature -name $featureName -IncludeManagementTools -Verbose 14 | 15 | $service = Get-Service -Name $serviceName -ErrorAction Stop 16 | 17 | if ($service.StartType -ne 'Automatic') 18 | { 19 | Write-Verbose -Message "Setting startup type for $serviceName to automatic" 20 | Set-Service -Name $serviceName -StartupType Automatic 21 | } 22 | 23 | if ($service.Status -ne 'Running') 24 | { 25 | Write-Verbose -Message "Starting service $serviceName" 26 | Start-Service -Name $serviceName 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing20.txt: -------------------------------------------------------------------------------- 1 | Publish-AzureRmVMDscConfiguration -ResourceGroupName armfiles -ConfigurationPath "C:\Users\rites\psdsc-configdata.ps1" -ContainerName templates -StorageAccountName armtfiles -ConfigurationDataPath "C:\Users\rites\configdata.psd1" -Force -Verbose -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing21.txt: -------------------------------------------------------------------------------- 1 | { 2 | "type": "extensions", 3 | "apiVersion": "2015-06-15", 4 | "name": "Microsoft.Powershell.DSC", 5 | "location": "[resourceGroup().location]", 6 | "dependsOn": [ 7 | "[resourceId('Microsoft.Compute/virtualMachines',variables('vmName'))]" 8 | ], 9 | "properties": { 10 | "publisher": "Microsoft.Powershell", 11 | "type": "DSC", 12 | "typeHandlerVersion": "2.9", 13 | "autoUpgradeMinorVersion": true, 14 | "settings": { 15 | "Configuration": { 16 | "url": "https://armtfiles.blob.core.windows.net/templates/psdsc-configdata.ps1.zip", 17 | "script": "psdsc-configdata.ps1", 18 | "function": "Main" 19 | }, 20 | "configurationArguments": { 21 | "serviceName": "XPS-Viewer" 22 | 23 | }, 24 | "configurationData": { 25 | "url": "https://armtfiles.blob.core.windows.net/templates/configdata.psd1" 26 | } 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing3.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firstCustomScriptExtension", 3 | "type": "extensions", 4 | "location": "[resourceGroup().location]", 5 | "apiVersion": "2016-03-30", 6 | "dependsOn": [ 7 | "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]" 8 | ], 9 | "tags": { 10 | "displayName": "firstCustomScriptExtension" 11 | }, 12 | "properties": { 13 | "publisher": "Microsoft.Compute", 14 | "type": "CustomScriptExtension", 15 | "typeHandlerVersion": "1.4", 16 | "autoUpgradeMinorVersion": true, 17 | "settings": { 18 | "fileUris": [ 19 | "[concat(parameters('storageAccountName'), '/', variables('firstCustomScriptExtensionScriptStorageContainer'), '/', variables('firstCustomScriptExtensionScriptFileName'))]" 20 | ], 21 | "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstCustomScriptExtensionScriptFileName'), ' -featureName web-server -serviceName w3svc')]" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing4.txt: -------------------------------------------------------------------------------- 1 | New-AzureRmResourceGroupDeployment -Name "csa01" -ResourceGroupName test01 -Mode Incremental -TemplateFile "c:\users\rites\source\repos\AzureResourceGroup19\WindowsVirtualMachine.json" -adminUsername "superadmin" -adminPassword $(ConvertTo-SecureString -String Pa55w0rdPa55w0rd -AsPlainText -Force) -dnsNameForPublicIP armtemplateunique -storageAccountName https://armtfiles.blob.core.windows.net -Verbose -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing5.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firstCustomScriptExtension", 3 | "type": "extensions", 4 | "location": "[resourceGroup().location]", 5 | "apiVersion": "2016-03-30", 6 | "dependsOn": [ 7 | "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]" 8 | ], 9 | "tags": { 10 | "displayName": "firstCustomScriptExtension" 11 | }, 12 | "properties": { 13 | "publisher": "Microsoft.Compute", 14 | "type": "CustomScriptExtension", 15 | "typeHandlerVersion": "1.4", 16 | "autoUpgradeMinorVersion": true, 17 | "settings": { 18 | "fileUris": [ 19 | "[concat(parameters('storageAccountName'), '/', variables('firstCustomScriptExtensionScriptStorageContainer'), '/', variables('firstCustomScriptExtensionScriptFileName'), parameters('_artifactsLocationSasToken'))]" 20 | ], 21 | "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstCustomScriptExtensionScriptFileName'), ' -featureName web-server -serviceName w3svc')]" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Azure-Resource-Manager-Templates-Quick-Start-Guide/16916bfcf527d5a1c5f486388a2c7965a0d340b2/Chapter05/chapter-5 - listing6.txt -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing7.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firstCustomScriptExtension", 3 | "type": "extensions", 4 | "location": "[resourceGroup().location]", 5 | "apiVersion": "2016-03-30", 6 | "dependsOn": [ 7 | "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]" 8 | ], 9 | "tags": { 10 | "displayName": "firstCustomScriptExtension" 11 | }, 12 | "properties": { 13 | "publisher": "Microsoft.Compute", 14 | "type": "CustomScriptExtension", 15 | "typeHandlerVersion": "1.4", 16 | "autoUpgradeMinorVersion": true, 17 | "settings": { 18 | "fileUris": [ 19 | "[concat(parameters('storageAccountName'), '/', variables('firstCustomScriptExtensionScriptStorageContainer'), '/', variables('firstCustomScriptExtensionScriptFileName'))]" 20 | ] 21 | }, 22 | "protectedSettings": { 23 | "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstCustomScriptExtensionScriptFileName'), ' -featureName web-server -serviceName w3svc')]", 24 | "storageAccountName": "armtfiles", 25 | "storageAccountKey": "your key" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing8.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "[concat(variables('vmName'),'/','firstCustomScriptExtension')]", 3 | "type": "Microsoft.Compute/virtualMachines/extensions", 4 | "location": "[resourceGroup().location]", 5 | "apiVersion": "2016-03-30", 6 | "dependsOn": [ 7 | "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]" 8 | ], 9 | "tags": { 10 | "displayName": "firstCustomScriptExtension" 11 | }, 12 | "properties": { 13 | "publisher": "Microsoft.Compute", 14 | "type": "CustomScriptExtension", 15 | "typeHandlerVersion": "1.4", 16 | "autoUpgradeMinorVersion": true, 17 | "settings": { 18 | "fileUris": [ 19 | "[concat(parameters('storageAccountName'), '/', variables('firstCustomScriptExtensionScriptStorageContainer'), '/', variables('firstCustomScriptExtensionScriptFileName'))]" 20 | ], 21 | "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstCustomScriptExtensionScriptFileName'), ' -featureName web-server -serviceName w3svc')]" 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter05/chapter-5 - listing9.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "[concat(variables('vmName'),'/','firstCustomScriptExtension')]", 3 | "type": "Microsoft.Compute/virtualMachines/extensions", 4 | "location": "[resourceGroup().location]", 5 | "apiVersion": "2016-03-30", 6 | "dependsOn": [ 7 | "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]" 8 | ], 9 | "tags": { 10 | "displayName": "firstCustomScriptExtension" 11 | }, 12 | "properties": { 13 | "publisher": "Microsoft.Compute", 14 | "type": "CustomScriptExtension", 15 | "typeHandlerVersion": "1.4", 16 | "autoUpgradeMinorVersion": true, 17 | "settings": { 18 | "fileUris": [ 19 | "[concat(parameters('storageAccountName'), '/', variables('firstCustomScriptExtensionScriptStorageContainer'), '/', variables('firstCustomScriptExtensionScriptFileName'))]" 20 | ], 21 | "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstCustomScriptExtensionScriptFileName'), ' -featureName web-server -serviceName w3svc')]" 22 | } 23 | 24 | } 25 | } 26 | ], 27 | "outputs": { 28 | "customScriptOutput": { 29 | "type": "string", 30 | "value": "[reference('firstCustomScriptExtension').instanceView.substatuses[0].message]" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter05/configdata.psd1: -------------------------------------------------------------------------------- 1 | # Configuration Data for AD 2 | @{ 3 | AllNodes = @( 4 | @{ 5 | NodeName="*" 6 | RetryCount = 20 7 | RetryIntervalSec = 30 8 | PSDscAllowPlainTextPassword=$true 9 | PSDscAllowDomainUser = $true 10 | }, 11 | @{ 12 | Nodename = "localhost" 13 | Role = "WebServer" 14 | IsPresent = "present" 15 | } 16 | ) 17 | } 18 | -------------------------------------------------------------------------------- /Chapter05/first.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | var="FOOsball" 3 | echo $var 4 | echo "Ritesh Modi" 5 | echo $1 6 | echo $2 7 | date +"%T" 8 | echo $RANDOM 9 | $RANDOM -------------------------------------------------------------------------------- /Chapter05/psdsc-configdata.ps1: -------------------------------------------------------------------------------- 1 | Configuration Main 2 | { 3 | 4 | [CmdletBinding()] 5 | Param ( 6 | [string]$serviceName 7 | ) 8 | 9 | Import-DscResource -ModuleName PSDesiredStateConfiguration 10 | 11 | node $AllNodes.Where{$_.Role -eq "WebServer"}.Nodename 12 | { 13 | 14 | WindowsFeature iis 15 | { 16 | Name = $serviceName 17 | Ensure = $AllNodes.Where{$_.Role -eq "WebServer"}.IsPresent 18 | 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter05/psdsc.ps1: -------------------------------------------------------------------------------- 1 | Configuration Main 2 | { 3 | Import-DscResource -ModuleName PSDesiredStateConfiguration 4 | 5 | node localhost 6 | { 7 | WindowsFeature iis 8 | { 9 | Name = "Web-Server" 10 | Ensure = "present" 11 | 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing1.txt: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "adminUsername": { 6 | "type": "string", 7 | "metadata": { 8 | "description": "Username for the Virtual Machine." 9 | } 10 | }, 11 | "adminPassword": { 12 | "type": "securestring", 13 | "metadata": { 14 | "description": "Password for the Virtual Machine." 15 | } 16 | }, 17 | "dnsLabelPrefix": { 18 | "type": "string", 19 | "metadata": { 20 | "description": "Unique DNS Name for the Public IP used to access the Virtual Machine." 21 | } 22 | }, 23 | "windowsOSVersion": { 24 | "type": "string", 25 | "defaultValue": "2016-Datacenter", 26 | "allowedValues": [ 27 | "2008-R2-SP1", 28 | "2012-Datacenter", 29 | "2012-R2-Datacenter", 30 | "2016-Nano-Server", 31 | "2016-Datacenter-with-Containers", 32 | "2016-Datacenter" 33 | ], 34 | "metadata": { 35 | "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version." 36 | } 37 | }, 38 | "location": { 39 | "type": "string", 40 | "defaultValue": "[resourceGroup().location]", 41 | "metadata": { 42 | "description": "Location for all resources." 43 | } 44 | } 45 | }, 46 | "variables": { 47 | "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'sawinvm')]", 48 | "imagePublisher": "MicrosoftWindowsServer", 49 | "imageOffer": "WindowsServer", 50 | "nicName": "myVMNic", 51 | "addressPrefix": "10.0.0.0/16", 52 | "subnetName": "Subnet", 53 | "subnetPrefix": "10.0.0.0/24", 54 | "publicIPAddressName": "myPublicIP", 55 | "OSDiskName": "osdiskforwindowssimple", 56 | "vhdStorageContainerName": "vhds", 57 | "vmName": "MyWindowsVM", 58 | "vmSize": "Standard_A2", 59 | "virtualNetworkName": "MyVNET", 60 | "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]" 61 | }, 62 | "resources": [ 63 | { 64 | "type": "Microsoft.Storage/storageAccounts", 65 | "name": "[variables('storageAccountName')]", 66 | "apiVersion": "2016-01-01", 67 | "location": "[parameters('location')]", 68 | "sku": { 69 | "name": "Standard_LRS" 70 | }, 71 | "kind": "Storage", 72 | "properties": {} 73 | }, 74 | { 75 | "apiVersion": "2016-03-30", 76 | "type": "Microsoft.Network/publicIPAddresses", 77 | "name": "[variables('publicIPAddressName')]", 78 | "location": "[parameters('location')]", 79 | "properties": { 80 | "publicIPAllocationMethod": "Dynamic", 81 | "dnsSettings": { 82 | "domainNameLabel": "[parameters('dnsLabelPrefix')]" 83 | } 84 | } 85 | }, 86 | { 87 | "apiVersion": "2016-03-30", 88 | "type": "Microsoft.Network/virtualNetworks", 89 | "name": "[variables('virtualNetworkName')]", 90 | "location": "[parameters('location')]", 91 | "properties": { 92 | "addressSpace": { 93 | "addressPrefixes": [ 94 | "[variables('addressPrefix')]" 95 | ] 96 | }, 97 | "subnets": [ 98 | { 99 | "name": "[variables('subnetName')]", 100 | "properties": { 101 | "addressPrefix": "[variables('subnetPrefix')]" 102 | } 103 | } 104 | ] 105 | } 106 | }, 107 | { 108 | "apiVersion": "2016-03-30", 109 | "type": "Microsoft.Network/networkInterfaces", 110 | "name": "[variables('nicName')]", 111 | "location": "[parameters('location')]", 112 | "dependsOn": [ 113 | "[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 114 | "[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 115 | ], 116 | "properties": { 117 | "ipConfigurations": [ 118 | { 119 | "name": "ipconfig1", 120 | "properties": { 121 | "privateIPAllocationMethod": "Dynamic", 122 | "publicIPAddress": { 123 | "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]" 124 | }, 125 | "subnet": { 126 | "id": "[variables('subnetRef')]" 127 | } 128 | } 129 | } 130 | ] 131 | } 132 | }, 133 | { 134 | "apiVersion": "2015-06-15", 135 | "type": "Microsoft.Compute/virtualMachines", 136 | "name": "[variables('vmName')]", 137 | "location": "[resourceGroup().location]", 138 | "tags": { 139 | "displayName": "VirtualMachine" 140 | }, 141 | "dependsOn": [ 142 | "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]", 143 | "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 144 | ], 145 | "properties": { 146 | "hardwareProfile": { 147 | "vmSize": "[variables('vmSize')]" 148 | }, 149 | "osProfile": { 150 | "computerName": "[variables('vmName')]", 151 | "adminUsername": "[parameters('adminUsername')]", 152 | "adminPassword": "[parameters('adminPassword')]" 153 | }, 154 | "storageProfile": { 155 | "imageReference": { 156 | "publisher": "[variables('imagePublisher')]", 157 | "offer": "[variables('imageOffer')]", 158 | "sku": "[parameters('windowsOSVersion')]", 159 | "version": "latest" 160 | }, 161 | "osDisk": { 162 | "name": "osdisk", 163 | "vhd": { 164 | "uri": "[concat('https://', variables('storageAccountName'), '.blob.core.windows.net/', variables('vhdStorageContainerName'), '/', variables('OSDiskName'), '.vhd')]" 165 | }, 166 | "caching": "ReadWrite", 167 | "createOption": "FromImage" 168 | } 169 | }, 170 | "networkProfile": { 171 | "networkInterfaces": [ 172 | { 173 | "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 174 | } 175 | ] 176 | } 177 | } 178 | } 179 | ], 180 | "outputs": { 181 | "storageAccount": { 182 | "type": "object", 183 | "value": "[reference(variables('storageAccountName'))]" 184 | }, 185 | "publicIPAddressName": { 186 | "type": "object", 187 | "value": "[reference(variables('publicIPAddressName'))]" 188 | }, 189 | "virtualNetworkName": { 190 | "type": "object", 191 | "value": "[reference(variables('virtualNetworkName'))]" 192 | }, 193 | "nicName": { 194 | "type": "object", 195 | "value": "[reference(variables('nicName'))]" 196 | }, 197 | "vmName": { 198 | "type": "object", 199 | "value": "[reference(variables('vmName'))]" 200 | } 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing10.txt: -------------------------------------------------------------------------------- 1 | Context "Virtual Machine from template deployment" { 2 | 3 | It "The virtual machine is provisioned successfully" { 4 | [string]$virtualMachine.provisioningState | Should Be "Succeeded" 5 | } 6 | It "The size of virtual machine is $($deployment.Parameters.virtualMachineSize.Value)" { 7 | [string]$virtualMachine.hardwareProfile.vmSize | Should Be "Standard_A2" 8 | } 9 | It "The virtual machine is attached to appropriate NIC" { 10 | [string]$virtualMachine.networkProfile.networkInterfaces[0].id | Should Be $(Get-AzureRmResource -ResourceId $([string]$virtualMachine.networkProfile.networkInterfaces[0].id)).Resourceid 11 | } 12 | 13 | It "The virtual machine is enabled for automatic update" { 14 | [bool]$virtualMachine.osProfile.windowsConfiguration.enableAutomaticUpdates | Should Be true 15 | } 16 | 17 | It "VM agent is provisioned within virtual machine" { 18 | [bool]$virtualMachine.osProfile.windowsConfiguration.provisionVMAgent | Should Be true 19 | } 20 | It "The SKU of virtual machine image is $($deployment.Parameters.imageReferenceSku.Value)" { 21 | [string]$virtualMachine.storageProfile.imageReference.sku | Should Be "2016-Datacenter" 22 | } 23 | 24 | It "The offer of virtual machine image is $($deployment.Parameters.imageReferenceOffer.Value)" { 25 | [string]$virtualMachine.storageProfile.imageReference.offer | Should Be "WindowsServer" 26 | } 27 | 28 | It "The publisher of virtual machine image is $($deployment.Parameters.imageReferencePublisher.Value)" { 29 | [string]$virtualMachine.storageProfile.imageReference.publisher | Should Be "MicrosoftWindowsServer" 30 | } 31 | It "The virtual machine is based on Windows operating system" { 32 | [string]$virtualMachine.storageProfile.osDisk.osType | Should Be "Windows" 33 | } 34 | It "The virtual machine is creating using an Image" { 35 | [string]$virtualMachine.storageProfile.osDisk.createOption | Should Be "FromImage" 36 | } 37 | It "The size of virtual machine os disk is 127 GB" { 38 | [int]$virtualMachine.storageProfile.osDisk.diskSizeGB | Should Be 127 39 | } 40 | It "The caching is ReadWrite for virtual machine os disk" { 41 | [string]$virtualMachine.storageProfile.osDisk.caching | Should Be "ReadWrite" 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing11.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | param( 5 | [string] $deploymentName = "csa01", 6 | [string] $resourceGroupName = "test01" 7 | 8 | ) 9 | 10 | 11 | Describe "Validation Tests" { 12 | BeforeAll { 13 | 14 | 15 | $deployment = (Get-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name $deploymentName) 16 | 17 | $storage = $deployment.Outputs.storageAccount.Value 18 | $publicIP = $deployment.Outputs.publicIPAddressName.Value 19 | $nic = $deployment.Outputs.nicName.Value 20 | $virtualNetwork = $deployment.Outputs.virtualNetworkName.Value 21 | $virtualMachine = $deployment.Outputs.vmName.Value 22 | } 23 | Context "Storage from template deployment" { 24 | 25 | It "The storage account has been provisioned successfully" { 26 | [string]$storage.provisioningState | Should Be "Succeeded" 27 | } 28 | It "The storage account is in available state" { 29 | [string]$storage.statusOfPrimary | Should Be "available" 30 | } 31 | 32 | 33 | 34 | It "The storage account location is West Europe" { 35 | [string]$storage.primaryLocation | Should Be "westeurope" 36 | } 37 | 38 | } 39 | Context "virtual network from template deployment" { 40 | 41 | It "The virtual network has been provisioned successfully" { 42 | [string]$virtualNetwork.provisioningState | Should Be "Succeeded" 43 | } 44 | It "The address range for virtual network is $($deployment.Parameters.addressPrefix.Value)" { 45 | [string]$virtualNetwork.addressSpace.addressPrefixes | Should Be "10.0.0.0/16" 46 | } 47 | It "The count of subnets in virtual network is 1" { 48 | [int]$virtualNetwork.subnets.Count | Should Be 1 49 | } 50 | 51 | It "The IP address range for subnet is $($deployment.Parameters.subnetPrefix.Value)" { 52 | [string]$virtualNetwork.subnets[0].properties.addressPrefix | Should Be "10.0.0.0/24" 53 | } 54 | 55 | It "The subnet has been provisioned successfully" { 56 | [string]$virtualNetwork.subnets[0].properties.provisioningState | Should Be "Succeeded" 57 | } 58 | 59 | } 60 | Context "Public IP address from template deployment" { 61 | 62 | It "The public IP address resource Have been deployed successfully" { 63 | [string]$publicIP.provisioningState | Should Be "Succeeded" 64 | } 65 | It "The Public IP address is allocation dynamic IP address" { 66 | [string]$publicIP.publicIPAllocationMethod | Should Be "Dynamic" 67 | } 68 | } 69 | 70 | Context "Network Interface from template deployment" { 71 | 72 | It "The NIC Have been provisioned successfully" { 73 | [string]$nic.provisioningState | Should Be "Succeeded" 74 | } 75 | It "Is primary NIC" { 76 | [string]$nic.primary | Should Be true 77 | } 78 | It "IP forwarding is disabled on NIC" { 79 | [int]$nic.enableIPForwarding | Should Be 0 80 | } 81 | 82 | It "TThe NIC IP configuration was provisioned successfully" { 83 | [string]$nic.ipConfigurations[0].properties.provisioningState | Should Be "Succeeded" 84 | } 85 | 86 | It "The NIC is the primary Nic" { 87 | [string]$nic.ipConfigurations[0].properties.primary | Should Be true 88 | } 89 | It "The IP allocation method used for NIC is dynamic" { 90 | [string]$nic.ipConfigurations[0].properties.privateIPAllocationMethod | Should Be "Dynamic" 91 | } 92 | 93 | It "The NIC is associated to appropriate subnet" { 94 | [string]$nic.ipConfigurations[0].properties.subnet.id | should be $([string]$virtualNetwork.subnets[0].id) 95 | } 96 | 97 | It "NIC is referencing the appropriate public IP resource" { 98 | [string]$nic.ipConfigurations[0].properties.publicIPAddress.id | should be $(Get-AzureRmResource -ResourceId $([string]$nic.ipConfigurations[0].properties.publicIPAddress.id)).Resourceid 99 | } 100 | 101 | 102 | } 103 | 104 | Context "Virtual Machine from template deployment" { 105 | 106 | It "The virtual machine is provisioned successfully" { 107 | [string]$virtualMachine.provisioningState | Should Be "Succeeded" 108 | } 109 | It "The size of virtual machine is $($deployment.Parameters.virtualMachineSize.Value)" { 110 | [string]$virtualMachine.hardwareProfile.vmSize | Should Be "Standard_A2" 111 | } 112 | It "The virtual machine is attached to appropriate NIC" { 113 | [string]$virtualMachine.networkProfile.networkInterfaces[0].id | Should Be $(Get-AzureRmResource -ResourceId $([string]$virtualMachine.networkProfile.networkInterfaces[0].id)).Resourceid 114 | } 115 | 116 | It "The virtual machine is enabled for automatic update" { 117 | [bool]$virtualMachine.osProfile.windowsConfiguration.enableAutomaticUpdates | Should Be true 118 | } 119 | 120 | It "VM agent is provisioned within virtual machine" { 121 | [bool]$virtualMachine.osProfile.windowsConfiguration.provisionVMAgent | Should Be true 122 | } 123 | It "The SKU of virtual machine image is $($deployment.Parameters.imageReferenceSku.Value)" { 124 | [string]$virtualMachine.storageProfile.imageReference.sku | Should Be "2016-Datacenter" 125 | } 126 | 127 | It "The offer of virtual machine image is $($deployment.Parameters.imageReferenceOffer.Value)" { 128 | [string]$virtualMachine.storageProfile.imageReference.offer | Should Be "WindowsServer" 129 | } 130 | 131 | It "The publisher of virtual machine image is $($deployment.Parameters.imageReferencePublisher.Value)" { 132 | [string]$virtualMachine.storageProfile.imageReference.publisher | Should Be "MicrosoftWindowsServer" 133 | } 134 | It "The virtual machine is based on Windows operating system" { 135 | [string]$virtualMachine.storageProfile.osDisk.osType | Should Be "Windows" 136 | } 137 | It "The virtual machine is creating using an Image" { 138 | [string]$virtualMachine.storageProfile.osDisk.createOption | Should Be "FromImage" 139 | } 140 | It "The size of virtual machine os disk is 127 GB" { 141 | [int]$virtualMachine.storageProfile.osDisk.diskSizeGB | Should Be 127 142 | } 143 | It "The caching is ReadWrite for virtual machine os disk" { 144 | [string]$virtualMachine.storageProfile.osDisk.caching | Should Be "ReadWrite" 145 | } 146 | } 147 | 148 | 149 | } 150 | -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing2.txt: -------------------------------------------------------------------------------- 1 | New-AzureRmResourceGroupDeployment -Name "csa01" -ResourceGroupName test01 -Mode Incremental -TemplateFile "C:\Users\rites\Desktop\Chapter7\templateforUnitTests.json" -adminUsername "superadmin" -adminPassword $(ConvertTo-SecureString -String Pa55w0rdPa55w0rd -AsPlainText -Force) -dnsLabelPrefix armtemplateunique -Verbose -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing3.txt: -------------------------------------------------------------------------------- 1 | Get-AzureRmResourceGroupDeployment -ResourceGroupName test01 -Name csa01 -Verbose -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing4.txt: -------------------------------------------------------------------------------- 1 | function AddTwoNumbers([int] $a, [int] $b) { 2 | 3 | return $a + $b 4 | 5 | } 6 | 7 | $firstValue, $secondValue 8 | Describe "Addition Validation Tests" { 9 | BeforeAll { 10 | $firstValue = 10 11 | $secondValue = 20; 12 | } 13 | 14 | Context "using Global variables" { 15 | 16 | It "Adding two positive numbers" { 17 | AddTwoNumbers -a $firstValue -b $secondValue | Should Be 30 18 | } 19 | } 20 | 21 | Context "Using Local Variables" { 22 | 23 | It "Adding two positive numbers" { 24 | $firstValue = 100 25 | $secondValue = 200 26 | AddTwoNumbers -a $firstValue -b $secondValue | Should Be 300 27 | } 28 | 29 | It "Adding two negative numbers" { 30 | $firstValue = -100 31 | $secondValue = -200 32 | AddTwoNumbers -a $firstValue -b $secondValue | Should Be -300 33 | } 34 | } 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing5.txt: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | 3 | 4 | $deployment = (Get-AzureRmResourceGroupDeployment -ResourceGroupName $deploymentName -Name $deploymentName) 5 | 6 | $storage = $deployment.Outputs.storageaccount.Value 7 | $publicIP = $deployment.Outputs.publicIPAddressName.Value 8 | $nic = $deployment.Outputs.nicName.Value 9 | $virtualNetwork = $deployment.Outputs.virtualNetworkName.Value 10 | $virtualMachine = $deployment.Outputs.vmName.Value 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing6.txt: -------------------------------------------------------------------------------- 1 | Context "Storage from template deployment" { 2 | 3 | It "The storage account has been provisioned successfully" { 4 | [string]$storage.provisioningState | Should Be "Succeeded" 5 | } 6 | It "The storage account is in available state" { 7 | [string]$storage.statusOfPrimary | Should Be "available" 8 | } 9 | 10 | 11 | 12 | It "The storage account location is West Europe" { 13 | [string]$storage.primaryLocation | Should Be "westeurope" 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing7.txt: -------------------------------------------------------------------------------- 1 | Context "Public IP address from template deployment" { 2 | 3 | It "The public IP address resource Have been deployed successfully" { 4 | [string]$publicIP.provisioningState | Should Be "Succeeded" 5 | } 6 | It "The Public IP address is allocation dynamic IP address" { 7 | [string]$publicIP.publicIPAllocationMethod | Should Be "Dynamic" 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing8.txt: -------------------------------------------------------------------------------- 1 | Context "virtual network from template deployment" { 2 | 3 | It "The virtual network has been provisioned successfully" { 4 | [string]$virtualNetwork.provisioningState | Should Be "Succeeded" 5 | } 6 | It "The address range for virtual network is "10.0.0.0/16" { 7 | [string]$virtualNetwork.addressSpace.addressPrefixes | Should Be "10.0.0.0/16" 8 | } 9 | It "The count of subnets in virtual network is 1" { 10 | [int]$virtualNetwork.subnets.Count | Should Be 1 11 | } 12 | 13 | It "The IP address range for subnet is "10.0.0.0/24"{ 14 | [string]$virtualNetwork.subnets[0].properties.addressPrefix | Should Be "10.0.0.0/24" 15 | } 16 | 17 | It "The subnet has been provisioned successfully" { 18 | [string]$virtualNetwork.subnets[0].properties.provisioningState | Should Be "Succeeded" 19 | } 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Chapter06/chapter-6 - listing9.txt: -------------------------------------------------------------------------------- 1 | Context "Network Interface from template deployment" { 2 | 3 | It "The NIC Have been provisioned successfully" { 4 | [string]$nic.provisioningState | Should Be "Succeeded" 5 | } 6 | It "Is primary NIC" { 7 | [string]$nic.primary | Should Be true 8 | } 9 | It "IP forwarding is disabled on NIC" { 10 | [int]$nic.enableIPForwarding | Should Be 0 11 | } 12 | 13 | It "The NIC IP configuration was provisioned successfully" { 14 | [string]$nic.ipConfigurations[0].properties.provisioningState | Should Be "Succeeded" 15 | } 16 | 17 | It "The NIC is the primary Nic" { 18 | [string]$nic.ipConfigurations[0].properties.primary | Should Be true 19 | } 20 | It "The IP allocation method used for NIC is dynamic" { 21 | [string]$nic.ipConfigurations[0].properties.privateIPAllocationMethod | Should Be "Dynamic" 22 | } 23 | 24 | It "The NIC is associated to appropriate subnet" { 25 | [string]$nic.ipConfigurations[0].properties.subnet.id | should be $([string]$virtualNetwork.subnets[0].id) 26 | } 27 | 28 | It "NIC is referencing the appropriate public IP resource" { 29 | [string]$nic.ipConfigurations[0].properties.publicIPAddress.id | should be $(Get-AzureRmResource -ResourceId $([string]$nic.ipConfigurations[0].properties.publicIPAddress.id)).Resourceid 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Chapter07/RedefiningProperties.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "vnetAddressPrefix": { 6 | "type": "string", 7 | "metadata": { 8 | "description": "Address Prefix of the virtual network" 9 | } 10 | }, 11 | "subnetPrefix": { 12 | "type": "string", 13 | "metadata": { 14 | "description": "address prefix of the subnet" 15 | } 16 | } 17 | }, 18 | "variables": { 19 | "virtualNetworkName": "sampleVirtualNetwork", 20 | "subnetName": "FirstSubnet", 21 | "nicName": "nic1", 22 | "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]" 23 | }, 24 | "resources": [ 25 | { 26 | "apiVersion": "2018-08-01", 27 | "type": "Microsoft.Network/virtualNetworks", 28 | "name": "[variables('virtualNetworkName')]", 29 | "location": "[resourceGroup().location]", 30 | "properties": { 31 | "addressSpace": { 32 | "addressPrefixes": [ 33 | "[parameters('vnetAddressPrefix')]" 34 | ] 35 | }, 36 | "subnets": [ 37 | { 38 | "name": "[variables('subnetName')]", 39 | "properties": { 40 | "addressPrefix": "[parameters('subnetPrefix')]" 41 | } 42 | } 43 | ] 44 | } 45 | }, 46 | { 47 | "apiVersion": "2018-08-01", 48 | "type": "Microsoft.Network/networkInterfaces", 49 | "name": "[variables('nicName')]", 50 | "location": "[resourceGroup().location]", 51 | "dependsOn": [ 52 | "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 53 | ], 54 | "properties": { 55 | "ipConfigurations": [ 56 | { 57 | "name": "ipconfig1", 58 | "properties": { 59 | "privateIPAllocationMethod": "Dynamic", 60 | "subnet": { 61 | "id": "[variables('subnetRef')]" 62 | } 63 | } 64 | } 65 | ] 66 | } 67 | }, 68 | { 69 | "apiVersion": "2018-01-01", 70 | "name": "nestedTemplate", 71 | "type": "Microsoft.Resources/deployments", 72 | "dependsOn": [ 73 | "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 74 | ], 75 | "properties": { 76 | "mode": "Incremental", 77 | "template": { 78 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 79 | "contentVersion": "1.0.0.0", 80 | "resources": [ 81 | { 82 | "apiVersion": "2015-06-15", 83 | "type": "Microsoft.Network/networkInterfaces", 84 | "name": "[variables('nicName')]", 85 | "location": "[resourceGroup().location]", 86 | "properties": { 87 | "ipConfigurations": [ 88 | { 89 | "name": "ipconfig1", 90 | "properties": { 91 | "privateIPAllocationMethod": "static", 92 | "privateIPAddress": "[reference(variables('nicName')).ipConfigurations[0].properties.privateIPAddress]", 93 | "subnet": { 94 | "id": "[variables('subnetRef')]" 95 | } 96 | } 97 | } 98 | ] 99 | } 100 | } 101 | ] 102 | } 103 | } 104 | } 105 | 106 | ], 107 | "outputs": { 108 | 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Chapter07/SharedServicesSQL-1.0.0.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "administratorLogin": { 6 | "type": "string" 7 | }, 8 | "administratorLoginPassword": { 9 | "type": "securestring" 10 | }, 11 | "databaseName": { 12 | "type": "string" 13 | }, 14 | "sqlserverName": { 15 | "type": "string" 16 | }, 17 | "customTags": { "type": "object" }, 18 | "collation": { 19 | "type": "string", 20 | "defaultValue": "SQL_Latin1_General_CP1_CI_AS" 21 | }, 22 | "edition": { 23 | "type": "string", 24 | "defaultValue": "Basic", 25 | "allowedValues": [ 26 | "Basic", 27 | "Standard", 28 | "Premium" 29 | ] 30 | }, 31 | "maxSizeBytes": { 32 | "type": "string", 33 | "defaultValue": "1073741824" 34 | }, 35 | "requestedServiceObjectiveName": { 36 | "type": "string", 37 | "defaultValue": "Basic", 38 | "allowedValues": [ 39 | "Basic", 40 | "S0", 41 | "S1", 42 | "S2", 43 | "P1", 44 | "P2", 45 | "P3" 46 | ], 47 | "metadata": { 48 | "description": "Describes the performance level for Edition" 49 | } 50 | } 51 | }, 52 | "variables": { 53 | 54 | }, 55 | "resources": [ 56 | { 57 | "name": "[parameters('sqlserverName')]", 58 | "type": "Microsoft.Sql/servers", 59 | "location": "[resourceGroup().location]", 60 | "tags": { 61 | "displayName": "SqlServer" 62 | }, 63 | "apiVersion": "2014-04-01-preview", 64 | "properties": { 65 | "administratorLogin": "[parameters('administratorLogin')]", 66 | "administratorLoginPassword": "[parameters('administratorLoginPassword')]" 67 | }, 68 | "resources": [ 69 | { 70 | "name": "[parameters('databaseName')]", 71 | "type": "databases", 72 | "location": "[resourceGroup().location]", 73 | "tags": { 74 | "displayName": "Database" 75 | }, 76 | "apiVersion": "2014-04-01-preview", 77 | "dependsOn": [ 78 | "[resourceId('Microsoft.Sql/servers/', parameters('sqlserverName'))]" 79 | ], 80 | "properties": { 81 | "edition": "[parameters('edition')]", 82 | "collation": "[parameters('collation')]", 83 | "maxSizeBytes": "[parameters('maxSizeBytes')]", 84 | "requestedServiceObjectiveName": "[parameters('requestedServiceObjectiveName')]" 85 | } 86 | }, 87 | { 88 | "type": "firewallrules", 89 | "apiVersion": "2014-04-01-preview", 90 | "dependsOn": [ 91 | "[resourceId('Microsoft.Sql/servers/', parameters('sqlserverName'))]" 92 | ], 93 | "location": "[resourceGroup().location]", 94 | "name": "AllowAllWindowsAzureIps", 95 | "properties": { 96 | "endIpAddress": "0.0.0.0", 97 | "startIpAddress": "0.0.0.0" 98 | } 99 | } 100 | ] 101 | } 102 | 103 | ], 104 | "outputs": { 105 | "SQLServerFQDN": { 106 | "type": "string", 107 | "value": "[reference(parameters('sqlserverName')).fullyQualifiedDomainName]" 108 | } 109 | 110 | } 111 | } -------------------------------------------------------------------------------- /Chapter07/appserviceplan-1.0.0.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "customTags": { "type": "object" }, 6 | "appServicePlanName": { "type": "string" }, 7 | "appServicePlanSkuTier": { "type": "string" }, 8 | "appServicePlanSkuName": { "type": "string" } 9 | }, 10 | "variables": { 11 | }, 12 | "resources": [ 13 | { 14 | "type": "Microsoft.Web/serverfarms", 15 | "kind": "app", 16 | "name": "[parameters('appServicePlanName')]", 17 | "location": "[resourceGroup().location]", 18 | "apiVersion": "2016-09-01", 19 | "tags": "[parameters('customTags')]", 20 | "properties": { 21 | "name": "[parameters('appServicePlanName')]" 22 | }, 23 | "sku": { 24 | "Tier": "[parameters('appServicePlanSkuTier')]", 25 | "Name": "[parameters('appServicePlanSkuName')]" 26 | } 27 | } 28 | ], 29 | "outputs": { 30 | "appServicePlan": { 31 | "type": "object", 32 | "value": "[reference(parameters('appServicePlanName'))]" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Chapter07/azuredeploy.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "resourceGroupInfo": { 6 | "type": "array" 7 | }, 8 | "sqlServerProperties": { 9 | "type": "object" 10 | }, 11 | "environmentName": { 12 | "type": "string", 13 | "allowedValues": [ "DEV", "TST", "PRD", "SIT", "PAT", "STG", "UAT" ] 14 | }, 15 | "department": { 16 | "type": "string" 17 | }, 18 | "templateRepository": { 19 | "type": "object" 20 | }, 21 | "storagekey": { 22 | "type": "securestring" 23 | }, 24 | "appServicePlanSkuTier": { 25 | "type": "string" 26 | }, 27 | "appServicePlanSkuName": { 28 | "type": "string" 29 | }, 30 | "diagnosticlevel": { 31 | "type": "string" 32 | } 33 | }, 34 | "variables": { 35 | "variableTags": "[json(concat('{\"application\": \"All\", \"environment\": \"',parameters('environmentName'),'\", \"supportTeam\": \"',parameters('department'),'\"}'))]", 36 | "templateRefBaseUri": "[concat('https://', parameters('templateRepository').libraryTemplateStorageAccountName,'.blob.core.windows.net/', parameters('templateRepository').libraryTemplateStorageContainerName, '/')]", 37 | "templateRefAppPlanTemplateUri": "[concat(variables('templateRefBaseUri'), 'appserviceplan-1.0.0.0.json',parameters('storagekey'))]", 38 | "templateRefWebAppTemplateUri": "[concat(variables('templateRefBaseUri'), 'webappsimple-1.0.0.0.json',parameters('storagekey'))]", 39 | "templateRefSharedServicesTemplateUri": "[concat(variables('templateRefBaseUri'), 'SharedServicesSQL-1.0.0.0.json',parameters('storagekey'))]", 40 | "multiLocation": { 41 | "copy": [ 42 | { 43 | "name": "location", 44 | "count": "[length(parameters('resourceGroupInfo'))]", 45 | "input": { 46 | "resourceGroupName": "[concat('RGP','-',parameters('environmentName'),'-', parameters('resourceGroupInfo')[copyIndex('location')].resourceGroupName )]", 47 | "appServicePlanName": "[toLower(concat('asp','-',parameters('resourceGroupInfo')[copyIndex('location')].resourceGroupSuffix,'-',parameters('appServicePlanSkuName'),'-', parameters('environmentName')))]", 48 | "webAppName": "[toLower(concat('web','-',parameters('resourceGroupInfo')[copyIndex('location')].resourceGroupSuffix,'-', parameters('appServicePlanSkuName'),'-', parameters('environmentName')))]" 49 | } 50 | } 51 | ] 52 | } 53 | }, 54 | "resources": [ 55 | { 56 | "type": "Microsoft.Resources/resourceGroups", 57 | "location": "[parameters('resourceGroupInfo')[copyIndex()].resourceGroupLocation]", 58 | "name": "[variables('multiLocation').location[copyIndex()].resourceGroupName]", 59 | "apiVersion": "2018-05-01", 60 | "tags": "[variables('variableTags')]", 61 | "copy": { 62 | "name": "allResourceGroups", 63 | "count": "[length(parameters('resourceGroupInfo'))]" 64 | }, 65 | "properties": {} 66 | }, 67 | { 68 | "type": "Microsoft.Resources/deployments", 69 | "apiVersion": "2017-05-10", 70 | "name": "sharedServices-sqlServices", 71 | "resourceGroup": "[variables('multiLocation').location[0].resourceGroupName]", 72 | "dependsOn": [ 73 | "allResourceGroups" 74 | ], 75 | "properties": { 76 | "mode": "Incremental", 77 | "templateLink": { 78 | "uri": "[variables('templateRefSharedServicesTemplateUri')]", 79 | "contentVersion": "1.0.0.0" 80 | }, 81 | "parameters": { 82 | "administratorLogin": { 83 | "value": "[parameters('sqlServerProperties').administratorLogin]" 84 | }, 85 | "administratorLoginPassword": { 86 | "reference": { 87 | "keyVault": { 88 | "id": "[concat(subscription().id,'/resourcegroups/', parameters('sqlServerProperties').keyVaultResourceGroupName, '/providers/Microsoft.KeyVault/vaults/', parameters('sqlServerProperties').keyVaultName)]" 89 | }, 90 | "secretName": "[parameters('sqlServerProperties').adminstratorPasswordSecretName]" 91 | } 92 | }, 93 | "databaseName": { 94 | "value": "[parameters('sqlServerProperties').databaseName]" 95 | }, 96 | "customTags": { 97 | "value": "[variables('variableTags')]" 98 | }, 99 | "collation": { 100 | "value": "[parameters('sqlServerProperties').collation]" 101 | }, 102 | "edition": { 103 | "value": "[parameters('sqlServerProperties').edition]" 104 | }, 105 | "maxSizeBytes": { 106 | "value": "[parameters('sqlServerProperties').maxSizeBytes]" 107 | }, 108 | "requestedServiceObjectiveName": { 109 | "value": "[parameters('sqlServerProperties').requestedServiceObjectiveName]" 110 | }, 111 | "sqlserverName": { 112 | "value": "[parameters('sqlServerProperties').sqlserverName]" 113 | } 114 | } 115 | } 116 | }, 117 | 118 | { 119 | "type": "Microsoft.Resources/deployments", 120 | "apiVersion": "2017-05-10", 121 | "name": "[concat('crossAppServePlan', copyIndex())]", 122 | "dependsOn": [ 123 | "sharedServices-sqlServices" 124 | ], 125 | "copy": { 126 | "name": "allAppServicePlans", 127 | "count": "[length(parameters('resourceGroupInfo'))]" 128 | }, 129 | "resourceGroup": "[variables('multiLocation').location[copyIndex()].resourceGroupName]", 130 | "properties": { 131 | "mode": "Incremental", 132 | "templateLink": { 133 | "uri": "[variables('templateRefAppPlanTemplateUri')]", 134 | "contentVersion": "1.0.0.0" 135 | }, 136 | "parameters": { 137 | "appServicePlanName": { 138 | "value": "[variables('multiLocation').location[copyIndex()].appServicePlanName]" 139 | }, 140 | "appServicePlanSkuTier": { 141 | "value": "[parameters('appServicePlanSkuTier')]" 142 | }, 143 | "appServicePlanSkuName": { 144 | "value": "[parameters('appServicePlanSkuName')]" 145 | }, 146 | "customTags": { 147 | "value": "[variables('variableTags')]" 148 | } 149 | } 150 | } 151 | }, 152 | { 153 | "type": "Microsoft.Resources/deployments", 154 | "apiVersion": "2017-05-10", 155 | "name": "[concat('crossWebApp', copyIndex())]", 156 | "dependsOn": [ 157 | "allAppServicePlans" 158 | ], 159 | "copy": { 160 | "name": "allWebApps", 161 | "count": "[length(parameters('resourceGroupInfo'))]" 162 | }, 163 | "resourceGroup": "[variables('multiLocation').location[copyIndex()].resourceGroupName]", 164 | "properties": { 165 | "mode": "Incremental", 166 | "templateLink": { 167 | "uri": "[variables('templateRefWebAppTemplateUri')]", 168 | "contentVersion": "1.0.0.0" 169 | }, 170 | "parameters": { 171 | "appServicePlanName": { 172 | "value": "[variables('multiLocation').location[copyIndex()].appServicePlanName]" 173 | }, 174 | "diagnosticlevel": { 175 | "value": "[parameters('diagnosticlevel')]" 176 | }, 177 | "webAppName": { 178 | "value": "[variables('multiLocation').location[copyIndex()].webAppName]" 179 | }, 180 | "serverName": { 181 | "value": "[concat(reference('sharedServices-sqlServices').outputs.SQLServerFQDN.value,', 1433;')]" 182 | }, 183 | "databaseName": { 184 | "value": "[concat( parameters('sqlServerProperties').databaseName,'; ')]" 185 | }, 186 | "userID": { 187 | "value": "[concat(parameters('sqlServerProperties').administratorLogin,'; ')]" 188 | }, 189 | "customTags": { 190 | "value": "[variables('variableTags')]" 191 | }, 192 | "administratorLoginPassword": { 193 | "reference": { 194 | "keyVault": { 195 | "id": "[concat('/subscriptions/9755ffce-e94b-4332-9be8-1ade15e78909','/resourcegroups/', parameters('sqlServerProperties').keyVaultResourceGroupName, '/providers/Microsoft.KeyVault/vaults/', parameters('sqlServerProperties').keyVaultName)]" 196 | }, 197 | "secretName": "[parameters('sqlServerProperties').adminstratorPasswordSecretName]" 198 | } 199 | } 200 | } 201 | } 202 | } 203 | 204 | ], 205 | "outputs": { 206 | 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /Chapter07/azuredeploy.parameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "resourceGroupInfo": { 6 | "value": [ 7 | { 8 | "resourceGroupName": "eCommerceUS", 9 | "resourceGroupLocation": "East US 2", 10 | "resourceGroupSuffix": "eastus" 11 | }, 12 | { 13 | "resourceGroupName": "eCommerceEurope", 14 | "resourceGroupLocation": "West Europe", 15 | "resourceGroupSuffix": "westEurope" 16 | 17 | } 18 | ] 19 | }, 20 | "sqlServerProperties": { 21 | "value": { 22 | "administratorLogin": "eCommerceAdmin", 23 | "databaseName": "eCommerceDatabase", 24 | "collation": "SQL_Latin1_General_CP1_CI_AS", 25 | "edition": "Standard", 26 | "maxSizeBytes": "1073741824", 27 | "requestedServiceObjectiveName": "S0", 28 | "sqlserverName": "armtemplatebooksqlserver", 29 | "keyVaultName": "keyvaultarmtemplatebook", 30 | "keyVaultResourceGroupName": "ARMPatterns", 31 | "adminstratorPasswordSecretName": "adminstratorPasswordSQL" 32 | } 33 | }, 34 | "templateRepository": { 35 | "value": { 36 | "libraryTemplateStorageAccountName": "hostforarmtemplates", 37 | "libraryTemplateStorageContainerName": "armtemplates" 38 | } 39 | }, 40 | "environmentName": { 41 | "value": "DEV" 42 | }, 43 | "department": { 44 | "value": "Finance" 45 | }, 46 | "storagekey": { 47 | "reference": { 48 | "keyVault": { "id": "/subscriptions/9755ffce-e94b-4332-9be8-1ade15e78909/resourceGroups/ARMPatterns/providers/Microsoft.KeyVault/vaults/keyvaultarmtemplatebook" }, 49 | "secretName": "storageAccountkey" 50 | } 51 | }, 52 | "appServicePlanSkuName": { 53 | "value": "S1" 54 | }, 55 | "appServicePlanSkuTier": { 56 | "value": "Standard" 57 | }, 58 | "diagnosticlevel": { 59 | "value": "warning" 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Chapter07/webappsimple-1.0.0.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "appServicePlanName": { "type": "string" }, 6 | "diagnosticlevel": { 7 | "type": "string", 8 | "allowedValues": [ "error", "warning", "information", "verbose" ], 9 | "defaultValue": "warning" 10 | }, 11 | "customTags": { "type": "object" }, 12 | "webAppName": { "type": "string" }, 13 | "serverName": { "type": "string" }, 14 | "databaseName": { "type": "string" }, 15 | "userID": { "type": "string" }, 16 | "administratorLoginPassword": { "type": "securestring" } 17 | }, 18 | "variables": { 19 | }, 20 | "resources": [ 21 | { 22 | "type": "Microsoft.Web/sites", 23 | "kind": "app", 24 | "name": "[parameters('webAppName')]", 25 | "location": "[resourceGroup().location]", 26 | "apiVersion": "2016-08-01", 27 | "tags": "[parameters('customTags')]", 28 | "properties": { 29 | "name": "[parameters('webAppName')]", 30 | "enabled": true, 31 | "reserved": true, 32 | "serverFarmId": "[resourceId('Microsoft.Web/serverFarms', parameters('appServicePlanName'))]", 33 | "siteConfig": { 34 | "AlwaysOn": true, 35 | "connectionStrings": [ 36 | { 37 | "name": "ConnString1", 38 | "connectionString": "[concat('Data Source=tcp:', parameters('serverName'), 'Initial Catalog=', parameters('databaseName'), 'User Id=', parameters('userID') , 'Password=', parameters('administratorLoginPassword') , ';')]" 39 | } 40 | ] 41 | }, 42 | "applicationLogs": { 43 | "fileSystem": { 44 | "level": "On" 45 | }, 46 | "azureTableStorage": { 47 | "level": "Off", 48 | "sasUrl": null 49 | } 50 | }, 51 | "httpLogs": { 52 | "fileSystem": { 53 | "retentionInMb": 35, 54 | "retentionInDays": 365, 55 | "enabled": false 56 | } 57 | }, 58 | "failedRequestsTracing": { 59 | "enabled": true 60 | }, 61 | "detailedErrorMessages": { 62 | "enabled": true 63 | } 64 | } 65 | } 66 | ], 67 | "outputs": { 68 | "webapp": { 69 | "type": "object", 70 | "value": "[reference(parameters('webAppName'))]" 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ## $5 Tech Unlocked 2021! 5 | [Buy and download this Book for only $5 on PacktPub.com](https://www.packtpub.com/product/azure-resource-manager-templates-quick-start-guide/9781789803235) 6 | ----- 7 | *If you have read this book, please leave a review on [Amazon.com](https://www.amazon.com/gp/product/1789803233). Potential readers can then use your unbiased opinion to help them make purchase decisions. Thank you. The $5 campaign runs from __December 15th 2020__ to __January 13th 2021.__* 8 | 9 | 10 | # Azure Resource Manager Templates Quick Start Guide 11 | 12 | Azure Resource Manager Templates Quick Start Guide 13 | 14 | This is the code repository for [Azure Resource Manager Templates Quick Start Guide](https://www.packtpub.com/virtualization-and-cloud/azure-resource-manager-templates-quick-start-guide?utm_source=github&utm_medium=repository&utm_campaign=9781789803235), published by Packt. 15 | 16 | **Create, deploy, and manage Azure resources with ARM templates using best practices** 17 | 18 | ## What is this book about? 19 | Azure Resource Manager (ARM) templates are declarations of Azure resources in the JSON format to provision and maintain them using infrastructure as code. This book gives practical solutions and examples for provisioning and managing various Azure services using ARM templates. 20 | 21 | This book covers the following exciting features: 22 | * Understand the foundations of ARM templates including nested and linked templates 23 | * Design, create, and unit test ARM templates using best practices 24 | * Learn about conditional deployments, looping, Custom Script Extensions using PowerShell, Bash, and DSC 25 | * Implement design patterns related to ARM templates 26 | * Run post-deployment PowerShell and Desired State Configuration scripts 27 | 28 | If you feel this book is for you, get your [copy](https://www.amazon.com/dp/1789803233) today! 29 | 30 | https://www.packtpub.com/ 32 | 33 | 34 | ## Instructions and Navigations 35 | All of the code is organized into folders. For example, Chapter02. 36 | 37 | The code will look like the following: 38 | ``` 39 | "parameters": { 40 | "storageAccountName": { 41 | "type" : "string" 42 | } 43 | } 44 | ``` 45 | 46 | **Following is what you need for this book:** 47 | This books is for developers, DevOps engineers, and architects who have experience in Azure.. 48 | 49 | With the following software and hardware list you can run all code files present in the book (Chapter 1-8). 50 | 51 | ### Software and Hardware List 52 | 53 | | Chapter | Software required | OS required | 54 | | -------- | ------------------------------------| -----------------------------------| 55 | | | Visual studio 2017 | Windows Server 2016 or | 56 | | 1-8 | Powershell 5.1 and above | Window 10 latest version - 64 bit | 57 | | | Azure powershell 6.6 and above | | 58 | | | Azure cli latest version | | 59 | | | Azure subscription | | 60 | | | | | 61 | 62 | 63 | 64 | We also provide a PDF file that has color images of the screenshots/diagrams used in this book. [Click here to download it](https://www.packtpub.com/sites/default/files/downloads/9781789803235_ColorImages.pdf). 65 | 66 | 67 | ### Related products 68 | * Hands-On Azure for Developers [[Packt]](https://www.packtpub.com/virtualization-and-cloud/hands-azure-developers?utm_source=github&utm_medium=repository&utm_campaign=9781789340624) [[Amazon]](https://www.amazon.com/dp/1789340624) 69 | 70 | * Implementing Azure Solutions - Second Edition [[Packt]](https://www.packtpub.com/virtualization-and-cloud/implementing-azure-solutions-second-edition?utm_source=github&utm_medium=repository&utm_campaign=9781789343045) [[Amazon]](https://www.amazon.com/dp/1789343046) 71 | 72 | ## Get to Know the Author 73 | **Ritesh Modi** is an ex-Microsoft Senior Technology Evangelist. He is a Microsoft Regional Director and the Regional Lead for Microsoft certified trainers. 74 | He is an architect, senior evangelist, cloud architect, published author, speaker, and a known leader for his contributions to blockchain, Ethereum, data centers, Azure, bots, cognitive services, DevOps, artificial intelligence, and automation. He is the author of eight books. 75 | He has spoken at more than 25 conferences, including TechEd and PowerShell Asia, and is a published author for MSDN magazine. He has more than a decade of experience of building and deploying enterprise solutions for customers. He has more than 25 technical certifications. 76 | 77 | 78 | 79 | ## Other books by the authors 80 | * [DevOps with Windows Server 2016](https://www.packtpub.com/networking-and-servers/devops-windows-server-2016?utm_source=github&utm_medium=repository&utm_campaign=9781786468550) 81 | * [Solidity Programming Essentials](https://www.packtpub.com/application-development/solidity-programming-essentials?utm_source=github&utm_medium=repository&utm_campaign=9781788831383) 82 | 83 | ### Suggestions and Feedback 84 | [Click here](https://docs.google.com/forms/d/e/1FAIpQLSdy7dATC6QmEL81FIUuymZ0Wy9vH1jHkvpY57OiMeKGqib_Ow/viewform) if you have any feedback or suggestions. 85 | ### Download a free PDF 86 | 87 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
88 |

https://packt.link/free-ebook/9781789803235

--------------------------------------------------------------------------------