provider/azurerm: create common schema for location field, add diff suppress (#10409)

This commit is contained in:
Peter McAtominey 2016-11-29 15:54:00 +00:00 committed by Paul Stack
parent 8cdafe0508
commit a4054c999e
32 changed files with 72 additions and 183 deletions

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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()

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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(),
},

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,