github.com/yoctocloud/packer@v0.6.2-0.20160520224004-e11a0a18423f/builder/azure/arm/template.go (about) 1 // Copyright (c) Microsoft Corporation. All rights reserved. 2 // Licensed under the MIT License. See the LICENSE file in builder/azure for license information. 3 4 package arm 5 6 // See https://github.com/Azure/azure-quickstart-templates for a extensive list of templates. 7 8 const Linux = `{ 9 "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json", 10 "contentVersion": "1.0.0.0", 11 "parameters": { 12 "adminUsername": { 13 "type": "string" 14 }, 15 "adminPassword": { 16 "type": "string" 17 }, 18 "dnsNameForPublicIP": { 19 "type": "string" 20 }, 21 "imagePublisher": { 22 "type": "string" 23 }, 24 "imageOffer": { 25 "type": "string" 26 }, 27 "imageSku": { 28 "type": "string" 29 }, 30 "imageVersion": { 31 "type": "string" 32 }, 33 "osDiskName": { 34 "type": "string" 35 }, 36 "sshAuthorizedKey": { 37 "type": "string" 38 }, 39 "storageAccountBlobEndpoint": { 40 "type": "string" 41 }, 42 "vmSize": { 43 "type": "string" 44 }, 45 "vmName": { 46 "type": "string" 47 } 48 }, 49 "variables": { 50 "addressPrefix": "10.0.0.0/16", 51 "apiVersion": "2015-06-15", 52 "location": "[resourceGroup().location]", 53 "nicName": "packerNic", 54 "publicIPAddressName": "packerPublicIP", 55 "publicIPAddressType": "Dynamic", 56 "sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]", 57 "subnetName": "packerSubnet", 58 "subnetAddressPrefix": "10.0.0.0/24", 59 "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]", 60 "virtualNetworkName": "packerNetwork", 61 "vmStorageAccountContainerName": "images", 62 "vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]" 63 }, 64 "resources": [ 65 { 66 "apiVersion": "[variables('apiVersion')]", 67 "type": "Microsoft.Network/publicIPAddresses", 68 "name": "[variables('publicIPAddressName')]", 69 "location": "[variables('location')]", 70 "properties": { 71 "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 72 "dnsSettings": { 73 "domainNameLabel": "[parameters('dnsNameForPublicIP')]" 74 } 75 } 76 }, 77 { 78 "apiVersion": "[variables('apiVersion')]", 79 "type": "Microsoft.Network/virtualNetworks", 80 "name": "[variables('virtualNetworkName')]", 81 "location": "[variables('location')]", 82 "properties": { 83 "addressSpace": { 84 "addressPrefixes": [ 85 "[variables('addressPrefix')]" 86 ] 87 }, 88 "subnets": [ 89 { 90 "name": "[variables('subnetName')]", 91 "properties": { 92 "addressPrefix": "[variables('subnetAddressPrefix')]" 93 } 94 } 95 ] 96 } 97 }, 98 { 99 "apiVersion": "[variables('apiVersion')]", 100 "type": "Microsoft.Network/networkInterfaces", 101 "name": "[variables('nicName')]", 102 "location": "[variables('location')]", 103 "dependsOn": [ 104 "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 105 "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 106 ], 107 "properties": { 108 "ipConfigurations": [ 109 { 110 "name": "ipconfig", 111 "properties": { 112 "privateIPAllocationMethod": "Dynamic", 113 "publicIPAddress": { 114 "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 115 }, 116 "subnet": { 117 "id": "[variables('subnetRef')]" 118 } 119 } 120 } 121 ] 122 } 123 }, 124 { 125 "apiVersion": "[variables('apiVersion')]", 126 "type": "Microsoft.Compute/virtualMachines", 127 "name": "[parameters('vmName')]", 128 "location": "[variables('location')]", 129 "dependsOn": [ 130 "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 131 ], 132 "properties": { 133 "hardwareProfile": { 134 "vmSize": "[parameters('vmSize')]" 135 }, 136 "osProfile": { 137 "computerName": "[parameters('vmName')]", 138 "adminUsername": "[parameters('adminUsername')]", 139 "adminPassword": "[parameters('adminPassword')]", 140 "linuxConfiguration": { 141 "disablePasswordAuthentication": "false", 142 "ssh": { 143 "publicKeys": [ 144 { 145 "path": "[variables('sshKeyPath')]", 146 "keyData": "[parameters('sshAuthorizedKey')]" 147 } 148 ] 149 } 150 } 151 }, 152 "storageProfile": { 153 "imageReference": { 154 "publisher": "[parameters('imagePublisher')]", 155 "offer": "[parameters('imageOffer')]", 156 "sku": "[parameters('imageSku')]", 157 "version": "[parameters('imageVersion')]" 158 }, 159 "osDisk": { 160 "name": "osdisk", 161 "vhd": { 162 "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" 163 }, 164 "caching": "ReadWrite", 165 "createOption": "FromImage" 166 } 167 }, 168 "networkProfile": { 169 "networkInterfaces": [ 170 { 171 "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 172 } 173 ] 174 }, 175 "diagnosticsProfile": { 176 "bootDiagnostics": { 177 "enabled": "false" 178 } 179 } 180 } 181 } 182 ] 183 }` 184 185 // Template to deploy a KeyVault. 186 // 187 // NOTE: the parameters for the KeyVault template are identical to Windows 188 // template. Keeping these values in sync simplifies the code at the expense 189 // of template bloat. This bloat may be addressed in the future. 190 const KeyVault = `{ 191 "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json", 192 "contentVersion": "1.0.0.0", 193 "parameters": { 194 "adminUserName": { 195 "type": "string" 196 }, 197 "adminPassword": { 198 "type": "securestring" 199 }, 200 "dnsNameForPublicIP": { 201 "type": "string" 202 }, 203 "imageOffer": { 204 "type": "string" 205 }, 206 "imagePublisher": { 207 "type": "string" 208 }, 209 "imageSku": { 210 "type": "string" 211 }, 212 "imageVersion": { 213 "type": "string" 214 }, 215 "keyVaultName": { 216 "type": "string" 217 }, 218 "keyVaultSecretValue": { 219 "type": "securestring" 220 }, 221 "objectId": { 222 "type": "string" 223 }, 224 "osDiskName": { 225 "type": "string" 226 }, 227 "storageAccountBlobEndpoint": { 228 "type": "string" 229 }, 230 "tenantId": { 231 "type": "string" 232 }, 233 "vmName": { 234 "type": "string" 235 }, 236 "vmSize": { 237 "type": "string" 238 }, 239 "winRMCertificateUrl": { 240 "type": "string" 241 } 242 }, 243 "variables": { 244 "apiVersion": "2015-06-01", 245 "location": "[resourceGroup().location]", 246 "keyVaultSecretName": "packerKeyVaultSecret" 247 }, 248 "resources": [ 249 { 250 "apiVersion": "[variables('apiVersion')]", 251 "type": "Microsoft.KeyVault/vaults", 252 "name": "[parameters('keyVaultName')]", 253 "location": "[variables('location')]", 254 "properties": { 255 "enabledForDeployment": "true", 256 "enabledForTemplateDeployment": "true", 257 "tenantId": "[parameters('tenantId')]", 258 "accessPolicies": [ 259 { 260 "tenantId": "[parameters('tenantId')]", 261 "objectId": "[parameters('objectId')]", 262 "permissions": { 263 "keys": [ "all" ], 264 "secrets": [ "all" ] 265 } 266 } 267 ], 268 "sku": { 269 "name": "standard", 270 "family": "A" 271 } 272 }, 273 "resources": [ 274 { 275 "apiVersion": "[variables('apiVersion')]", 276 "type": "secrets", 277 "name": "[variables('keyVaultSecretName')]", 278 "dependsOn": [ 279 "[concat('Microsoft.KeyVault/vaults/', parameters('keyVaultName'))]" 280 ], 281 "properties": { 282 "value": "[parameters('keyVaultSecretValue')]" 283 } 284 } 285 ] 286 } 287 ] 288 }` 289 290 const Windows = `{ 291 "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json", 292 "contentVersion": "1.0.0.0", 293 "parameters": { 294 "adminUserName": { 295 "type": "string" 296 }, 297 "adminPassword": { 298 "type": "securestring" 299 }, 300 "dnsNameForPublicIP": { 301 "type": "string" 302 }, 303 "imageOffer": { 304 "type": "string" 305 }, 306 "imagePublisher": { 307 "type": "string" 308 }, 309 "imageSku": { 310 "type": "string" 311 }, 312 "imageVersion": { 313 "type": "string" 314 }, 315 "keyVaultName": { 316 "type": "string" 317 }, 318 "keyVaultSecretValue": { 319 "type": "securestring" 320 }, 321 "objectId": { 322 "type": "string" 323 }, 324 "osDiskName": { 325 "type": "string" 326 }, 327 "storageAccountBlobEndpoint": { 328 "type": "string" 329 }, 330 "tenantId": { 331 "type": "string" 332 }, 333 "vmName": { 334 "type": "string" 335 }, 336 "vmSize": { 337 "type": "string" 338 }, 339 "winRMCertificateUrl": { 340 "type": "string" 341 } 342 }, 343 "variables": { 344 "addressPrefix": "10.0.0.0/16", 345 "apiVersion": "2015-06-15", 346 "location": "[resourceGroup().location]", 347 "nicName": "packerNic", 348 "publicIPAddressName": "packerPublicIP", 349 "publicIPAddressType": "Dynamic", 350 "subnetName": "packerSubnet", 351 "subnetAddressPrefix": "10.0.0.0/24", 352 "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]", 353 "virtualNetworkName": "packerNetwork", 354 "vmStorageAccountContainerName": "images", 355 "vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]" 356 }, 357 "resources": [ 358 { 359 "apiVersion": "[variables('apiVersion')]", 360 "type": "Microsoft.Network/publicIPAddresses", 361 "name": "[variables('publicIPAddressName')]", 362 "location": "[variables('location')]", 363 "properties": { 364 "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 365 "dnsSettings": { 366 "domainNameLabel": "[parameters('dnsNameForPublicIP')]" 367 } 368 } 369 }, 370 { 371 "apiVersion": "[variables('apiVersion')]", 372 "type": "Microsoft.Network/virtualNetworks", 373 "name": "[variables('virtualNetworkName')]", 374 "location": "[variables('location')]", 375 "properties": { 376 "addressSpace": { 377 "addressPrefixes": [ 378 "[variables('addressPrefix')]" 379 ] 380 }, 381 "subnets": [ 382 { 383 "name": "[variables('subnetName')]", 384 "properties": { 385 "addressPrefix": "[variables('subnetAddressPrefix')]" 386 } 387 } 388 ] 389 } 390 }, 391 { 392 "apiVersion": "[variables('apiVersion')]", 393 "type": "Microsoft.Network/networkInterfaces", 394 "name": "[variables('nicName')]", 395 "location": "[variables('location')]", 396 "dependsOn": [ 397 "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 398 "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 399 ], 400 "properties": { 401 "ipConfigurations": [ 402 { 403 "name": "ipconfig", 404 "properties": { 405 "privateIPAllocationMethod": "Dynamic", 406 "publicIPAddress": { 407 "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 408 }, 409 "subnet": { 410 "id": "[variables('subnetRef')]" 411 } 412 } 413 } 414 ] 415 } 416 }, 417 { 418 "apiVersion": "[variables('apiVersion')]", 419 "type": "Microsoft.Compute/virtualMachines", 420 "name": "[parameters('vmName')]", 421 "location": "[variables('location')]", 422 "dependsOn": [ 423 "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 424 ], 425 "properties": { 426 "hardwareProfile": { 427 "vmSize": "[parameters('vmSize')]" 428 }, 429 "osProfile": { 430 "computerName": "[parameters('vmName')]", 431 "adminUsername": "[parameters('adminUsername')]", 432 "adminPassword": "[parameters('adminPassword')]", 433 "secrets": [ 434 { 435 "sourceVault": { 436 "id": "[resourceId(resourceGroup().name, 'Microsoft.KeyVault/vaults', parameters('keyVaultName'))]" 437 }, 438 "vaultCertificates": [ 439 { 440 "certificateUrl": "[parameters('winRMCertificateUrl')]", 441 "certificateStore": "My" 442 } 443 ] 444 } 445 ], 446 "windowsConfiguration": { 447 "provisionVMAgent": "true", 448 "winRM": { 449 "listeners": [{ 450 "protocol": "https", 451 "certificateUrl": "[parameters('winRMCertificateUrl')]" 452 } 453 ] 454 }, 455 "enableAutomaticUpdates": "true" 456 } 457 }, 458 "storageProfile": { 459 "imageReference": { 460 "publisher": "[parameters('imagePublisher')]", 461 "offer": "[parameters('imageOffer')]", 462 "sku": "[parameters('imageSku')]", 463 "version": "[parameters('imageVersion')]" 464 }, 465 "osDisk": { 466 "name": "osdisk", 467 "vhd": { 468 "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" 469 }, 470 "caching": "ReadWrite", 471 "createOption": "FromImage" 472 } 473 }, 474 "networkProfile": { 475 "networkInterfaces": [ 476 { 477 "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 478 } 479 ] 480 }, 481 "diagnosticsProfile": { 482 "bootDiagnostics": { 483 "enabled": "false" 484 } 485 } 486 } 487 } 488 ] 489 }`