Changes to behaviour of string enum comparison in AzureRM provider (#14861)

* Fix for CDN Profile SKU

* Fix for event hub namespace

* Fix for managed disk

* Fix for redis cache, servicebus namespace and storage account.

* Fix for virtual machine scale set
This commit is contained in:
Abhijeet Gaiha 2017-06-01 17:16:36 +05:30 committed by Paul Stack
parent ea48d71c0f
commit 6e995323a4
14 changed files with 394 additions and 24 deletions

View File

@ -37,10 +37,11 @@ func resourceArmCdnProfile() *schema.Resource {
},
"sku": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateCdnProfileSku,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateCdnProfileSku,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"tags": tagsSchema(),

View File

@ -108,6 +108,32 @@ func TestAccAzureRMCdnProfile_withTags(t *testing.T) {
})
}
func TestAccAzureRMCdnProfile_NonStandardCasing(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMCdnProfileNonStandardCasing(ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMCdnProfileDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCdnProfileExists("azurerm_cdn_profile.test"),
),
},
resource.TestStep{
Config: config,
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}
func testCheckAzureRMCdnProfileExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
@ -209,3 +235,18 @@ resource "azurerm_cdn_profile" "test" {
}
}
`
func testAccAzureRMCdnProfileNonStandardCasing(ri int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US"
}
resource "azurerm_cdn_profile" "test" {
name = "acctestcdnprof%d"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "standard_verizon"
}
`, ri, ri)
}

View File

@ -41,9 +41,10 @@ func resourceArmEventHubNamespace() *schema.Resource {
},
"sku": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateEventHubNamespaceSku,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateEventHubNamespaceSku,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"capacity": {

View File

@ -146,6 +146,31 @@ func TestAccAzureRMEventHubNamespace_readDefaultKeys(t *testing.T) {
})
}
func TestAccAzureRMEventHubNamespace_NonStandardCasing(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMEventHubNamespaceNonStandardCasing(ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubNamespaceExists("azurerm_eventhub_namespace.test"),
),
},
resource.TestStep{
Config: config,
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}
func testCheckAzureRMEventHubNamespaceDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).eventHubNamespacesClient
@ -226,3 +251,18 @@ resource "azurerm_eventhub_namespace" "test" {
capacity = "2"
}
`
func testAccAzureRMEventHubNamespaceNonStandardCasing(ri int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US"
}
resource "azurerm_eventhub_namespace" "test" {
name = "acctesteventhubnamespace-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "basic"
}
`, ri, ri)
}

View File

@ -43,6 +43,7 @@ func resourceArmManagedDisk() *schema.Resource {
string(disk.PremiumLRS),
string(disk.StandardLRS),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"create_option": {

View File

@ -126,6 +126,30 @@ func TestAccAzureRMManagedDisk_update(t *testing.T) {
})
}
func TestAccAzureRMManagedDisk_NonStandardCasing(t *testing.T) {
var d disk.Model
ri := acctest.RandInt()
config := testAccAzureRMManagedDiskNonStandardCasing(ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true),
),
},
resource.TestStep{
Config: config,
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}
func testCheckAzureRMManagedDiskExists(name string, d *disk.Model, shouldExist bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
@ -320,3 +344,23 @@ resource "azurerm_managed_disk" "test" {
environment = "acctest"
}
}`
func testAccAzureRMManagedDiskNonStandardCasing(ri int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US 2"
}
resource "azurerm_managed_disk" "test" {
name = "acctestd-%d"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_type = "standard_lrs"
create_option = "Empty"
disk_size_gb = "1"
tags {
environment = "acctest"
cost-center = "ops"
}
}`, ri, ri)
}

View File

@ -47,15 +47,17 @@ func resourceArmRedisCache() *schema.Resource {
},
"family": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateRedisFamily,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateRedisFamily,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"sku_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateRedisSku,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateRedisSku,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"shard_count": {

View File

@ -185,6 +185,31 @@ func TestAccAzureRMRedisCache_premiumSharded(t *testing.T) {
})
}
func TestAccAzureRMRedisCache_NonStandardCasing(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMRedisCacheNonStandardCasing(ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMRedisCacheDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRedisCacheExists("azurerm_redis_cache.test"),
),
},
resource.TestStep{
Config: config,
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}
func testCheckAzureRMRedisCacheExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
@ -330,3 +355,24 @@ resource "azurerm_redis_cache" "test" {
}
}
`
func testAccAzureRMRedisCacheNonStandardCasing(ri int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US"
}
resource "azurerm_redis_cache" "test" {
name = "acctestRedis-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
capacity = 1
family = "c"
sku_name = "basic"
enable_non_ssl_port = false
redis_configuration {
maxclients = "256"
}
}
`, ri, ri)
}

