provider/azurerm: create common schema for location field, add diff suppress (#10409)
This commit is contained in:
parent
8cdafe0508
commit
a4054c999e
|
@ -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)
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -223,15 +223,6 @@ func registerAzureResourceProvidersWithSubscription(client *riviera.Client) erro
|
||||||
return err
|
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
|
// armMutexKV is the instance of MutexKV for ARM resources
|
||||||
var armMutexKV = mutexkv.NewMutexKV()
|
var armMutexKV = mutexkv.NewMutexKV()
|
||||||
|
|
||||||
|
|
|
@ -33,12 +33,7 @@ func resourceArmAvailabilitySet() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"platform_update_domain_count": {
|
"platform_update_domain_count": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
|
|
|
@ -29,12 +29,7 @@ func resourceArmCdnEndpoint() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -28,12 +28,7 @@ func resourceArmCdnProfile() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -39,11 +39,7 @@ func resourceArmEventHub() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
"partition_count": {
|
"partition_count": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
|
|
|
@ -5,9 +5,10 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/arm/eventhub"
|
"github.com/Azure/azure-sdk-for-go/arm/eventhub"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default Authorization Rule/Policy created by Azure, used to populate the
|
// Default Authorization Rule/Policy created by Azure, used to populate the
|
||||||
|
@ -31,12 +32,7 @@ func resourceArmEventHubNamespace() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -33,12 +33,7 @@ func resourceArmKeyVault() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -26,12 +26,7 @@ func resourceArmLoadBalancer() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -25,12 +25,7 @@ func resourceArmLoadBalancerBackendAddressPool() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -26,12 +26,7 @@ func resourceArmLoadBalancerNatPool() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -26,12 +26,7 @@ func resourceArmLoadBalancerNatRule() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -26,12 +26,7 @@ func resourceArmLoadBalancerProbe() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -28,12 +28,7 @@ func resourceArmLoadBalancerRule() *schema.Resource {
|
||||||
ValidateFunc: validateArmLoadBalancerRuleName,
|
ValidateFunc: validateArmLoadBalancerRuleName,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -25,12 +25,7 @@ func resourceArmLocalNetworkGateway() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Optional: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -26,12 +26,7 @@ func resourceArmNetworkInterface() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -30,12 +30,7 @@ func resourceArmNetworkSecurityGroup() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -28,12 +28,7 @@ func resourceArmPublicIp() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -28,12 +28,8 @@ func resourceArmResourceGroup() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
ValidateFunc: validateArmResourceGroupName,
|
ValidateFunc: validateArmResourceGroupName,
|
||||||
},
|
},
|
||||||
"location": &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
"location": locationSchema(),
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"tags": tagsSchema(),
|
"tags": tagsSchema(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,12 +29,7 @@ func resourceArmRouteTable() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -24,12 +24,7 @@ func resourceArmSearchService() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": &schema.Schema{
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": &schema.Schema{
|
"resource_group_name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -31,12 +31,7 @@ func resourceArmServiceBusNamespace() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -38,12 +38,7 @@ func resourceArmServiceBusSubscription() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -32,12 +32,7 @@ func resourceArmServiceBusTopic() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -23,12 +23,7 @@ func resourceArmSqlDatabase() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -26,12 +26,7 @@ func resourceArmSqlServer() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": &schema.Schema{
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": &schema.Schema{
|
"resource_group_name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -46,12 +46,7 @@ func resourceArmStorageAccount() *schema.Resource {
|
||||||
DiffSuppressFunc: resourceAzurermResourceGroupNameDiffSuppress,
|
DiffSuppressFunc: resourceAzurermResourceGroupNameDiffSuppress,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"account_kind": {
|
"account_kind": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -31,12 +31,7 @@ func resourceArmVirtualMachine() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -27,12 +27,7 @@ func resourceArmVirtualMachineExtensions() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": &schema.Schema{
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": &schema.Schema{
|
"resource_group_name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -26,12 +26,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": &schema.Schema{
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": &schema.Schema{
|
"resource_group_name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -67,12 +67,7 @@ func resourceArmVirtualNetwork() *schema.Resource {
|
||||||
Set: resourceAzureSubnetHash,
|
Set: resourceAzureSubnetHash,
|
||||||
},
|
},
|
||||||
|
|
||||||
"location": {
|
"location": locationSchema(),
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
ForceNew: true,
|
|
||||||
StateFunc: azureRMNormalizeLocation,
|
|
||||||
},
|
|
||||||
|
|
||||||
"resource_group_name": {
|
"resource_group_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
Loading…
Reference in New Issue