2016-05-21 02:01:16 -04:00
|
|
|
package template
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2016-10-12 19:24:04 -04:00
|
|
|
"strings"
|
2016-05-21 02:01:16 -04:00
|
|
|
|
2018-04-06 04:12:58 -04:00
|
|
|
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
|
2016-05-21 02:01:16 -04:00
|
|
|
"github.com/Azure/go-autorest/autorest/to"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
jsonPrefix = ""
|
|
|
|
jsonIndent = " "
|
|
|
|
|
2016-06-30 19:51:52 -04:00
|
|
|
resourceKeyVaults = "Microsoft.KeyVault/vaults"
|
2017-05-29 00:06:09 -04:00
|
|
|
resourceManagedDisk = "Microsoft.Compute/images"
|
2016-06-30 19:51:52 -04:00
|
|
|
resourceNetworkInterfaces = "Microsoft.Network/networkInterfaces"
|
|
|
|
resourcePublicIPAddresses = "Microsoft.Network/publicIPAddresses"
|
|
|
|
resourceVirtualMachine = "Microsoft.Compute/virtualMachines"
|
|
|
|
resourceVirtualNetworks = "Microsoft.Network/virtualNetworks"
|
2016-05-21 02:01:16 -04:00
|
|
|
|
|
|
|
variableSshKeyPath = "sshKeyPath"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TemplateBuilder struct {
|
|
|
|
template *Template
|
2017-05-29 00:06:09 -04:00
|
|
|
osType compute.OperatingSystemTypes
|
2016-05-21 02:01:16 -04:00
|
|
|
}
|
|
|
|
|
2016-07-29 17:17:33 -04:00
|
|
|
func NewTemplateBuilder(template string) (*TemplateBuilder, error) {
|
2016-05-21 02:01:16 -04:00
|
|
|
var t Template
|
|
|
|
|
2016-07-29 17:17:33 -04:00
|
|
|
err := json.Unmarshal([]byte(template), &t)
|
2016-05-21 02:01:16 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &TemplateBuilder{
|
|
|
|
template: &t,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TemplateBuilder) BuildLinux(sshAuthorizedKey string) error {
|
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.OsProfile
|
|
|
|
profile.LinuxConfiguration = &compute.LinuxConfiguration{
|
|
|
|
SSH: &compute.SSHConfiguration{
|
|
|
|
PublicKeys: &[]compute.SSHPublicKey{
|
2016-07-16 01:23:53 -04:00
|
|
|
{
|
2016-05-21 02:01:16 -04:00
|
|
|
Path: to.StringPtr(s.toVariable(variableSshKeyPath)),
|
|
|
|
KeyData: to.StringPtr(sshAuthorizedKey),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-29 00:06:09 -04:00
|
|
|
s.osType = compute.Linux
|
2016-05-21 02:01:16 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TemplateBuilder) BuildWindows(keyVaultName, winRMCertificateUrl string) error {
|
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.OsProfile
|
|
|
|
|
|
|
|
profile.Secrets = &[]compute.VaultSecretGroup{
|
2016-07-16 01:23:53 -04:00
|
|
|
{
|
2016-05-21 02:01:16 -04:00
|
|
|
SourceVault: &compute.SubResource{
|
|
|
|
ID: to.StringPtr(s.toResourceID(resourceKeyVaults, keyVaultName)),
|
|
|
|
},
|
|
|
|
VaultCertificates: &[]compute.VaultCertificate{
|
2016-07-16 01:23:53 -04:00
|
|
|
{
|
2016-05-21 02:01:16 -04:00
|
|
|
CertificateStore: to.StringPtr("My"),
|
|
|
|
CertificateURL: to.StringPtr(winRMCertificateUrl),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.WindowsConfiguration = &compute.WindowsConfiguration{
|
|
|
|
ProvisionVMAgent: to.BoolPtr(true),
|
|
|
|
WinRM: &compute.WinRMConfiguration{
|
|
|
|
Listeners: &[]compute.WinRMListener{
|
2016-07-16 01:23:53 -04:00
|
|
|
{
|
2016-05-21 02:01:16 -04:00
|
|
|
Protocol: "https",
|
|
|
|
CertificateURL: to.StringPtr(winRMCertificateUrl),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-05-29 00:06:09 -04:00
|
|
|
|
|
|
|
s.osType = compute.Windows
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-08-13 04:45:04 -04:00
|
|
|
func (s *TemplateBuilder) SetManagedDiskUrl(managedImageId string, storageAccountType compute.StorageAccountTypes) error {
|
2017-05-29 00:06:09 -04:00
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.StorageProfile
|
|
|
|
profile.ImageReference = &compute.ImageReference{
|
2017-06-22 19:36:40 -04:00
|
|
|
ID: &managedImageId,
|
2017-05-29 00:06:09 -04:00
|
|
|
}
|
2017-06-22 19:36:40 -04:00
|
|
|
profile.OsDisk.OsType = s.osType
|
2018-04-06 04:12:58 -04:00
|
|
|
profile.OsDisk.CreateOption = compute.DiskCreateOptionTypesFromImage
|
2017-05-29 00:06:09 -04:00
|
|
|
profile.OsDisk.Vhd = nil
|
2017-08-13 04:45:04 -04:00
|
|
|
profile.OsDisk.ManagedDisk = &compute.ManagedDiskParameters{
|
|
|
|
StorageAccountType: storageAccountType,
|
|
|
|
}
|
2017-05-29 00:06:09 -04:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-08-13 04:45:04 -04:00
|
|
|
func (s *TemplateBuilder) SetManagedMarketplaceImage(location, publisher, offer, sku, version, imageID string, storageAccountType compute.StorageAccountTypes) error {
|
2017-05-29 00:06:09 -04:00
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.StorageProfile
|
|
|
|
profile.ImageReference = &compute.ImageReference{
|
2017-05-30 03:33:54 -04:00
|
|
|
Publisher: &publisher,
|
|
|
|
Offer: &offer,
|
|
|
|
Sku: &sku,
|
|
|
|
Version: &version,
|
|
|
|
//ID: &imageID,
|
2017-05-29 00:06:09 -04:00
|
|
|
}
|
2017-05-30 03:33:54 -04:00
|
|
|
profile.OsDisk.OsType = s.osType
|
2018-04-06 04:12:58 -04:00
|
|
|
profile.OsDisk.CreateOption = compute.DiskCreateOptionTypesFromImage
|
2017-05-29 00:06:09 -04:00
|
|
|
profile.OsDisk.Vhd = nil
|
2017-08-13 04:45:04 -04:00
|
|
|
profile.OsDisk.ManagedDisk = &compute.ManagedDiskParameters{
|
|
|
|
StorageAccountType: storageAccountType,
|
|
|
|
}
|
2017-05-29 00:06:09 -04:00
|
|
|
|
2016-05-21 02:01:16 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-30 16:56:44 -04:00
|
|
|
func (s *TemplateBuilder) SetSharedGalleryImage(location, imageID string) error {
|
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.StorageProfile
|
2018-10-03 19:10:46 -04:00
|
|
|
profile.ImageReference = &compute.ImageReference{ID: &imageID}
|
2018-09-30 16:56:44 -04:00
|
|
|
profile.OsDisk.OsType = s.osType
|
|
|
|
profile.OsDisk.Vhd = nil
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-21 02:01:16 -04:00
|
|
|
func (s *TemplateBuilder) SetMarketPlaceImage(publisher, offer, sku, version string) error {
|
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.StorageProfile
|
|
|
|
profile.ImageReference = &compute.ImageReference{
|
|
|
|
Publisher: to.StringPtr(publisher),
|
|
|
|
Offer: to.StringPtr(offer),
|
|
|
|
Sku: to.StringPtr(sku),
|
|
|
|
Version: to.StringPtr(version),
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TemplateBuilder) SetImageUrl(imageUrl string, osType compute.OperatingSystemTypes) error {
|
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.StorageProfile
|
|
|
|
profile.OsDisk.OsType = osType
|
|
|
|
profile.OsDisk.Image = &compute.VirtualHardDisk{
|
|
|
|
URI: to.StringPtr(imageUrl),
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-05 04:27:52 -05:00
|
|
|
func (s *TemplateBuilder) SetPlanInfo(name, product, publisher, promotionCode string) error {
|
|
|
|
var promotionCodeVal *string = nil
|
|
|
|
if promotionCode != "" {
|
|
|
|
promotionCodeVal = to.StringPtr(promotionCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, x := range *s.template.Resources {
|
|
|
|
if strings.EqualFold(*x.Type, resourceVirtualMachine) {
|
|
|
|
(*s.template.Resources)[i].Plan = &Plan{
|
|
|
|
Name: to.StringPtr(name),
|
|
|
|
Product: to.StringPtr(product),
|
|
|
|
Publisher: to.StringPtr(publisher),
|
|
|
|
PromotionCode: promotionCodeVal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-10-12 19:24:04 -04:00
|
|
|
func (s *TemplateBuilder) SetOSDiskSizeGB(diskSizeGB int32) error {
|
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.StorageProfile
|
|
|
|
profile.OsDisk.DiskSizeGB = to.Int32Ptr(diskSizeGB)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-23 18:34:13 -05:00
|
|
|
func (s *TemplateBuilder) SetAdditionalDisks(diskSizeGB []int32, isManaged bool) error {
|
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.StorageProfile
|
|
|
|
dataDisks := make([]DataDiskUnion, len(diskSizeGB))
|
|
|
|
|
|
|
|
for i, additionalsize := range diskSizeGB {
|
|
|
|
dataDisks[i].DiskSizeGB = to.Int32Ptr(additionalsize)
|
|
|
|
dataDisks[i].Lun = to.IntPtr(i)
|
|
|
|
dataDisks[i].Name = to.StringPtr(fmt.Sprintf("datadisk-%d", i+1))
|
|
|
|
dataDisks[i].CreateOption = "Empty"
|
|
|
|
dataDisks[i].Caching = "ReadWrite"
|
|
|
|
if isManaged {
|
|
|
|
dataDisks[i].Vhd = nil
|
|
|
|
dataDisks[i].ManagedDisk = profile.OsDisk.ManagedDisk
|
|
|
|
} else {
|
|
|
|
dataDisks[i].Vhd = &compute.VirtualHardDisk{
|
|
|
|
URI: to.StringPtr(fmt.Sprintf("[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/datadisk-', '%d','.vhd')]", i+1)),
|
|
|
|
}
|
|
|
|
dataDisks[i].ManagedDisk = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
profile.DataDisks = &dataDisks
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-10-13 14:56:23 -04:00
|
|
|
func (s *TemplateBuilder) SetCustomData(customData string) error {
|
|
|
|
resource, err := s.getResourceByType(resourceVirtualMachine)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
profile := resource.Properties.OsProfile
|
|
|
|
profile.CustomData = to.StringPtr(customData)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-06-30 19:51:52 -04:00
|
|
|
func (s *TemplateBuilder) SetVirtualNetwork(virtualNetworkResourceGroup, virtualNetworkName, subnetName string) error {
|
|
|
|
s.setVariable("virtualNetworkResourceGroup", virtualNetworkResourceGroup)
|
|
|
|
s.setVariable("virtualNetworkName", virtualNetworkName)
|
|
|
|
s.setVariable("subnetName", subnetName)
|
|
|
|
|
|
|
|
s.deleteResourceByType(resourceVirtualNetworks)
|
|
|
|
s.deleteResourceByType(resourcePublicIPAddresses)
|
|
|
|
resource, err := s.getResourceByType(resourceNetworkInterfaces)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.deleteResourceDependency(resource, func(s string) bool {
|
|
|
|
return strings.Contains(s, "Microsoft.Network/virtualNetworks") ||
|
|
|
|
strings.Contains(s, "Microsoft.Network/publicIPAddresses")
|
|
|
|
})
|
|
|
|
|
2017-05-28 03:38:45 -04:00
|
|
|
(*resource.Properties.IPConfigurations)[0].PublicIPAddress = nil
|
2016-06-30 19:51:52 -04:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-13 04:14:30 -04:00
|
|
|
func (s *TemplateBuilder) SetPrivateVirtualNetworkWithPublicIp(virtualNetworkResourceGroup, virtualNetworkName, subnetName string) error {
|
2017-08-06 18:32:44 -04:00
|
|
|
s.setVariable("virtualNetworkResourceGroup", virtualNetworkResourceGroup)
|
|
|
|
s.setVariable("virtualNetworkName", virtualNetworkName)
|
|
|
|
s.setVariable("subnetName", subnetName)
|
|
|
|
|
|
|
|
s.deleteResourceByType(resourceVirtualNetworks)
|
|
|
|
resource, err := s.getResourceByType(resourceNetworkInterfaces)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.deleteResourceDependency(resource, func(s string) bool {
|
|
|
|
return strings.Contains(s, "Microsoft.Network/virtualNetworks")
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-07-29 17:17:33 -04:00
|
|
|
func (s *TemplateBuilder) SetTags(tags *map[string]*string) error {
|
|
|
|
if tags == nil || len(*tags) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range *s.template.Resources {
|
|
|
|
(*s.template.Resources)[i].Tags = tags
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-21 02:01:16 -04:00
|
|
|
func (s *TemplateBuilder) ToJSON() (*string, error) {
|
|
|
|
bs, err := json.MarshalIndent(s.template, jsonPrefix, jsonIndent)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return to.StringPtr(string(bs)), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TemplateBuilder) getResourceByType(t string) (*Resource, error) {
|
|
|
|
for _, x := range *s.template.Resources {
|
|
|
|
if strings.EqualFold(*x.Type, t) {
|
|
|
|
return &x, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("template: could not find a resource of type %s", t)
|
|
|
|
}
|
|
|
|
|
2018-03-05 04:27:52 -05:00
|
|
|
func (s *TemplateBuilder) getResourceByType2(t string) (**Resource, error) {
|
|
|
|
for _, x := range *s.template.Resources {
|
|
|
|
if strings.EqualFold(*x.Type, t) {
|
|
|
|
p := &x
|
|
|
|
return &p, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("template: could not find a resource of type %s", t)
|
|
|
|
}
|
|
|
|
|
2016-06-30 19:51:52 -04:00
|
|
|
func (s *TemplateBuilder) setVariable(name string, value string) {
|
|
|
|
(*s.template.Variables)[name] = value
|
|
|
|
}
|
|
|
|
|
2016-05-21 02:01:16 -04:00
|
|
|
func (s *TemplateBuilder) toKeyVaultID(name string) string {
|
|
|
|
return s.toResourceID(resourceKeyVaults, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TemplateBuilder) toResourceID(id, name string) string {
|
|
|
|
return fmt.Sprintf("[resourceId(resourceGroup().name, '%s', '%s')]", id, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TemplateBuilder) toVariable(name string) string {
|
|
|
|
return fmt.Sprintf("[variables('%s')]", name)
|
|
|
|
}
|
|
|
|
|
2016-06-30 19:51:52 -04:00
|
|
|
func (s *TemplateBuilder) deleteResourceByType(resourceType string) {
|
|
|
|
resources := make([]Resource, 0)
|
|
|
|
|
|
|
|
for _, resource := range *s.template.Resources {
|
|
|
|
if *resource.Type == resourceType {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
resources = append(resources, resource)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.template.Resources = &resources
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TemplateBuilder) deleteResourceDependency(resource *Resource, predicate func(string) bool) {
|
|
|
|
deps := make([]string, 0)
|
|
|
|
|
|
|
|
for _, dep := range *resource.DependsOn {
|
|
|
|
if !predicate(dep) {
|
|
|
|
deps = append(deps, dep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*resource.DependsOn = deps
|
|
|
|
}
|
|
|
|
|
2016-07-29 17:17:33 -04:00
|
|
|
// See https://github.com/Azure/azure-quickstart-templates for a extensive list of templates.
|
|
|
|
|
|
|
|
// Template to deploy a KeyVault.
|
|
|
|
//
|
|
|
|
// This template is still hard-coded unlike the ARM templates used for VMs for
|
|
|
|
// a couple of reasons.
|
|
|
|
//
|
|
|
|
// 1. The SDK defines no types for a Key Vault
|
|
|
|
// 2. The Key Vault template is relatively simple, and is static.
|
|
|
|
//
|
|
|
|
const KeyVault = `{
|
|
|
|
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
|
|
|
|
"contentVersion": "1.0.0.0",
|
|
|
|
"parameters": {
|
|
|
|
"keyVaultName": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"keyVaultSecretValue": {
|
|
|
|
"type": "securestring"
|
|
|
|
},
|
|
|
|
"objectId": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"tenantId": {
|
|
|
|
"type": "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"variables": {
|
|
|
|
"apiVersion": "2015-06-01",
|
|
|
|
"location": "[resourceGroup().location]",
|
|
|
|
"keyVaultSecretName": "packerKeyVaultSecret"
|
|
|
|
},
|
|
|
|
"resources": [
|
|
|
|
{
|
|
|
|
"apiVersion": "[variables('apiVersion')]",
|
|
|
|
"type": "Microsoft.KeyVault/vaults",
|
|
|
|
"name": "[parameters('keyVaultName')]",
|
|
|
|
"location": "[variables('location')]",
|
|
|
|
"properties": {
|
|
|
|
"enabledForDeployment": "true",
|
|
|
|
"enabledForTemplateDeployment": "true",
|
|
|
|
"tenantId": "[parameters('tenantId')]",
|
|
|
|
"accessPolicies": [
|
|
|
|
{
|
|
|
|
"tenantId": "[parameters('tenantId')]",
|
|
|
|
"objectId": "[parameters('objectId')]",
|
|
|
|
"permissions": {
|
|
|
|
"keys": [ "all" ],
|
|
|
|
"secrets": [ "all" ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"sku": {
|
|
|
|
"name": "standard",
|
|
|
|
"family": "A"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"resources": [
|
|
|
|
{
|
|
|
|
"apiVersion": "[variables('apiVersion')]",
|
|
|
|
"type": "secrets",
|
|
|
|
"name": "[variables('keyVaultSecretName')]",
|
|
|
|
"dependsOn": [
|
|
|
|
"[concat('Microsoft.KeyVault/vaults/', parameters('keyVaultName'))]"
|
|
|
|
],
|
|
|
|
"properties": {
|
|
|
|
"value": "[parameters('keyVaultSecretValue')]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}`
|
|
|
|
|
|
|
|
const BasicTemplate = `{
|
2016-05-21 02:01:16 -04:00
|
|
|
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
|
|
|
|
"contentVersion": "1.0.0.0",
|
|
|
|
"parameters": {
|
|
|
|
"adminUsername": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"adminPassword": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"dnsNameForPublicIP": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2018-03-10 14:17:43 -05:00
|
|
|
"nicName": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2016-05-21 02:01:16 -04:00
|
|
|
"osDiskName": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2018-03-10 14:17:43 -05:00
|
|
|
"publicIPAddressName": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"subnetName": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2016-05-21 02:01:16 -04:00
|
|
|
"storageAccountBlobEndpoint": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2018-03-10 14:17:43 -05:00
|
|
|
"virtualNetworkName": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2016-05-21 02:01:16 -04:00
|
|
|
"vmSize": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"vmName": {
|
|
|
|
"type": "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"variables": {
|
|
|
|
"addressPrefix": "10.0.0.0/16",
|
2018-09-30 16:56:44 -04:00
|
|
|
"apiVersion": "2018-04-01",
|
2017-05-29 00:06:09 -04:00
|
|
|
"managedDiskApiVersion": "2017-03-30",
|
|
|
|
"networkInterfacesApiVersion": "2017-04-01",
|
|
|
|
"publicIPAddressApiVersion": "2017-04-01",
|
|
|
|
"virtualNetworksApiVersion": "2017-04-01",
|
2016-05-21 02:01:16 -04:00
|
|
|
"location": "[resourceGroup().location]",
|
|
|
|
"publicIPAddressType": "Dynamic",
|
|
|
|
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
|
2018-03-10 14:17:43 -05:00
|
|
|
"subnetName": "[parameters('subnetName')]",
|
2016-05-21 02:01:16 -04:00
|
|
|
"subnetAddressPrefix": "10.0.0.0/24",
|
|
|
|
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
|
2018-03-10 14:17:43 -05:00
|
|
|
"virtualNetworkName": "[parameters('virtualNetworkName')]",
|
2016-06-30 19:51:52 -04:00
|
|
|
"virtualNetworkResourceGroup": "[resourceGroup().name]",
|
2016-05-21 02:01:16 -04:00
|
|
|
"vmStorageAccountContainerName": "images",
|
2016-06-30 19:51:52 -04:00
|
|
|
"vnetID": "[resourceId(variables('virtualNetworkResourceGroup'), 'Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
|
2016-05-21 02:01:16 -04:00
|
|
|
},
|
|
|
|
"resources": [
|
|
|
|
{
|
2017-05-29 00:06:09 -04:00
|
|
|
"apiVersion": "[variables('publicIPAddressApiVersion')]",
|
2016-05-21 02:01:16 -04:00
|
|
|
"type": "Microsoft.Network/publicIPAddresses",
|
2018-03-10 14:17:43 -05:00
|
|
|
"name": "[parameters('publicIPAddressName')]",
|
2016-05-21 02:01:16 -04:00
|
|
|
"location": "[variables('location')]",
|
|
|
|
"properties": {
|
|
|
|
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
|
|
|
|
"dnsSettings": {
|
|
|
|
"domainNameLabel": "[parameters('dnsNameForPublicIP')]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-05-29 00:06:09 -04:00
|
|
|
"apiVersion": "[variables('virtualNetworksApiVersion')]",
|
2016-05-21 02:01:16 -04:00
|
|
|
"type": "Microsoft.Network/virtualNetworks",
|
|
|
|
"name": "[variables('virtualNetworkName')]",
|
|
|
|
"location": "[variables('location')]",
|
|
|
|
"properties": {
|
|
|
|
"addressSpace": {
|
|
|
|
"addressPrefixes": [
|
|
|
|
"[variables('addressPrefix')]"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"subnets": [
|
|
|
|
{
|
|
|
|
"name": "[variables('subnetName')]",
|
|
|
|
"properties": {
|
|
|
|
"addressPrefix": "[variables('subnetAddressPrefix')]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-05-29 00:06:09 -04:00
|
|
|
"apiVersion": "[variables('networkInterfacesApiVersion')]",
|
2016-05-21 02:01:16 -04:00
|
|
|
"type": "Microsoft.Network/networkInterfaces",
|
2018-03-10 14:17:43 -05:00
|
|
|
"name": "[parameters('nicName')]",
|
2016-05-21 02:01:16 -04:00
|
|
|
"location": "[variables('location')]",
|
|
|
|
"dependsOn": [
|
2018-03-10 14:17:43 -05:00
|
|
|
"[concat('Microsoft.Network/publicIPAddresses/', parameters('publicIPAddressName'))]",
|
2016-05-21 02:01:16 -04:00
|
|
|
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
|
|
|
|
],
|
|
|
|
"properties": {
|
|
|
|
"ipConfigurations": [
|
|
|
|
{
|
|
|
|
"name": "ipconfig",
|
|
|
|
"properties": {
|
|
|
|
"privateIPAllocationMethod": "Dynamic",
|
|
|
|
"publicIPAddress": {
|
2018-03-10 14:17:43 -05:00
|
|
|
"id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddressName'))]"
|
2016-05-21 02:01:16 -04:00
|
|
|
},
|
|
|
|
"subnet": {
|
|
|
|
"id": "[variables('subnetRef')]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"apiVersion": "[variables('apiVersion')]",
|
|
|
|
"type": "Microsoft.Compute/virtualMachines",
|
|
|
|
"name": "[parameters('vmName')]",
|
|
|
|
"location": "[variables('location')]",
|
|
|
|
"dependsOn": [
|
2018-03-10 14:17:43 -05:00
|
|
|
"[concat('Microsoft.Network/networkInterfaces/', parameters('nicName'))]"
|
2016-05-21 02:01:16 -04:00
|
|
|
],
|
|
|
|
"properties": {
|
|
|
|
"hardwareProfile": {
|
|
|
|
"vmSize": "[parameters('vmSize')]"
|
|
|
|
},
|
|
|
|
"osProfile": {
|
|
|
|
"computerName": "[parameters('vmName')]",
|
|
|
|
"adminUsername": "[parameters('adminUsername')]",
|
|
|
|
"adminPassword": "[parameters('adminPassword')]"
|
|
|
|
},
|
|
|
|
"storageProfile": {
|
|
|
|
"osDisk": {
|
2018-05-02 14:18:03 -04:00
|
|
|
"name": "[parameters('osDiskName')]",
|
2016-05-21 02:01:16 -04:00
|
|
|
"vhd": {
|
|
|
|
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
|
|
|
},
|
|
|
|
"caching": "ReadWrite",
|
|
|
|
"createOption": "FromImage"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"networkProfile": {
|
|
|
|
"networkInterfaces": [
|
|
|
|
{
|
2018-03-10 14:17:43 -05:00
|
|
|
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]"
|
2016-05-21 02:01:16 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"diagnosticsProfile": {
|
|
|
|
"bootDiagnostics": {
|
|
|
|
"enabled": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}`
|