View File

@ -40,10 +40,11 @@ func resourceArmServiceBusNamespace() *schema.Resource {
},
"sku": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateServiceBusNamespaceSku,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateServiceBusNamespaceSku,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"capacity": {

View File

@ -122,6 +122,31 @@ func TestAccAzureRMServiceBusNamespace_readDefaultKeys(t *testing.T) {
})
}
func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMServiceBusNamespaceNonStandardCasing(ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMServiceBusNamespaceExists("azurerm_servicebus_namespace.test"),
),
},
resource.TestStep{
Config: config,
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}
func testCheckAzureRMServiceBusNamespaceDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).serviceBusNamespacesClient
@ -188,3 +213,18 @@ resource "azurerm_servicebus_namespace" "test" {
sku = "basic"
}
`
func testAccAzureRMServiceBusNamespaceNonStandardCasing(ri int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US"
}
resource "azurerm_servicebus_namespace" "test" {
name = "acctestservicebusnamespace-%d"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Basic"
}
`, ri, ri)
}

View File

@ -59,9 +59,10 @@ func resourceArmStorageAccount() *schema.Resource {
},
"account_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArmStorageAccountType,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArmStorageAccountType,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
// Only valid for BlobStorage accounts, defaults to "Hot" in create function

View File

@ -170,6 +170,32 @@ func TestAccAzureRMStorageAccount_blobStorageWithUpdate(t *testing.T) {
})
}
func TestAccAzureRMStorageAccount_NonStandardCasing(t *testing.T) {
ri := acctest.RandInt()
rs := acctest.RandString(4)
preConfig := testAccAzureRMStorageAccountNonStandardCasing(ri, rs)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMStorageAccountDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
),
},
resource.TestStep{
Config: preConfig,
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}
func testCheckAzureRMStorageAccountExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
@ -357,3 +383,20 @@ resource "azurerm_storage_account" "testsa" {
environment = "production"
}
}`
func testAccAzureRMStorageAccountNonStandardCasing(ri int, rs string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "testrg" {
name = "testAccAzureRMSA-%d"
location = "westus"
}
resource "azurerm_storage_account" "testsa" {
name = "unlikely23exst2acct%s"
resource_group_name = "${azurerm_resource_group.testrg.name}"
location = "westus"
account_type = "standard_LRS"
tags {
environment = "production"
}
}`, ri, rs)
}

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"strings"
"github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/hashicorp/terraform/helper/hashcode"
@ -50,9 +51,10 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
},
"tier": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"capacity": {
@ -951,7 +953,7 @@ func resourceArmVirtualMachineScaleSetSkuHash(v interface{}) int {
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))
if m["tier"] != nil {
buf.WriteString(fmt.Sprintf("%s-", m["tier"].(string)))
buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(m["tier"].(string))))
}
buf.WriteString(fmt.Sprintf("%d-", m["capacity"].(int)))

View File

@ -230,6 +230,31 @@ func TestAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict(t *testing.T) {
})
}
func TestAccAzureRMVirtualMachineScaleSet_NonStandardCasing(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMVirtualMachineScaleSetNonStandardCasing(ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
),
},
resource.TestStep{
Config: config,
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}
func testGetAzureRMVirtualMachineScaleSet(s *terraform.State, resourceName string) (result *compute.VirtualMachineScaleSet, err error) {
// Ensure we have enough information in state to look up in API
rs, ok := s.RootModule().Resources[resourceName]
@ -1420,3 +1445,85 @@ resource "azurerm_virtual_machine_scale_set" "test" {
}
}
`
func testAccAzureRMVirtualMachineScaleSetNonStandardCasing(ri int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US 2"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_network_interface" "test" {
name = "acctni-%d"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
}
}
resource "azurerm_storage_account" "test" {
name = "accsa%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "westus2"
account_type = "Standard_LRS"
tags {
environment = "staging"
}
}
resource "azurerm_storage_container" "test" {
name = "vhds"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctvmss-%d"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
sku {
name = "Standard_A0"
tier = "standard"
capacity = 2
}
os_profile {
computer_name_prefix = "testvm-%d"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
network_profile {
name = "TestNetworkProfile-%d"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
}
}
storage_profile_os_disk {
name = "osDiskProfile"
caching = "ReadWrite"
create_option = "FromImage"
vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "14.04.2-LTS"
version = "latest"
}
}
`, ri, ri, ri, ri, ri, ri, ri, ri)
}