diff --git a/builtin/providers/azurerm/location.go b/builtin/providers/azurerm/location.go new file mode 100644 index 000000000..3eb51e787 --- /dev/null +++ b/builtin/providers/azurerm/location.go @@ -0,0 +1,30 @@ +package azurerm + +import ( + "strings" + + "github.com/hashicorp/terraform/helper/schema" +) + +func locationSchema() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + StateFunc: azureRMNormalizeLocation, + DiffSuppressFunc: azureRMSuppressLocationDiff, + } +} + +// azureRMNormalizeLocation is a function which normalises human-readable region/location +// names (e.g. "West US") to the values used and returned by the Azure API (e.g. "westus"). +// In state we track the API internal version as it is easier to go from the human form +// to the canonical form than the other way around. +func azureRMNormalizeLocation(location interface{}) string { + input := location.(string) + return strings.Replace(strings.ToLower(input), " ", "", -1) +} + +func azureRMSuppressLocationDiff(k, old, new string, d *schema.ResourceData) bool { + return azureRMNormalizeLocation(old) == azureRMNormalizeLocation(new) +} diff --git a/builtin/providers/azurerm/location_test.go b/builtin/providers/azurerm/location_test.go new file mode 100644 index 000000000..aa0e4dea9 --- /dev/null +++ b/builtin/providers/azurerm/location_test.go @@ -0,0 +1,10 @@ +package azurerm + +import "testing" + +func TestAzureRMNormalizeLocation(t *testing.T) { + s := azureRMNormalizeLocation("West US") + if s != "westus" { + t.Fatalf("expected location to equal westus, actual %s", s) + } +} diff --git a/builtin/providers/azurerm/provider.go b/builtin/providers/azurerm/provider.go index 527c20433..08e9b519a 100644 --- a/builtin/providers/azurerm/provider.go +++ b/builtin/providers/azurerm/provider.go @@ -223,15 +223,6 @@ func registerAzureResourceProvidersWithSubscription(client *riviera.Client) erro return err } -// azureRMNormalizeLocation is a function which normalises human-readable region/location -// names (e.g. "West US") to the values used and returned by the Azure API (e.g. "westus"). -// In state we track the API internal version as it is easier to go from the human form -// to the canonical form than the other way around. -func azureRMNormalizeLocation(location interface{}) string { - input := location.(string) - return strings.Replace(strings.ToLower(input), " ", "", -1) -} - // armMutexKV is the instance of MutexKV for ARM resources var armMutexKV = mutexkv.NewMutexKV() diff --git a/builtin/providers/azurerm/resource_arm_availability_set.go b/builtin/providers/azurerm/resource_arm_availability_set.go index 04510c512..f396d24ca 100644 --- a/builtin/providers/azurerm/resource_arm_availability_set.go +++ b/builtin/providers/azurerm/resource_arm_availability_set.go @@ -33,12 +33,7 @@ func resourceArmAvailabilitySet() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "platform_update_domain_count": { Type: schema.TypeInt, diff --git a/builtin/providers/azurerm/resource_arm_cdn_endpoint.go b/builtin/providers/azurerm/resource_arm_cdn_endpoint.go index 7c961016c..0782a2714 100644 --- a/builtin/providers/azurerm/resource_arm_cdn_endpoint.go +++ b/builtin/providers/azurerm/resource_arm_cdn_endpoint.go @@ -29,12 +29,7 @@ func resourceArmCdnEndpoint() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_cdn_profile.go b/builtin/providers/azurerm/resource_arm_cdn_profile.go index 7ef7909d6..5a5498345 100644 --- a/builtin/providers/azurerm/resource_arm_cdn_profile.go +++ b/builtin/providers/azurerm/resource_arm_cdn_profile.go @@ -28,12 +28,7 @@ func resourceArmCdnProfile() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_eventhub.go b/builtin/providers/azurerm/resource_arm_eventhub.go index bb70c6c00..169cf690f 100644 --- a/builtin/providers/azurerm/resource_arm_eventhub.go +++ b/builtin/providers/azurerm/resource_arm_eventhub.go @@ -39,11 +39,7 @@ func resourceArmEventHub() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, + "location": locationSchema(), "partition_count": { Type: schema.TypeInt, diff --git a/builtin/providers/azurerm/resource_arm_eventhub_namespace.go b/builtin/providers/azurerm/resource_arm_eventhub_namespace.go index ff8eab012..e03281e22 100644 --- a/builtin/providers/azurerm/resource_arm_eventhub_namespace.go +++ b/builtin/providers/azurerm/resource_arm_eventhub_namespace.go @@ -5,9 +5,10 @@ import ( "log" "strings" + "net/http" + "github.com/Azure/azure-sdk-for-go/arm/eventhub" "github.com/hashicorp/terraform/helper/schema" - "net/http" ) // Default Authorization Rule/Policy created by Azure, used to populate the @@ -31,12 +32,7 @@ func resourceArmEventHubNamespace() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_key_vault.go b/builtin/providers/azurerm/resource_arm_key_vault.go index 190b76de7..3dddcd291 100644 --- a/builtin/providers/azurerm/resource_arm_key_vault.go +++ b/builtin/providers/azurerm/resource_arm_key_vault.go @@ -33,12 +33,7 @@ func resourceArmKeyVault() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer.go b/builtin/providers/azurerm/resource_arm_loadbalancer.go index d60dc57ac..193acb128 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer.go @@ -26,12 +26,7 @@ func resourceArmLoadBalancer() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_backend_address_pool.go b/builtin/providers/azurerm/resource_arm_loadbalancer_backend_address_pool.go index 516e45a70..e6bfe66c7 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_backend_address_pool.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_backend_address_pool.go @@ -25,12 +25,7 @@ func resourceArmLoadBalancerBackendAddressPool() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_nat_pool.go b/builtin/providers/azurerm/resource_arm_loadbalancer_nat_pool.go index af01dfb18..4784b4b86 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_nat_pool.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_nat_pool.go @@ -26,12 +26,7 @@ func resourceArmLoadBalancerNatPool() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_nat_rule.go b/builtin/providers/azurerm/resource_arm_loadbalancer_nat_rule.go index a0f1cee25..8353d6b26 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_nat_rule.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_nat_rule.go @@ -26,12 +26,7 @@ func resourceArmLoadBalancerNatRule() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_probe.go b/builtin/providers/azurerm/resource_arm_loadbalancer_probe.go index b619324d0..187c42083 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_probe.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_probe.go @@ -26,12 +26,7 @@ func resourceArmLoadBalancerProbe() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go b/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go index 7285abaea..18e30b059 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go @@ -28,12 +28,7 @@ func resourceArmLoadBalancerRule() *schema.Resource { ValidateFunc: validateArmLoadBalancerRuleName, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_local_network_gateway.go b/builtin/providers/azurerm/resource_arm_local_network_gateway.go index 82ea38e5e..1a172e32a 100644 --- a/builtin/providers/azurerm/resource_arm_local_network_gateway.go +++ b/builtin/providers/azurerm/resource_arm_local_network_gateway.go @@ -25,12 +25,7 @@ func resourceArmLocalNetworkGateway() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_network_interface_card.go b/builtin/providers/azurerm/resource_arm_network_interface_card.go index f91b5ed10..b3ebc3174 100644 --- a/builtin/providers/azurerm/resource_arm_network_interface_card.go +++ b/builtin/providers/azurerm/resource_arm_network_interface_card.go @@ -26,12 +26,7 @@ func resourceArmNetworkInterface() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_network_security_group.go b/builtin/providers/azurerm/resource_arm_network_security_group.go index e7344b10a..d23293027 100644 --- a/builtin/providers/azurerm/resource_arm_network_security_group.go +++ b/builtin/providers/azurerm/resource_arm_network_security_group.go @@ -30,12 +30,7 @@ func resourceArmNetworkSecurityGroup() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_public_ip.go b/builtin/providers/azurerm/resource_arm_public_ip.go index e0dadf816..127ab92b6 100644 --- a/builtin/providers/azurerm/resource_arm_public_ip.go +++ b/builtin/providers/azurerm/resource_arm_public_ip.go @@ -28,12 +28,7 @@ func resourceArmPublicIp() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_resource_group.go b/builtin/providers/azurerm/resource_arm_resource_group.go index 4f4382783..7d71f7607 100644 --- a/builtin/providers/azurerm/resource_arm_resource_group.go +++ b/builtin/providers/azurerm/resource_arm_resource_group.go @@ -28,12 +28,8 @@ func resourceArmResourceGroup() *schema.Resource { ForceNew: true, ValidateFunc: validateArmResourceGroupName, }, - "location": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + + "location": locationSchema(), "tags": tagsSchema(), }, diff --git a/builtin/providers/azurerm/resource_arm_route_table.go b/builtin/providers/azurerm/resource_arm_route_table.go index 8ba9b740c..750dc6782 100644 --- a/builtin/providers/azurerm/resource_arm_route_table.go +++ b/builtin/providers/azurerm/resource_arm_route_table.go @@ -29,12 +29,7 @@ func resourceArmRouteTable() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_search_service.go b/builtin/providers/azurerm/resource_arm_search_service.go index ffaa54ffe..8f451be14 100644 --- a/builtin/providers/azurerm/resource_arm_search_service.go +++ b/builtin/providers/azurerm/resource_arm_search_service.go @@ -24,12 +24,7 @@ func resourceArmSearchService() *schema.Resource { ForceNew: true, }, - "location": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_servicebus_namespace.go b/builtin/providers/azurerm/resource_arm_servicebus_namespace.go index 408bc4c23..c0538c25e 100644 --- a/builtin/providers/azurerm/resource_arm_servicebus_namespace.go +++ b/builtin/providers/azurerm/resource_arm_servicebus_namespace.go @@ -31,12 +31,7 @@ func resourceArmServiceBusNamespace() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_servicebus_subscription.go b/builtin/providers/azurerm/resource_arm_servicebus_subscription.go index 9c980e02a..28517c858 100644 --- a/builtin/providers/azurerm/resource_arm_servicebus_subscription.go +++ b/builtin/providers/azurerm/resource_arm_servicebus_subscription.go @@ -38,12 +38,7 @@ func resourceArmServiceBusSubscription() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_servicebus_topic.go b/builtin/providers/azurerm/resource_arm_servicebus_topic.go index 97d5704b9..9804cff4d 100644 --- a/builtin/providers/azurerm/resource_arm_servicebus_topic.go +++ b/builtin/providers/azurerm/resource_arm_servicebus_topic.go @@ -32,12 +32,7 @@ func resourceArmServiceBusTopic() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_sql_database.go b/builtin/providers/azurerm/resource_arm_sql_database.go index 35cd861a9..b022c7d1b 100644 --- a/builtin/providers/azurerm/resource_arm_sql_database.go +++ b/builtin/providers/azurerm/resource_arm_sql_database.go @@ -23,12 +23,7 @@ func resourceArmSqlDatabase() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_sql_server.go b/builtin/providers/azurerm/resource_arm_sql_server.go index a77a5b2ce..b13525443 100644 --- a/builtin/providers/azurerm/resource_arm_sql_server.go +++ b/builtin/providers/azurerm/resource_arm_sql_server.go @@ -26,12 +26,7 @@ func resourceArmSqlServer() *schema.Resource { ForceNew: true, }, - "location": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_storage_account.go b/builtin/providers/azurerm/resource_arm_storage_account.go index bba3e6b1c..f9e212558 100644 --- a/builtin/providers/azurerm/resource_arm_storage_account.go +++ b/builtin/providers/azurerm/resource_arm_storage_account.go @@ -46,12 +46,7 @@ func resourceArmStorageAccount() *schema.Resource { DiffSuppressFunc: resourceAzurermResourceGroupNameDiffSuppress, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "account_kind": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index c5fb76561..604ecb570 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -31,12 +31,7 @@ func resourceArmVirtualMachine() *schema.Resource { ForceNew: true, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go b/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go index 2f8a24763..801e83e48 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go @@ -27,12 +27,7 @@ func resourceArmVirtualMachineExtensions() *schema.Resource { ForceNew: true, }, - "location": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go b/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go index 9e2be1dc7..69b6f0dc5 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go @@ -26,12 +26,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource { ForceNew: true, }, - "location": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/azurerm/resource_arm_virtual_network.go b/builtin/providers/azurerm/resource_arm_virtual_network.go index 25a02d999..623b2d216 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_network.go +++ b/builtin/providers/azurerm/resource_arm_virtual_network.go @@ -67,12 +67,7 @@ func resourceArmVirtualNetwork() *schema.Resource { Set: resourceAzureSubnetHash, }, - "location": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: azureRMNormalizeLocation, - }, + "location": locationSchema(), "resource_group_name": { Type: schema.TypeString,