From 130cea91d4a3a0dbdc45d1c1f8c468a131277c5b Mon Sep 17 00:00:00 2001 From: Christopher Boumenot Date: Mon, 11 Jul 2016 14:36:49 -0700 Subject: [PATCH] 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. --- ...est.TestKeyVaultDeployment03.approved.json | 67 ++++ ...stVirtualMachineDeployment03.approved.json | 160 ++++++++ ...stVirtualMachineDeployment04.approved.json | 158 ++++++++ builder/azure/arm/template_factory_test.go | 12 +- builder/azure/common/approvals/approvals.go | 122 ------ ...ilder_test.TestBuildLinux00.approved.json} | 318 ++++++++-------- ...ilder_test.TestBuildLinux01.approved.json} | 314 ++++++++-------- ...der_test.TestBuildWindows00.approved.json} | 346 +++++++++--------- .../common/template/template_builder_test.go | 15 +- 9 files changed, 882 insertions(+), 630 deletions(-) create mode 100644 builder/azure/arm/template_factory_test.TestKeyVaultDeployment03.approved.json create mode 100644 builder/azure/arm/template_factory_test.TestVirtualMachineDeployment03.approved.json create mode 100644 builder/azure/arm/template_factory_test.TestVirtualMachineDeployment04.approved.json delete mode 100644 builder/azure/common/approvals/approvals.go rename builder/azure/common/template/{TestBuildLinux00.approved.txt => template_builder_test.TestBuildLinux00.approved.json} (86%) rename builder/azure/common/template/{TestBuildLinux01.approved.txt => template_builder_test.TestBuildLinux01.approved.json} (86%) rename builder/azure/common/template/{TestBuildWindows00.approved.txt => template_builder_test.TestBuildWindows00.approved.json} (87%) diff --git a/builder/azure/arm/template_factory_test.TestKeyVaultDeployment03.approved.json b/builder/azure/arm/template_factory_test.TestKeyVaultDeployment03.approved.json new file mode 100644 index 000000000..6d4049800 --- /dev/null +++ b/builder/azure/arm/template_factory_test.TestKeyVaultDeployment03.approved.json @@ -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]" + } +} \ No newline at end of file diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment03.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment03.approved.json new file mode 100644 index 000000000..a6fce9d67 --- /dev/null +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment03.approved.json @@ -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'))]" + } +} \ No newline at end of file diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment04.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment04.approved.json new file mode 100644 index 000000000..74a4b767f --- /dev/null +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment04.approved.json @@ -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'))]" + } +} \ No newline at end of file diff --git a/builder/azure/arm/template_factory_test.go b/builder/azure/arm/template_factory_test.go index b098ec37f..d2445c188 100644 --- a/builder/azure/arm/template_factory_test.go +++ b/builder/azure/arm/template_factory_test.go @@ -2,11 +2,10 @@ package arm import ( "encoding/json" - "strings" "testing" "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/template" ) @@ -115,8 +114,7 @@ func TestVirtualMachineDeployment03(t *testing.T) { t.Fatal(err) } - reader := strings.NewReader(string(bs)) - err = approvals.Verify(t, reader) + err = approvaltests.VerifyJSONBytes(t, bs) if err != nil { t.Fatal(err) } @@ -151,8 +149,7 @@ func TestVirtualMachineDeployment04(t *testing.T) { t.Fatal(err) } - reader := strings.NewReader(string(bs)) - err = approvals.Verify(t, reader) + err = approvaltests.VerifyJSONBytes(t, bs) if err != nil { t.Fatal(err) } @@ -248,8 +245,7 @@ func TestKeyVaultDeployment03(t *testing.T) { t.Fatal(err) } - reader := strings.NewReader(string(bs)) - err = approvals.Verify(t, reader) + err = approvaltests.VerifyJSONBytes(t, bs) if err != nil { t.Fatal(err) } diff --git a/builder/azure/common/approvals/approvals.go b/builder/azure/common/approvals/approvals.go deleted file mode 100644 index 605d9c4a9..000000000 --- a/builder/azure/common/approvals/approvals.go +++ /dev/null @@ -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" -} diff --git a/builder/azure/common/template/TestBuildLinux00.approved.txt b/builder/azure/common/template/template_builder_test.TestBuildLinux00.approved.json similarity index 86% rename from builder/azure/common/template/TestBuildLinux00.approved.txt rename to builder/azure/common/template/template_builder_test.TestBuildLinux00.approved.json index ebba273b8..a8ecfc0be 100644 --- a/builder/azure/common/template/TestBuildLinux00.approved.txt +++ b/builder/azure/common/template/template_builder_test.TestBuildLinux00.approved.json @@ -1,160 +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" - } - }, - "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": [ - { - "apiVersion": "[variables('apiVersion')]", - "name": "[variables('publicIPAddressName')]", - "type": "Microsoft.Network/publicIPAddresses", - "location": "[variables('location')]", - "properties": { - "dnsSettings": { - "domainNameLabel": "[parameters('dnsNameForPublicIP')]" - }, - "publicIPAllocationMethod": "[variables('publicIPAddressType')]" - } - }, - { - "apiVersion": "[variables('apiVersion')]", - "name": "[variables('virtualNetworkName')]", - "type": "Microsoft.Network/virtualNetworks", - "location": "[variables('location')]", - "properties": { - "addressSpace": { - "addressPrefixes": [ - "[variables('addressPrefix')]" - ] - }, - "subnets": [ - { - "properties": { - "addressPrefix": "[variables('subnetAddressPrefix')]" - }, - "name": "[variables('subnetName')]" - } - ] - } - }, - { - "apiVersion": "[variables('apiVersion')]", - "name": "[variables('nicName')]", - "type": "Microsoft.Network/networkInterfaces", - "location": "[variables('location')]", - "dependsOn": [ - "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", - "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" - ], - "properties": { - "ipConfigurations": [ - { - "properties": { - "privateIPAllocationMethod": "Dynamic", - "subnet": { - "id": "[variables('subnetRef')]" - }, - "publicIPAddress": { - "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" - } - }, - "name": "ipconfig" - } - ] - } - }, - { - "apiVersion": "[variables('apiVersion')]", - "name": "[parameters('vmName')]", - "type": "Microsoft.Compute/virtualMachines", - "location": "[variables('location')]", - "dependsOn": [ - "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" - ], - "properties": { - "diagnosticsProfile": { - "bootDiagnostics": { - "enabled": false - } - }, - "hardwareProfile": { - "vmSize": "[parameters('vmSize')]" - }, - "networkProfile": { - "networkInterfaces": [ - { - "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" - } - ] - }, - "osProfile": { - "computerName": "[parameters('vmName')]", - "adminUsername": "[parameters('adminUsername')]", - "adminPassword": "[parameters('adminPassword')]", - "linuxConfiguration": { - "ssh": { - "publicKeys": [ - { - "path": "[variables('sshKeyPath')]", - "keyData": "--test-ssh-authorized-key--" - } - ] - } - } - }, - "storageProfile": { - "imageReference": { - "publisher": "Canonical", - "offer": "UbuntuServer", - "sku": "16.04", - "version": "latest" - }, - "osDisk": { - "name": "osdisk", - "vhd": { - "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" - }, - "caching": "ReadWrite", - "createOption": "FromImage" - } - } - } - } - ] +{ + "$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": "--test-ssh-authorized-key--", + "path": "[variables('sshKeyPath')]" + } + ] + } + } + }, + "storageProfile": { + "imageReference": { + "offer": "UbuntuServer", + "publisher": "Canonical", + "sku": "16.04", + "version": "latest" + }, + "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'))]" + } } \ No newline at end of file diff --git a/builder/azure/common/template/TestBuildLinux01.approved.txt b/builder/azure/common/template/template_builder_test.TestBuildLinux01.approved.json similarity index 86% rename from builder/azure/common/template/TestBuildLinux01.approved.txt rename to builder/azure/common/template/template_builder_test.TestBuildLinux01.approved.json index 0f7799013..45bf5b271 100644 --- a/builder/azure/common/template/TestBuildLinux01.approved.txt +++ b/builder/azure/common/template/template_builder_test.TestBuildLinux01.approved.json @@ -1,158 +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" - } - }, - "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": [ - { - "apiVersion": "[variables('apiVersion')]", - "name": "[variables('publicIPAddressName')]", - "type": "Microsoft.Network/publicIPAddresses", - "location": "[variables('location')]", - "properties": { - "dnsSettings": { - "domainNameLabel": "[parameters('dnsNameForPublicIP')]" - }, - "publicIPAllocationMethod": "[variables('publicIPAddressType')]" - } - }, - { - "apiVersion": "[variables('apiVersion')]", - "name": "[variables('virtualNetworkName')]", - "type": "Microsoft.Network/virtualNetworks", - "location": "[variables('location')]", - "properties": { - "addressSpace": { - "addressPrefixes": [ - "[variables('addressPrefix')]" - ] - }, - "subnets": [ - { - "properties": { - "addressPrefix": "[variables('subnetAddressPrefix')]" - }, - "name": "[variables('subnetName')]" - } - ] - } - }, - { - "apiVersion": "[variables('apiVersion')]", - "name": "[variables('nicName')]", - "type": "Microsoft.Network/networkInterfaces", - "location": "[variables('location')]", - "dependsOn": [ - "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", - "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" - ], - "properties": { - "ipConfigurations": [ - { - "properties": { - "privateIPAllocationMethod": "Dynamic", - "subnet": { - "id": "[variables('subnetRef')]" - }, - "publicIPAddress": { - "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" - } - }, - "name": "ipconfig" - } - ] - } - }, - { - "apiVersion": "[variables('apiVersion')]", - "name": "[parameters('vmName')]", - "type": "Microsoft.Compute/virtualMachines", - "location": "[variables('location')]", - "dependsOn": [ - "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" - ], - "properties": { - "diagnosticsProfile": { - "bootDiagnostics": { - "enabled": false - } - }, - "hardwareProfile": { - "vmSize": "[parameters('vmSize')]" - }, - "networkProfile": { - "networkInterfaces": [ - { - "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" - } - ] - }, - "osProfile": { - "computerName": "[parameters('vmName')]", - "adminUsername": "[parameters('adminUsername')]", - "adminPassword": "[parameters('adminPassword')]", - "linuxConfiguration": { - "ssh": { - "publicKeys": [ - { - "path": "[variables('sshKeyPath')]", - "keyData": "--test-ssh-authorized-key--" - } - ] - } - } - }, - "storageProfile": { - "osDisk": { - "osType": "Linux", - "name": "osdisk", - "vhd": { - "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" - }, - "image": { - "uri": "http://azure/custom.vhd" - }, - "caching": "ReadWrite", - "createOption": "FromImage" - } - } - } - } - ] +{ + "$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": "--test-ssh-authorized-key--", + "path": "[variables('sshKeyPath')]" + } + ] + } + } + }, + "storageProfile": { + "osDisk": { + "caching": "ReadWrite", + "createOption": "FromImage", + "image": { + "uri": "http://azure/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'))]" + } } \ No newline at end of file diff --git a/builder/azure/common/template/TestBuildWindows00.approved.txt b/builder/azure/common/template/template_builder_test.TestBuildWindows00.approved.json similarity index 87% rename from builder/azure/common/template/TestBuildWindows00.approved.txt rename to builder/azure/common/template/template_builder_test.TestBuildWindows00.approved.json index 6217322fa..d2460d7b4 100644 --- a/builder/azure/common/template/TestBuildWindows00.approved.txt +++ b/builder/azure/common/template/template_builder_test.TestBuildWindows00.approved.json @@ -1,174 +1,174 @@ -{ - "$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" - } - }, - "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": [ - { - "apiVersion": "[variables('apiVersion')]", - "name": "[variables('publicIPAddressName')]", - "type": "Microsoft.Network/publicIPAddresses", - "location": "[variables('location')]", - "properties": { - "dnsSettings": { - "domainNameLabel": "[parameters('dnsNameForPublicIP')]" - }, - "publicIPAllocationMethod": "[variables('publicIPAddressType')]" - } - }, - { - "apiVersion": "[variables('apiVersion')]", - "name": "[variables('virtualNetworkName')]", - "type": "Microsoft.Network/virtualNetworks", - "location": "[variables('location')]", - "properties": { - "addressSpace": { - "addressPrefixes": [ - "[variables('addressPrefix')]" - ] - }, - "subnets": [ - { - "properties": { - "addressPrefix": "[variables('subnetAddressPrefix')]" - }, - "name": "[variables('subnetName')]" - } - ] - } - }, - { - "apiVersion": "[variables('apiVersion')]", - "name": "[variables('nicName')]", - "type": "Microsoft.Network/networkInterfaces", - "location": "[variables('location')]", - "dependsOn": [ - "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", - "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" - ], - "properties": { - "ipConfigurations": [ - { - "properties": { - "privateIPAllocationMethod": "Dynamic", - "subnet": { - "id": "[variables('subnetRef')]" - }, - "publicIPAddress": { - "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" - } - }, - "name": "ipconfig" - } - ] - } - }, - { - "apiVersion": "[variables('apiVersion')]", - "name": "[parameters('vmName')]", - "type": "Microsoft.Compute/virtualMachines", - "location": "[variables('location')]", - "dependsOn": [ - "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" - ], - "properties": { - "diagnosticsProfile": { - "bootDiagnostics": { - "enabled": false - } - }, - "hardwareProfile": { - "vmSize": "[parameters('vmSize')]" - }, - "networkProfile": { - "networkInterfaces": [ - { - "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" - } - ] - }, - "osProfile": { - "computerName": "[parameters('vmName')]", - "adminUsername": "[parameters('adminUsername')]", - "adminPassword": "[parameters('adminPassword')]", - "windowsConfiguration": { - "provisionVMAgent": true, - "winRM": { - "listeners": [ - { - "protocol": "https", - "certificateUrl": "--test-winrm-certificate-url--" - } - ] - } - }, - "secrets": [ - { - "sourceVault": { - "id": "[resourceId(resourceGroup().name, 'Microsoft.KeyVault/vaults', '--test-key-vault-name')]" - }, - "vaultCertificates": [ - { - "certificateUrl": "--test-winrm-certificate-url--", - "certificateStore": "My" - } - ] - } - ] - }, - "storageProfile": { - "imageReference": { - "publisher": "MicrosoftWindowsServer", - "offer": "WindowsServer", - "sku": "2012-R2-Datacenter", - "version": "latest" - }, - "osDisk": { - "name": "osdisk", - "vhd": { - "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" - }, - "caching": "ReadWrite", - "createOption": "FromImage" - } - } - } - } - ] +{ + "$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')]", + "secrets": [ + { + "sourceVault": { + "id": "[resourceId(resourceGroup().name, 'Microsoft.KeyVault/vaults', '--test-key-vault-name')]" + }, + "vaultCertificates": [ + { + "certificateStore": "My", + "certificateUrl": "--test-winrm-certificate-url--" + } + ] + } + ], + "windowsConfiguration": { + "provisionVMAgent": true, + "winRM": { + "listeners": [ + { + "certificateUrl": "--test-winrm-certificate-url--", + "protocol": "https" + } + ] + } + } + }, + "storageProfile": { + "imageReference": { + "offer": "WindowsServer", + "publisher": "MicrosoftWindowsServer", + "sku": "2012-R2-Datacenter", + "version": "latest" + }, + "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'))]" + } } \ No newline at end of file diff --git a/builder/azure/common/template/template_builder_test.go b/builder/azure/common/template/template_builder_test.go index d6775d120..f203acace 100644 --- a/builder/azure/common/template/template_builder_test.go +++ b/builder/azure/common/template/template_builder_test.go @@ -1,11 +1,10 @@ package template import ( - "strings" "testing" "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. @@ -31,9 +30,7 @@ func TestBuildLinux00(t *testing.T) { t.Fatal(err) } - reader := strings.NewReader(*doc) - - err = approvals.Verify(t, reader) + err = approvaltests.VerifyJSONBytes(t, []byte(*doc)) if err != nil { t.Fatal(err) } @@ -61,9 +58,7 @@ func TestBuildLinux01(t *testing.T) { t.Fatal(err) } - reader := strings.NewReader(*doc) - - err = approvals.Verify(t, reader) + err = approvaltests.VerifyJSONBytes(t, []byte(*doc)) if err != nil { t.Fatal(err) } @@ -93,9 +88,7 @@ func TestBuildWindows00(t *testing.T) { t.Fatal(err) } - reader := strings.NewReader(*doc) - - err = approvals.Verify(t, reader) + err = approvaltests.VerifyJSONBytes(t, []byte(*doc)) if err != nil { t.Fatal(err) }