Update to an official version of Approvals

The in-project version of Approvals has been moved to its own GitHub
project under the offcial umbrella.  This PR snaps to that version of the
code.an official version of Approvals

The in-project version of Approvals has been moved to its own GitHub
project under the offcial umbrella.  This PR snaps to that version of the
code.
This commit is contained in:
Christopher Boumenot 2016-07-11 14:36:49 -07:00
parent 2e949bf43d
commit 130cea91d4
9 changed files with 882 additions and 630 deletions

View File

@ -0,0 +1,67 @@
{
"$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"
}
},
"resources": [
{
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"name": "[parameters('keyVaultName')]",
"properties": {
"accessPolicies": [
{
"objectId": "[parameters('objectId')]",
"permissions": {
"keys": [
"all"
],
"secrets": [
"all"
]
},
"tenantId": "[parameters('tenantId')]"
}
],
"enabledForDeployment": "true",
"enabledForTemplateDeployment": "true",
"sku": {
"family": "A",
"name": "standard"
},
"tenantId": "[parameters('tenantId')]"
},
"resources": [
{
"apiVersion": "[variables('apiVersion')]",
"dependsOn": [
"[concat('Microsoft.KeyVault/vaults/', parameters('keyVaultName'))]"
],
"name": "[variables('keyVaultSecretName')]",
"properties": {
"value": "[parameters('keyVaultSecretValue')]"
},
"type": "secrets"
}
],
"type": "Microsoft.KeyVault/vaults"
}
],
"variables": {
"apiVersion": "2015-06-01",
"keyVaultSecretName": "packerKeyVaultSecret",
"location": "[resourceGroup().location]"
}
}

View File

@ -0,0 +1,160 @@
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"adminPassword": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"dnsNameForPublicIP": {
"type": "string"
},
"osDiskName": {
"type": "string"
},
"storageAccountBlobEndpoint": {
"type": "string"
},
"vmName": {
"type": "string"
},
"vmSize": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"name": "[variables('publicIPAddressName')]",
"properties": {
"dnsSettings": {
"domainNameLabel": "[parameters('dnsNameForPublicIP')]"
},
"publicIPAllocationMethod": "[variables('publicIPAddressType')]"
},
"type": "Microsoft.Network/publicIPAddresses"
},
{
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"name": "[variables('virtualNetworkName')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetAddressPrefix')]"
}
}
]
},
"type": "Microsoft.Network/virtualNetworks"
},
{
"apiVersion": "[variables('apiVersion')]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"location": "[variables('location')]",
"name": "[variables('nicName')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
},
"type": "Microsoft.Network/networkInterfaces"
},
{
"apiVersion": "[variables('apiVersion')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"location": "[variables('location')]",
"name": "[parameters('vmName')]",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": false
}
},
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
},
"osProfile": {
"adminPassword": "[parameters('adminPassword')]",
"adminUsername": "[parameters('adminUsername')]",
"computerName": "[parameters('vmName')]",
"linuxConfiguration": {
"ssh": {
"publicKeys": [
{
"keyData": "",
"path": "[variables('sshKeyPath')]"
}
]
}
}
},
"storageProfile": {
"imageReference": {
"offer": "ImageOffer",
"publisher": "ImagePublisher",
"sku": "ImageSku",
"version": "ImageVersion"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "osdisk",
"vhd": {
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
}
}
}
},
"type": "Microsoft.Compute/virtualMachines"
}
],
"variables": {
"addressPrefix": "10.0.0.0/16",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"nicName": "packerNic",
"publicIPAddressName": "packerPublicIP",
"publicIPAddressType": "Dynamic",
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
"subnetAddressPrefix": "10.0.0.0/24",
"subnetName": "packerSubnet",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"virtualNetworkName": "packerNetwork",
"vmStorageAccountContainerName": "images",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
}
}

View File

