provider/azure: acc tests fixes
* avoid name collisions * update image names
This commit is contained in:
parent
f6e525e531
commit
3fbeb326cd
|
@ -3,9 +3,11 @@ package azure
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
@ -193,6 +195,10 @@ func TestAzure_isFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func genRandInt() int {
|
||||||
|
return rand.New(rand.NewSource(time.Now().UnixNano())).Int() % 100000
|
||||||
|
}
|
||||||
|
|
||||||
// testAzurePublishSettingsStr is a revoked publishsettings file
|
// testAzurePublishSettingsStr is a revoked publishsettings file
|
||||||
const testAzurePublishSettingsStr = `
|
const testAzurePublishSettingsStr = `
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
func TestAccAzureDataDisk_basic(t *testing.T) {
|
func TestAccAzureDataDisk_basic(t *testing.T) {
|
||||||
var disk virtualmachinedisk.DataDiskResponse
|
var disk virtualmachinedisk.DataDiskResponse
|
||||||
|
name := fmt.Sprintf("terraform-test%d", genRandInt())
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -20,13 +21,13 @@ func TestAccAzureDataDisk_basic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckAzureDataDiskDestroy,
|
CheckDestroy: testAccCheckAzureDataDiskDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAzureDataDisk_basic,
|
Config: testAccAzureDataDisk_basic(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAzureDataDiskExists(
|
testAccCheckAzureDataDiskExists(
|
||||||
"azure_data_disk.foo", &disk),
|
"azure_data_disk.foo", &disk),
|
||||||
testAccCheckAzureDataDiskAttributes(&disk),
|
testAccCheckAzureDataDiskAttributes(&disk),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"azure_data_disk.foo", "label", "terraform-test-0"),
|
"azure_data_disk.foo", "label", fmt.Sprintf("%s-0", name)),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"azure_data_disk.foo", "size", "10"),
|
"azure_data_disk.foo", "size", "10"),
|
||||||
),
|
),
|
||||||
|
@ -37,6 +38,7 @@ func TestAccAzureDataDisk_basic(t *testing.T) {
|
||||||
|
|
||||||
func TestAccAzureDataDisk_update(t *testing.T) {
|
func TestAccAzureDataDisk_update(t *testing.T) {
|
||||||
var disk virtualmachinedisk.DataDiskResponse
|
var disk virtualmachinedisk.DataDiskResponse
|
||||||
|
name := fmt.Sprintf("terraform-test%d", genRandInt())
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -44,12 +46,12 @@ func TestAccAzureDataDisk_update(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckAzureDataDiskDestroy,
|
CheckDestroy: testAccCheckAzureDataDiskDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAzureDataDisk_advanced,
|
Config: testAccAzureDataDisk_advanced(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAzureDataDiskExists(
|
testAccCheckAzureDataDiskExists(
|
||||||
"azure_data_disk.foo", &disk),
|
"azure_data_disk.foo", &disk),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"azure_data_disk.foo", "label", "terraform-test1-1"),
|
"azure_data_disk.foo", "label", fmt.Sprintf("%s-1", name)),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"azure_data_disk.foo", "lun", "1"),
|
"azure_data_disk.foo", "lun", "1"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -57,17 +59,17 @@ func TestAccAzureDataDisk_update(t *testing.T) {
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"azure_data_disk.foo", "caching", "ReadOnly"),
|
"azure_data_disk.foo", "caching", "ReadOnly"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"azure_data_disk.foo", "virtual_machine", "terraform-test1"),
|
"azure_data_disk.foo", "virtual_machine", name),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAzureDataDisk_update,
|
Config: testAccAzureDataDisk_update(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAzureDataDiskExists(
|
testAccCheckAzureDataDiskExists(
|
||||||
"azure_data_disk.foo", &disk),
|
"azure_data_disk.foo", &disk),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"azure_data_disk.foo", "label", "terraform-test1-1"),
|
"azure_data_disk.foo", "label", fmt.Sprintf("%s-1", name)),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"azure_data_disk.foo", "lun", "2"),
|
"azure_data_disk.foo", "lun", "2"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -168,55 +170,60 @@ func testAccCheckAzureDataDiskDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccAzureDataDisk_basic = fmt.Sprintf(`
|
func testAccAzureDataDisk_basic(name string) string {
|
||||||
resource "azure_instance" "foo" {
|
return fmt.Sprintf(`
|
||||||
name = "terraform-test"
|
resource "azure_instance" "foo" {
|
||||||
|
name = "%s"
|
||||||
image = "Ubuntu Server 14.04 LTS"
|
image = "Ubuntu Server 14.04 LTS"
|
||||||
size = "Basic_A1"
|
size = "Basic_A1"
|
||||||
storage_service_name = "%s"
|
storage_service_name = "%s"
|
||||||
location = "West US"
|
location = "West US"
|
||||||
username = "terraform"
|
username = "terraform"
|
||||||
password = "Pass!admin123"
|
password = "Pass!admin123"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azure_data_disk" "foo" {
|
resource "azure_data_disk" "foo" {
|
||||||
lun = 0
|
lun = 0
|
||||||
size = 10
|
size = 10
|
||||||
storage_service_name = "${azure_instance.foo.storage_service_name}"
|
storage_service_name = "${azure_instance.foo.storage_service_name}"
|
||||||
virtual_machine = "${azure_instance.foo.id}"
|
virtual_machine = "${azure_instance.foo.id}"
|
||||||
}`, testAccStorageServiceName)
|
}`, name, testAccStorageServiceName)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAzureDataDisk_advanced = fmt.Sprintf(`
|
func testAccAzureDataDisk_advanced(name string) string {
|
||||||
resource "azure_instance" "foo" {
|
return fmt.Sprintf(`
|
||||||
name = "terraform-test1"
|
resource "azure_instance" "foo" {
|
||||||
|
name = "%s"
|
||||||
image = "Ubuntu Server 14.04 LTS"
|
image = "Ubuntu Server 14.04 LTS"
|
||||||
size = "Basic_A1"
|
size = "Basic_A1"
|
||||||
storage_service_name = "%s"
|
storage_service_name = "%s"
|
||||||
location = "West US"
|
location = "West US"
|
||||||
username = "terraform"
|
username = "terraform"
|
||||||
password = "Pass!admin123"
|
password = "Pass!admin123"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azure_data_disk" "foo" {
|
resource "azure_data_disk" "foo" {
|
||||||
lun = 1
|
lun = 1
|
||||||
size = 10
|
size = 10
|
||||||
caching = "ReadOnly"
|
caching = "ReadOnly"
|
||||||
storage_service_name = "${azure_instance.foo.storage_service_name}"
|
storage_service_name = "${azure_instance.foo.storage_service_name}"
|
||||||
virtual_machine = "${azure_instance.foo.id}"
|
virtual_machine = "${azure_instance.foo.id}"
|
||||||
}`, testAccStorageServiceName)
|
}`, name, testAccStorageServiceName)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAzureDataDisk_update = fmt.Sprintf(`
|
func testAccAzureDataDisk_update(name string) string {
|
||||||
resource "azure_instance" "foo" {
|
return fmt.Sprintf(`
|
||||||
name = "terraform-test1"
|
resource "azure_instance" "foo" {
|
||||||
|
name = "%s"
|
||||||
image = "Ubuntu Server 14.04 LTS"
|
image = "Ubuntu Server 14.04 LTS"
|
||||||
size = "Basic_A1"
|
size = "Basic_A1"
|
||||||
storage_service_name = "%s"
|
storage_service_name = "%s"
|
||||||
location = "West US"
|
location = "West US"
|
||||||
username = "terraform"
|
username = "terraform"
|
||||||
password = "Pass!admin123"
|
password = "Pass!admin123"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azure_instance" "bar" {
|
resource "azure_instance" "bar" {
|
||||||
name = "terraform-test2"
|
name = "terraform-test2"
|
||||||
image = "Ubuntu Server 14.04 LTS"
|
image = "Ubuntu Server 14.04 LTS"
|
||||||
size = "Basic_A1"
|
size = "Basic_A1"
|
||||||
|
@ -224,12 +231,13 @@ resource "azure_instance" "bar" {
|
||||||
location = "West US"
|
location = "West US"
|
||||||
username = "terraform"
|
username = "terraform"
|
||||||
password = "Pass!admin123"
|
password = "Pass!admin123"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azure_data_disk" "foo" {
|
resource "azure_data_disk" "foo" {
|
||||||
lun = 2
|
lun = 2
|
||||||
size = 20
|
size = 20
|
||||||
caching = "ReadWrite"
|
caching = "ReadWrite"
|
||||||
storage_service_name = "${azure_instance.bar.storage_service_name}"
|
storage_service_name = "${azure_instance.bar.storage_service_name}"
|
||||||
virtual_machine = "${azure_instance.bar.id}"
|
virtual_machine = "${azure_instance.bar.id}"
|
||||||
}`, testAccStorageServiceName)
|
}`, name, testAccStorageServiceName)
|
||||||
|
}
|
||||||
|
|
|
@ -446,7 +446,7 @@ resource "azure_security_group_rule" "foo" {
|
||||||
|
|
||||||
resource "azure_instance" "foo" {
|
resource "azure_instance" "foo" {
|
||||||
name = "terraform-test1"
|
name = "terraform-test1"
|
||||||
image = "Windows Server 2012 R2 Datacenter, April 2015"
|
image = "Windows Server 2012 R2 Datacenter, September 2015"
|
||||||
size = "Basic_A1"
|
size = "Basic_A1"
|
||||||
storage_service_name = "%s"
|
storage_service_name = "%s"
|
||||||
location = "West US"
|
location = "West US"
|
||||||
|
@ -520,7 +520,7 @@ resource "azure_security_group_rule" "bar" {
|
||||||
|
|
||||||
resource "azure_instance" "foo" {
|
resource "azure_instance" "foo" {
|
||||||
name = "terraform-test1"
|
name = "terraform-test1"
|
||||||
image = "Windows Server 2012 R2 Datacenter, April 2015"
|
image = "Windows Server 2012 R2 Datacenter, September 2015"
|
||||||
size = "Basic_A2"
|
size = "Basic_A2"
|
||||||
storage_service_name = "%s"
|
storage_service_name = "%s"
|
||||||
location = "West US"
|
location = "West US"
|
||||||
|
|
Loading…
Reference in New Issue