github.com/skyscape-cloud-services/terraform@v0.9.2-0.20170609144644-7ece028a1747/builtin/providers/azurerm/location.go (about) 1 package azurerm 2 3 import ( 4 "strings" 5 6 "github.com/hashicorp/terraform/helper/schema" 7 ) 8 9 func locationSchema() *schema.Schema { 10 return &schema.Schema{ 11 Type: schema.TypeString, 12 Required: true, 13 ForceNew: true, 14 StateFunc: azureRMNormalizeLocation, 15 DiffSuppressFunc: azureRMSuppressLocationDiff, 16 } 17 } 18 19 func locationForDataSourceSchema() *schema.Schema { 20 return &schema.Schema{ 21 Type: schema.TypeString, 22 Computed: true, 23 } 24 } 25 26 func deprecatedLocationSchema() *schema.Schema { 27 return &schema.Schema{ 28 Type: schema.TypeString, 29 ForceNew: true, 30 Optional: true, 31 StateFunc: azureRMNormalizeLocation, 32 DiffSuppressFunc: azureRMSuppressLocationDiff, 33 Deprecated: "location is no longer used", 34 } 35 } 36 37 // azureRMNormalizeLocation is a function which normalises human-readable region/location 38 // names (e.g. "West US") to the values used and returned by the Azure API (e.g. "westus"). 39 // In state we track the API internal version as it is easier to go from the human form 40 // to the canonical form than the other way around. 41 func azureRMNormalizeLocation(location interface{}) string { 42 input := location.(string) 43 return strings.Replace(strings.ToLower(input), " ", "", -1) 44 } 45 46 func azureRMSuppressLocationDiff(k, old, new string, d *schema.ResourceData) bool { 47 return azureRMNormalizeLocation(old) == azureRMNormalizeLocation(new) 48 }