@ -0,0 +1,158 @@
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"adminPassword": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"dnsNameForPublicIP": {
"type": "string"
},
"osDiskName": {
"type": "string"
},
"storageAccountBlobEndpoint": {
"type": "string"
},
"vmName": {
"type": "string"
},
"vmSize": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"name": "[variables('publicIPAddressName')]",
"properties": {
"dnsSettings": {
"domainNameLabel": "[parameters('dnsNameForPublicIP')]"
},
"publicIPAllocationMethod": "[variables('publicIPAddressType')]"
},
"type": "Microsoft.Network/publicIPAddresses"
},
{
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"name": "[variables('virtualNetworkName')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetAddressPrefix')]"
}
}
]
},
"type": "Microsoft.Network/virtualNetworks"
},
{
"apiVersion": "[variables('apiVersion')]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"location": "[variables('location')]",
"name": "[variables('nicName')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
},
"type": "Microsoft.Network/networkInterfaces"
},
{
"apiVersion": "[variables('apiVersion')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"location": "[variables('location')]",
"name": "[parameters('vmName')]",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": false
}
},
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
},
"osProfile": {
"adminPassword": "[parameters('adminPassword')]",
"adminUsername": "[parameters('adminUsername')]",
"computerName": "[parameters('vmName')]",
"linuxConfiguration": {
"ssh": {
"publicKeys": [
{
"keyData": "",
"path": "[variables('sshKeyPath')]"
}
]
}
}
},
"storageProfile": {
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"image": {
"uri": "https://localhost/custom.vhd"
},
"name": "osdisk",
"osType": "Linux",
"vhd": {
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
}
}
}
},
"type": "Microsoft.Compute/virtualMachines"
}
],
"variables": {
"addressPrefix": "10.0.0.0/16",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"nicName": "packerNic",
"publicIPAddressName": "packerPublicIP",
"publicIPAddressType": "Dynamic",
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
"subnetAddressPrefix": "10.0.0.0/24",
"subnetName": "packerSubnet",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"virtualNetworkName": "packerNetwork",
"vmStorageAccountContainerName": "images",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
}
}

View File

