2018-04-19 03:21:59 -04:00
|
|
|
package arm
|
|
|
|
|
|
|
|
// these tests require the following variables to be set,
|
|
|
|
// although some test will only use a subset:
|
|
|
|
//
|
|
|
|
// * ARM_CLIENT_ID
|
|
|
|
// * ARM_CLIENT_SECRET
|
|
|
|
// * ARM_SUBSCRIPTION_ID
|
|
|
|
// * ARM_STORAGE_ACCOUNT
|
|
|
|
//
|
|
|
|
// The subscription in question should have a resource group
|
2018-05-18 15:09:42 -04:00
|
|
|
// called "packer-acceptance-test" in "South Central US" region. The
|
2019-07-25 00:49:51 -04:00
|
|
|
// storage account referred to in the above variable should
|
2018-05-18 04:34:12 -04:00
|
|
|
// be inside this resource group and in "South Central US" as well.
|
2018-04-19 03:21:59 -04:00
|
|
|
//
|
|
|
|
// In addition, the PACKER_ACC variable should also be set to
|
|
|
|
// a non-empty value to enable Packer acceptance tests and the
|
2018-05-03 20:32:15 -04:00
|
|
|
// options "-v -timeout 90m" should be provided to the test
|
2018-04-19 03:21:59 -04:00
|
|
|
// command, e.g.:
|
2018-05-03 20:28:34 -04:00
|
|
|
// go test -v -timeout 90m -run TestBuilderAcc_.*
|
2018-04-19 03:21:59 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-05-18 04:41:00 -04:00
|
|
|
"fmt"
|
2018-05-18 04:25:19 -04:00
|
|
|
"os"
|
2019-03-22 09:53:28 -04:00
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
builderT "github.com/hashicorp/packer-plugin-sdk/acctest"
|
2018-04-19 03:21:59 -04:00
|
|
|
)
|
|
|
|
|
2018-05-18 04:25:19 -04:00
|
|
|
const DeviceLoginAcceptanceTest = "DEVICELOGIN_TEST"
|
|
|
|
|
2018-04-19 03:21:59 -04:00
|
|
|
func TestBuilderAcc_ManagedDisk_Windows(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: testBuilderAccManagedDiskWindows,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-06-06 18:25:19 -04:00
|
|
|
func TestBuilderAcc_ManagedDisk_Windows_Build_Resource_Group(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: testBuilderAccManagedDiskWindowsBuildResourceGroup,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-10-23 13:17:05 -04:00
|
|
|
func TestBuilderAcc_ManagedDisk_Windows_Build_Resource_Group_Additional_Disk(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: testBuilderAccManagedDiskWindowsBuildResourceGroupAdditionalDisk,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-18 03:32:01 -04:00
|
|
|
func TestBuilderAcc_ManagedDisk_Windows_DeviceLogin(t *testing.T) {
|
2018-05-18 04:25:19 -04:00
|
|
|
if os.Getenv(DeviceLoginAcceptanceTest) == "" {
|
|
|
|
t.Skip(fmt.Sprintf(
|
|
|
|
"Device Login Acceptance tests skipped unless env '%s' set, as its requires manual step during execution",
|
|
|
|
DeviceLoginAcceptanceTest))
|
|
|
|
return
|
|
|
|
}
|
2018-05-18 03:32:01 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: testBuilderAccManagedDiskWindowsDeviceLogin,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-19 03:21:59 -04:00
|
|
|
func TestBuilderAcc_ManagedDisk_Linux(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: testBuilderAccManagedDiskLinux,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-18 04:25:19 -04:00
|
|
|
func TestBuilderAcc_ManagedDisk_Linux_DeviceLogin(t *testing.T) {
|
|
|
|
if os.Getenv(DeviceLoginAcceptanceTest) == "" {
|
|
|
|
t.Skip(fmt.Sprintf(
|
|
|
|
"Device Login Acceptance tests skipped unless env '%s' set, as its requires manual step during execution",
|
|
|
|
DeviceLoginAcceptanceTest))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: testBuilderAccManagedDiskLinuxDeviceLogin,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-06 14:24:16 -05:00
|
|
|
func TestBuilderAcc_ManagedDisk_Linux_AzureCLI(t *testing.T) {
|
|
|
|
if os.Getenv("AZURE_CLI_AUTH") == "" {
|
|
|
|
t.Skip("Azure CLI Acceptance tests skipped unless env 'AZURE_CLI_AUTH' is set, and an active `az login` session has been established")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: testBuilderAccManagedDiskLinuxAzureCLI,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-19 03:21:59 -04:00
|
|
|
func TestBuilderAcc_Blob_Windows(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: testBuilderAccBlobWindows,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilderAcc_Blob_Linux(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: testBuilderAccBlobLinux,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccPreCheck(*testing.T) {}
|
|
|
|
|
|
|
|
const testBuilderAccManagedDiskWindows = `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
|
|
|
|
"client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
|
2018-05-18 03:32:01 -04:00
|
|
|
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
|
2018-04-19 03:21:59 -04:00
|
|
|
},
|
|
|
|
"builders": [{
|
|
|
|
"type": "test",
|
|
|
|
|
|
|
|
"client_id": "{{user ` + "`client_id`" + `}}",
|
|
|
|
"client_secret": "{{user ` + "`client_secret`" + `}}",
|
|
|
|
"subscription_id": "{{user ` + "`subscription_id`" + `}}",
|
|
|
|
|
|
|
|
"managed_image_resource_group_name": "packer-acceptance-test",
|
|
|
|
"managed_image_name": "testBuilderAccManagedDiskWindows-{{timestamp}}",
|
|
|
|
|
|
|
|
"os_type": "Windows",
|
|
|
|
"image_publisher": "MicrosoftWindowsServer",
|
|
|
|
"image_offer": "WindowsServer",
|
|
|
|
"image_sku": "2012-R2-Datacenter",
|
|
|
|
|
|
|
|
"communicator": "winrm",
|
|
|
|
"winrm_use_ssl": "true",
|
|
|
|
"winrm_insecure": "true",
|
|
|
|
"winrm_timeout": "3m",
|
|
|
|
"winrm_username": "packer",
|
2018-05-19 00:17:19 -04:00
|
|
|
"async_resourcegroup_delete": "true",
|
2018-05-18 03:32:01 -04:00
|
|
|
|
|
|
|
"location": "South Central US",
|
|
|
|
"vm_size": "Standard_DS2_v2"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
2018-06-06 18:25:19 -04:00
|
|
|
const testBuilderAccManagedDiskWindowsBuildResourceGroup = `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
|
|
|
|
"client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
|
|
|
|
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
|
|
|
|
},
|
|
|
|
"builders": [{
|
|
|
|
"type": "test",
|
|
|
|
|
|
|
|
"client_id": "{{user ` + "`client_id`" + `}}",
|
|
|
|
"client_secret": "{{user ` + "`client_secret`" + `}}",
|
|
|
|
"subscription_id": "{{user ` + "`subscription_id`" + `}}",
|
|
|
|
|
|
|
|
"build_resource_group_name" : "packer-acceptance-test",
|
|
|
|
"managed_image_resource_group_name": "packer-acceptance-test",
|
2020-10-21 05:12:50 -04:00
|
|
|
"managed_image_name": "testBuilderAccManagedDiskWindowsBuildResourceGroup-{{timestamp}}",
|
2018-06-06 18:25:19 -04:00
|
|
|
|
|
|
|
"os_type": "Windows",
|
|
|
|
"image_publisher": "MicrosoftWindowsServer",
|
|
|
|
"image_offer": "WindowsServer",
|
|
|
|
"image_sku": "2012-R2-Datacenter",
|
|
|
|
|
|
|
|
"communicator": "winrm",
|
|
|
|
"winrm_use_ssl": "true",
|
|
|
|
"winrm_insecure": "true",
|
|
|
|
"winrm_timeout": "3m",
|
|
|
|
"winrm_username": "packer",
|
|
|
|
"async_resourcegroup_delete": "true",
|
|
|
|
|
|
|
|
"vm_size": "Standard_DS2_v2"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
2018-05-18 03:32:01 -04:00
|
|
|
|
2020-10-23 13:17:05 -04:00
|
|
|
const testBuilderAccManagedDiskWindowsBuildResourceGroupAdditionalDisk = `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
|
|
|
|
"client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
|
|
|
|
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
|
|
|
|
},
|
|
|
|
"builders": [{
|
|
|
|
"type": "test",
|
|
|
|
|
|
|
|
"client_id": "{{user ` + "`client_id`" + `}}",
|
|
|
|
"client_secret": "{{user ` + "`client_secret`" + `}}",
|
|
|
|
"subscription_id": "{{user ` + "`subscription_id`" + `}}",
|
|
|
|
|
|
|
|
"build_resource_group_name" : "packer-acceptance-test",
|
|
|
|
"managed_image_resource_group_name": "packer-acceptance-test",
|
|
|
|
"managed_image_name": "testBuilderAccManagedDiskWindowsBuildResourceGroupAdditionDisk-{{timestamp}}",
|
|
|
|
|
|
|
|
"os_type": "Windows",
|
|
|
|
"image_publisher": "MicrosoftWindowsServer",
|
|
|
|
"image_offer": "WindowsServer",
|
|
|
|
"image_sku": "2012-R2-Datacenter",
|
|
|
|
|
|
|
|
"communicator": "winrm",
|
|
|
|
"winrm_use_ssl": "true",
|
|
|
|
"winrm_insecure": "true",
|
|
|
|
"winrm_timeout": "3m",
|
|
|
|
"winrm_username": "packer",
|
|
|
|
"async_resourcegroup_delete": "true",
|
|
|
|
|
|
|
|
"vm_size": "Standard_DS2_v2",
|
|
|
|
"disk_additional_size": [10,15]
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2018-05-18 03:32:01 -04:00
|
|
|
const testBuilderAccManagedDiskWindowsDeviceLogin = `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
|
|
|
|
},
|
|
|
|
"builders": [{
|
|
|
|
"type": "test",
|
|
|
|
|
|
|
|
"subscription_id": "{{user ` + "`subscription_id`" + `}}",
|
|
|
|
|
|
|
|
"managed_image_resource_group_name": "packer-acceptance-test",
|
|
|
|
"managed_image_name": "testBuilderAccManagedDiskWindowsDeviceLogin-{{timestamp}}",
|
|
|
|
|
|
|
|
"os_type": "Windows",
|
|
|
|
"image_publisher": "MicrosoftWindowsServer",
|
|
|
|
"image_offer": "WindowsServer",
|
|
|
|
"image_sku": "2012-R2-Datacenter",
|
|
|
|
|
|
|
|
"communicator": "winrm",
|
|
|
|
"winrm_use_ssl": "true",
|
|
|
|
"winrm_insecure": "true",
|
|
|
|
"winrm_timeout": "3m",
|
|
|
|
"winrm_username": "packer",
|
2018-04-19 03:21:59 -04:00
|
|
|
|
2018-05-18 03:32:01 -04:00
|
|
|
"location": "South Central US",
|
2018-04-19 03:21:59 -04:00
|
|
|
"vm_size": "Standard_DS2_v2"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testBuilderAccManagedDiskLinux = `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
|
|
|
|
"client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
|
|
|
|
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
|
|
|
|
},
|
|
|
|
"builders": [{
|
|
|
|
"type": "test",
|
|
|
|
|
|
|
|
"client_id": "{{user ` + "`client_id`" + `}}",
|
|
|
|
"client_secret": "{{user ` + "`client_secret`" + `}}",
|
|
|
|
"subscription_id": "{{user ` + "`subscription_id`" + `}}",
|
|
|
|
|
|
|
|
"managed_image_resource_group_name": "packer-acceptance-test",
|
|
|
|
"managed_image_name": "testBuilderAccManagedDiskLinux-{{timestamp}}",
|
|
|
|
|
|
|
|
"os_type": "Linux",
|
|
|
|
"image_publisher": "Canonical",
|
|
|
|
"image_offer": "UbuntuServer",
|
|
|
|
"image_sku": "16.04-LTS",
|
|
|
|
|
2018-05-18 03:32:01 -04:00
|
|
|
"location": "South Central US",
|
2020-09-30 09:55:46 -04:00
|
|
|
"vm_size": "Standard_DS2_v2",
|
|
|
|
"azure_tags": {
|
|
|
|
"env": "testing",
|
|
|
|
"builder": "packer"
|
|
|
|
}
|
2018-04-19 03:21:59 -04:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
2018-05-18 04:25:19 -04:00
|
|
|
const testBuilderAccManagedDiskLinuxDeviceLogin = `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
|
|
|
|
},
|
|
|
|
"builders": [{
|
|
|
|
"type": "test",
|
|
|
|
|
|
|
|
"subscription_id": "{{user ` + "`subscription_id`" + `}}",
|
|
|
|
|
|
|
|
"managed_image_resource_group_name": "packer-acceptance-test",
|
|
|
|
"managed_image_name": "testBuilderAccManagedDiskLinuxDeviceLogin-{{timestamp}}",
|
|
|
|
|
|
|
|
"os_type": "Linux",
|
|
|
|
"image_publisher": "Canonical",
|
|
|
|
"image_offer": "UbuntuServer",
|
|
|
|
"image_sku": "16.04-LTS",
|
2018-05-19 00:17:19 -04:00
|
|
|
"async_resourcegroup_delete": "true",
|
2018-05-18 04:25:19 -04:00
|
|
|
|
|
|
|
"location": "South Central US",
|
|
|
|
"vm_size": "Standard_DS2_v2"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
2018-04-19 03:21:59 -04:00
|
|
|
|
|
|
|
const testBuilderAccBlobWindows = `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
|
|
|
|
"client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
|
|
|
|
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}",
|
|
|
|
"storage_account": "{{env ` + "`ARM_STORAGE_ACCOUNT`" + `}}"
|
|
|
|
},
|
|
|
|
"builders": [{
|
|
|
|
"type": "test",
|
|
|
|
|
|
|
|
"client_id": "{{user ` + "`client_id`" + `}}",
|
|
|
|
"client_secret": "{{user ` + "`client_secret`" + `}}",
|
|
|
|
"subscription_id": "{{user ` + "`subscription_id`" + `}}",
|
|
|
|
|
|
|
|
"storage_account": "{{user ` + "`storage_account`" + `}}",
|
|
|
|
"resource_group_name": "packer-acceptance-test",
|
|
|
|
"capture_container_name": "test",
|
|
|
|
"capture_name_prefix": "testBuilderAccBlobWin",
|
|
|
|
|
|
|
|
"os_type": "Windows",
|
|
|
|
"image_publisher": "MicrosoftWindowsServer",
|
|
|
|
"image_offer": "WindowsServer",
|
|
|
|
"image_sku": "2012-R2-Datacenter",
|
|
|
|
|
|
|
|
"communicator": "winrm",
|
|
|
|
"winrm_use_ssl": "true",
|
|
|
|
"winrm_insecure": "true",
|
|
|
|
"winrm_timeout": "3m",
|
|
|
|
"winrm_username": "packer",
|
|
|
|
|
2018-05-18 03:32:01 -04:00
|
|
|
"location": "South Central US",
|
2018-04-19 03:21:59 -04:00
|
|
|
"vm_size": "Standard_DS2_v2"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testBuilderAccBlobLinux = `
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
|
|
|
|
"client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
|
|
|
|
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}",
|
|
|
|
"storage_account": "{{env ` + "`ARM_STORAGE_ACCOUNT`" + `}}"
|
|
|
|
},
|
|
|
|
"builders": [{
|
|
|
|
"type": "test",
|
|
|
|
|
|
|
|
"client_id": "{{user ` + "`client_id`" + `}}",
|
|
|
|
"client_secret": "{{user ` + "`client_secret`" + `}}",
|
|
|
|
"subscription_id": "{{user ` + "`subscription_id`" + `}}",
|
|
|
|
|
|
|
|
"storage_account": "{{user ` + "`storage_account`" + `}}",
|
|
|
|
"resource_group_name": "packer-acceptance-test",
|
|
|
|
"capture_container_name": "test",
|
|
|
|
"capture_name_prefix": "testBuilderAccBlobLinux",
|
|
|
|
|
|
|
|
"os_type": "Linux",
|
|
|
|
"image_publisher": "Canonical",
|
|
|
|
"image_offer": "UbuntuServer",
|
|
|
|
"image_sku": "16.04-LTS",
|
|
|
|
|
2018-05-18 03:32:01 -04:00
|
|
|
"location": "South Central US",
|
2018-04-19 03:21:59 -04:00
|
|
|
"vm_size": "Standard_DS2_v2"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|
2020-11-06 14:24:16 -05:00
|
|
|
const testBuilderAccManagedDiskLinuxAzureCLI = `
|
|
|
|
{
|
|
|
|
"builders": [{
|
|
|
|
"type": "test",
|
|
|
|
|
|
|
|
"use_azure_cli_auth": true,
|
|
|
|
|
|
|
|
"managed_image_resource_group_name": "packer-acceptance-test",
|
|
|
|
"managed_image_name": "testBuilderAccManagedDiskLinuxAzureCLI-{{timestamp}}",
|
|
|
|
|
|
|
|
"os_type": "Linux",
|
|
|
|
"image_publisher": "Canonical",
|
|
|
|
"image_offer": "UbuntuServer",
|
|
|
|
"image_sku": "16.04-LTS",
|
|
|
|
|
|
|
|
"location": "South Central US",
|
|
|
|
"vm_size": "Standard_DS2_v2",
|
|
|
|
"azure_tags": {
|
|
|
|
"env": "testing",
|
|
|
|
"builder": "packer"
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
`
|