@ -2,11 +2,10 @@ package arm
import ( import (
"encoding/json" "encoding/json"
"strings"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/arm/resources/resources" "github.com/Azure/azure-sdk-for-go/arm/resources/resources"
"github.com/mitchellh/packer/builder/azure/common/approvals" "github.com/approvals/go-approval-tests"
"github.com/mitchellh/packer/builder/azure/common/constants" "github.com/mitchellh/packer/builder/azure/common/constants"
"github.com/mitchellh/packer/builder/azure/common/template" "github.com/mitchellh/packer/builder/azure/common/template"
) )
@ -115,8 +114,7 @@ func TestVirtualMachineDeployment03(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
reader := strings.NewReader(string(bs)) err = approvaltests.VerifyJSONBytes(t, bs)
err = approvals.Verify(t, reader)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -151,8 +149,7 @@ func TestVirtualMachineDeployment04(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
reader := strings.NewReader(string(bs)) err = approvaltests.VerifyJSONBytes(t, bs)
err = approvals.Verify(t, reader)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -248,8 +245,7 @@ func TestKeyVaultDeployment03(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
reader := strings.NewReader(string(bs)) err = approvaltests.VerifyJSONBytes(t, bs)
err = approvals.Verify(t, reader)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -1,122 +0,0 @@
package approvals
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"runtime"
"strings"
"testing"
)
type testState struct {
pc uintptr
fullName string
name string
fileName string
fileLine int
}
func Verify(t *testing.T, reader io.Reader) error {
state, err := findTestMethod()
if err != nil {
return err
}
return state.compare(state.getApprovalFile(), reader)
}
func (s *testState) compare(approvalFile string, reader io.Reader) error {
received, err := ioutil.ReadAll(reader)
if err != nil {
return err
}
// Ideally, this should only be written if
// 1. the approval file does not exist
// 2. the results differ
err = s.dumpReceivedTestResult(received)
if err != nil {
return err
}
fh, err := os.Open(approvalFile)
if err != nil {
return err
}
defer fh.Close()
approved, err := ioutil.ReadAll(fh)
if err != nil {
return err
}
// The two sides are identical, nothing more to do.
if bytes.Compare(received, approved) == 0 {
return nil
}
return fmt.Errorf("failed to approved %s", s.name)
}
func (s *testState) dumpReceivedTestResult(bs []byte) error {
fn := s.getReceivedFile()
err := ioutil.WriteFile(fn, bs, 0644)
return err
}
func (s *testState) getReceivedFile() string {
return fmt.Sprintf("%s.received.txt", s.name)
}
func (s *testState) getApprovalFile() string {
return fmt.Sprintf("%s.approved.txt", s.name)
}
func newTestState(pc uintptr, f *runtime.Func) (*testState, error) {
state := &testState{
pc: pc,
fullName: f.Name(),
}
state.fileName, state.fileLine = f.FileLine(pc)
splits := strings.Split(state.fullName, ".")
state.name = splits[len(splits)-1]
return state, nil
}
// Walk the call stack, and try to find the test method that was executed.
// The test method is identified by looking for the test runner, which is
// *assumed* to be common across all callers. The test runner has a Name() of
// 'testing.tRunner'. The method immediately previous to this is the test
// method.
func findTestMethod() (*testState, error) {
pc := make([]uintptr, 100)
count := runtime.Callers(0, pc)
i := 0
var lastFunc *runtime.Func
for ; i < count; i++ {
lastFunc = runtime.FuncForPC(pc[i])
if isTestRunner(lastFunc) {
break
}
}
if i == 0 || !isTestRunner(lastFunc) {
return nil, fmt.Errorf("approvals: could not find the test method")
}
testMethod := runtime.FuncForPC(pc[i-1])
return newTestState(pc[i-1], testMethod)
}
func isTestRunner(f *runtime.Func) bool {
return f != nil && f.Name() == "testing.tRunner"
}

View File

@ -24,39 +24,23 @@
"type": "string" "type": "string"
} }
}, },
"variables": {
"addressPrefix": "10.0.0.0/16",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"nicName": "packerNic",
"publicIPAddressName": "packerPublicIP",
"publicIPAddressType": "Dynamic",
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
"subnetAddressPrefix": "10.0.0.0/24",
"subnetName": "packerSubnet",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"virtualNetworkName": "packerNetwork",
"vmStorageAccountContainerName": "images",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
},
"resources": [ "resources": [
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[variables('publicIPAddressName')]",
"type": "Microsoft.Network/publicIPAddresses",
"location": "[variables('location')]", "location": "[variables('location')]",
"name": "[variables('publicIPAddressName')]",
"properties": { "properties": {
"dnsSettings": { "dnsSettings": {
"domainNameLabel": "[parameters('dnsNameForPublicIP')]" "domainNameLabel": "[parameters('dnsNameForPublicIP')]"
}, },
"publicIPAllocationMethod": "[variables('publicIPAddressType')]" "publicIPAllocationMethod": "[variables('publicIPAddressType')]"
} },
"type": "Microsoft.Network/publicIPAddresses"
}, },
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[variables('virtualNetworkName')]",
"type": "Microsoft.Network/virtualNetworks",
"location": "[variables('location')]", "location": "[variables('location')]",
"name": "[variables('virtualNetworkName')]",
"properties": { "properties": {
"addressSpace": { "addressSpace": {
"addressPrefixes": [ "addressPrefixes": [
@ -65,48 +49,48 @@
}, },
"subnets": [ "subnets": [
{ {
"name": "[variables('subnetName')]",
"properties": { "properties": {
"addressPrefix": "[variables('subnetAddressPrefix')]" "addressPrefix": "[variables('subnetAddressPrefix')]"
}, }
"name": "[variables('subnetName')]"
} }
] ]
} },
"type": "Microsoft.Network/virtualNetworks"
}, },
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[variables('nicName')]",
"type": "Microsoft.Network/networkInterfaces",
"location": "[variables('location')]",
"dependsOn": [ "dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
], ],
"location": "[variables('location')]",
"name": "[variables('nicName')]",
"properties": { "properties": {
"ipConfigurations": [ "ipConfigurations": [
{ {
"name": "ipconfig",
"properties": { "properties": {
"privateIPAllocationMethod": "Dynamic", "privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
},
"publicIPAddress": { "publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
}
}, },
"name": "ipconfig" "subnet": {
"id": "[variables('subnetRef')]"
}
}
} }
] ]
} },
"type": "Microsoft.Network/networkInterfaces"
}, },
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[parameters('vmName')]",
"type": "Microsoft.Compute/virtualMachines",
"location": "[variables('location')]",
"dependsOn": [ "dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
], ],
"location": "[variables('location')]",
"name": "[parameters('vmName')]",
"properties": { "properties": {
"diagnosticsProfile": { "diagnosticsProfile": {
"bootDiagnostics": { "bootDiagnostics": {
@ -124,15 +108,15 @@
] ]
}, },
"osProfile": { "osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]", "adminPassword": "[parameters('adminPassword')]",
"adminUsername": "[parameters('adminUsername')]",
"computerName": "[parameters('vmName')]",
"linuxConfiguration": { "linuxConfiguration": {
"ssh": { "ssh": {
"publicKeys": [ "publicKeys": [
{ {
"path": "[variables('sshKeyPath')]", "keyData": "--test-ssh-authorized-key--",
"keyData": "--test-ssh-authorized-key--" "path": "[variables('sshKeyPath')]"
} }
] ]
} }
@ -140,21 +124,37 @@
}, },
"storageProfile": { "storageProfile": {
"imageReference": { "imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer", "offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04", "sku": "16.04",
"version": "latest" "version": "latest"
}, },
"osDisk": { "osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "osdisk", "name": "osdisk",
"vhd": { "vhd": {
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
}
}
}
}, },
"caching": "ReadWrite", "type": "Microsoft.Compute/virtualMachines"
"createOption": "FromImage"
} }
],
"variables": {
"addressPrefix": "10.0.0.0/16",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"nicName": "packerNic",
"publicIPAddressName": "packerPublicIP",
"publicIPAddressType": "Dynamic",
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
"subnetAddressPrefix": "10.0.0.0/24",
"subnetName": "packerSubnet",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"virtualNetworkName": "packerNetwork",
"vmStorageAccountContainerName": "images",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
} }
}
}
]
} }

View File

@ -24,39 +24,23 @@
"type": "string" "type": "string"
} }
}, },
"variables": {
"addressPrefix": "10.0.0.0/16",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"nicName": "packerNic",
"publicIPAddressName": "packerPublicIP",
"publicIPAddressType": "Dynamic",
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
"subnetAddressPrefix": "10.0.0.0/24",
"subnetName": "packerSubnet",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"virtualNetworkName": "packerNetwork",
"vmStorageAccountContainerName": "images",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
},
"resources": [ "resources": [
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[variables('publicIPAddressName')]",
"type": "Microsoft.Network/publicIPAddresses",
"location": "[variables('location')]", "location": "[variables('location')]",
"name": "[variables('publicIPAddressName')]",
"properties": { "properties": {
"dnsSettings": { "dnsSettings": {
"domainNameLabel": "[parameters('dnsNameForPublicIP')]" "domainNameLabel": "[parameters('dnsNameForPublicIP')]"
}, },
"publicIPAllocationMethod": "[variables('publicIPAddressType')]" "publicIPAllocationMethod": "[variables('publicIPAddressType')]"
} },
"type": "Microsoft.Network/publicIPAddresses"
}, },
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[variables('virtualNetworkName')]",
"type": "Microsoft.Network/virtualNetworks",
"location": "[variables('location')]", "location": "[variables('location')]",
"name": "[variables('virtualNetworkName')]",
"properties": { "properties": {
"addressSpace": { "addressSpace": {
"addressPrefixes": [ "addressPrefixes": [
@ -65,48 +49,48 @@
}, },
"subnets": [ "subnets": [
{ {
"name": "[variables('subnetName')]",
"properties": { "properties": {
"addressPrefix": "[variables('subnetAddressPrefix')]" "addressPrefix": "[variables('subnetAddressPrefix')]"
}, }
"name": "[variables('subnetName')]"
} }
] ]
} },
"type": "Microsoft.Network/virtualNetworks"
}, },
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[variables('nicName')]",
"type": "Microsoft.Network/networkInterfaces",
"location": "[variables('location')]",
"dependsOn": [ "dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
], ],
"location": "[variables('location')]",
"name": "[variables('nicName')]",
"properties": { "properties": {
"ipConfigurations": [ "ipConfigurations": [
{ {
"name": "ipconfig",
"properties": { "properties": {
"privateIPAllocationMethod": "Dynamic", "privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
},
"publicIPAddress": { "publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
}
}, },
"name": "ipconfig" "subnet": {
"id": "[variables('subnetRef')]"
}
}
} }
] ]
} },
"type": "Microsoft.Network/networkInterfaces"
}, },
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[parameters('vmName')]",
"type": "Microsoft.Compute/virtualMachines",
"location": "[variables('location')]",
"dependsOn": [ "dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
], ],
"location": "[variables('location')]",
"name": "[parameters('vmName')]",
"properties": { "properties": {
"diagnosticsProfile": { "diagnosticsProfile": {
"bootDiagnostics": { "bootDiagnostics": {
@ -124,15 +108,15 @@
] ]
}, },
"osProfile": { "osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]", "adminPassword": "[parameters('adminPassword')]",
"adminUsername": "[parameters('adminUsername')]",
"computerName": "[parameters('vmName')]",
"linuxConfiguration": { "linuxConfiguration": {
"ssh": { "ssh": {
"publicKeys": [ "publicKeys": [
{ {
"path": "[variables('sshKeyPath')]", "keyData": "--test-ssh-authorized-key--",
"keyData": "--test-ssh-authorized-key--" "path": "[variables('sshKeyPath')]"
} }
] ]
} }
@ -140,19 +124,35 @@
}, },
"storageProfile": { "storageProfile": {
"osDisk": { "osDisk": {
"osType": "Linux", "caching": "ReadWrite",
"name": "osdisk", "createOption": "FromImage",
"vhd": {
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
},
"image": { "image": {
"uri": "http://azure/custom.vhd" "uri": "http://azure/custom.vhd"
}, },
"caching": "ReadWrite", "name": "osdisk",
"createOption": "FromImage" "osType": "Linux",
"vhd": {
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
} }
} }
} }
},
"type": "Microsoft.Compute/virtualMachines"
}
],
"variables": {
"addressPrefix": "10.0.0.0/16",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"nicName": "packerNic",
"publicIPAddressName": "packerPublicIP",
"publicIPAddressType": "Dynamic",
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
"subnetAddressPrefix": "10.0.0.0/24",
"subnetName": "packerSubnet",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"virtualNetworkName": "packerNetwork",
"vmStorageAccountContainerName": "images",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
} }
]
} }

View File

@ -24,39 +24,23 @@
"type": "string" "type": "string"
} }
}, },
"variables": {
"addressPrefix": "10.0.0.0/16",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"nicName": "packerNic",
"publicIPAddressName": "packerPublicIP",
"publicIPAddressType": "Dynamic",
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
"subnetAddressPrefix": "10.0.0.0/24",
"subnetName": "packerSubnet",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"virtualNetworkName": "packerNetwork",
"vmStorageAccountContainerName": "images",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
},
"resources": [ "resources": [
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[variables('publicIPAddressName')]",
"type": "Microsoft.Network/publicIPAddresses",
"location": "[variables('location')]", "location": "[variables('location')]",
"name": "[variables('publicIPAddressName')]",
"properties": { "properties": {
"dnsSettings": { "dnsSettings": {
"domainNameLabel": "[parameters('dnsNameForPublicIP')]" "domainNameLabel": "[parameters('dnsNameForPublicIP')]"
}, },
"publicIPAllocationMethod": "[variables('publicIPAddressType')]" "publicIPAllocationMethod": "[variables('publicIPAddressType')]"
} },
"type": "Microsoft.Network/publicIPAddresses"
}, },
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[variables('virtualNetworkName')]",
"type": "Microsoft.Network/virtualNetworks",
"location": "[variables('location')]", "location": "[variables('location')]",
"name": "[variables('virtualNetworkName')]",
"properties": { "properties": {
"addressSpace": { "addressSpace": {
"addressPrefixes": [ "addressPrefixes": [
@ -65,48 +49,48 @@
}, },
"subnets": [ "subnets": [
{ {
"name": "[variables('subnetName')]",
"properties": { "properties": {
"addressPrefix": "[variables('subnetAddressPrefix')]" "addressPrefix": "[variables('subnetAddressPrefix')]"
}, }
"name": "[variables('subnetName')]"
} }
] ]
} },
"type": "Microsoft.Network/virtualNetworks"
}, },
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[variables('nicName')]",
"type": "Microsoft.Network/networkInterfaces",
"location": "[variables('location')]",
"dependsOn": [ "dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
], ],
"location": "[variables('location')]",
"name": "[variables('nicName')]",
"properties": { "properties": {
"ipConfigurations": [ "ipConfigurations": [
{ {
"name": "ipconfig",
"properties": { "properties": {
"privateIPAllocationMethod": "Dynamic", "privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
},
"publicIPAddress": { "publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
}
}, },
"name": "ipconfig" "subnet": {
"id": "[variables('subnetRef')]"
}
}
} }
] ]
} },
"type": "Microsoft.Network/networkInterfaces"
}, },
{ {
"apiVersion": "[variables('apiVersion')]", "apiVersion": "[variables('apiVersion')]",
"name": "[parameters('vmName')]",
"type": "Microsoft.Compute/virtualMachines",
"location": "[variables('location')]",
"dependsOn": [ "dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
], ],
"location": "[variables('location')]",
"name": "[parameters('vmName')]",
"properties": { "properties": {
"diagnosticsProfile": { "diagnosticsProfile": {
"bootDiagnostics": { "bootDiagnostics": {
@ -124,51 +108,67 @@
] ]
}, },
"osProfile": { "osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]", "adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": { "adminUsername": "[parameters('adminUsername')]",
"provisionVMAgent": true, "computerName": "[parameters('vmName')]",
"winRM": {
"listeners": [
{
"protocol": "https",
"certificateUrl": "--test-winrm-certificate-url--"
}
]
}
},
"secrets": [ "secrets": [
{ {
"sourceVault": { "sourceVault": {
"id": "[resourceId(resourceGroup().name, 'Microsoft.KeyVault/vaults', '--test-key-vault-name')]" "id": "[resourceId(resourceGroup().name, 'Microsoft.KeyVault/vaults', '--test-key-vault-name')]"
}, },
"vaultCertificates": [ "vaultCertificates": [
{
"certificateStore": "My",
"certificateUrl": "--test-winrm-certificate-url--"
}
]
}
],
"windowsConfiguration": {
"provisionVMAgent": true,
"winRM": {
"listeners": [
{ {
"certificateUrl": "--test-winrm-certificate-url--", "certificateUrl": "--test-winrm-certificate-url--",
"certificateStore": "My" "protocol": "https"
} }
] ]
} }
] }
}, },
"storageProfile": { "storageProfile": {
"imageReference": { "imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer", "offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2012-R2-Datacenter", "sku": "2012-R2-Datacenter",
"version": "latest" "version": "latest"
}, },
"osDisk": { "osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "osdisk", "name": "osdisk",
"vhd": { "vhd": {
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
}
}
}
}, },
"caching": "ReadWrite", "type": "Microsoft.Compute/virtualMachines"
"createOption": "FromImage"
} }
],
"variables": {
"addressPrefix": "10.0.0.0/16",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"nicName": "packerNic",
"publicIPAddressName": "packerPublicIP",
"publicIPAddressType": "Dynamic",
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
"subnetAddressPrefix": "10.0.0.0/24",
"subnetName": "packerSubnet",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"virtualNetworkName": "packerNetwork",
"vmStorageAccountContainerName": "images",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
} }
}
}
]
} }

View File

@ -1,11 +1,10 @@
package template package template
import ( import (
"strings"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/mitchellh/packer/builder/azure/common/approvals" "github.com/approvals/go-approval-tests"
) )
// Ensure that a Linux template is configured as expected. // Ensure that a Linux template is configured as expected.
@ -31,9 +30,7 @@ func TestBuildLinux00(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
reader := strings.NewReader(*doc) err = approvaltests.VerifyJSONBytes(t, []byte(*doc))
err = approvals.Verify(t, reader)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -61,9 +58,7 @@ func TestBuildLinux01(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
reader := strings.NewReader(*doc) err = approvaltests.VerifyJSONBytes(t, []byte(*doc))
err = approvals.Verify(t, reader)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -93,9 +88,7 @@ func TestBuildWindows00(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
reader := strings.NewReader(*doc) err = approvaltests.VerifyJSONBytes(t, []byte(*doc))
err = approvals.Verify(t, reader)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }