forked from hashicorp/terraform-provider-azurerm
/
location.go
63 lines (54 loc) · 1.74 KB
/
location.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package azure
import (
"strings"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
)
func SchemaLocation() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
StateFunc: NormalizeLocation,
DiffSuppressFunc: SuppressLocationDiff,
}
}
func SchemaLocationOptional() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
StateFunc: NormalizeLocation,
DiffSuppressFunc: SuppressLocationDiff,
}
}
func SchemaLocationForDataSource() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Computed: true,
}
}
func SchemaLocationDeprecated() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
ForceNew: true,
Optional: true,
StateFunc: NormalizeLocation,
DiffSuppressFunc: SuppressLocationDiff,
Deprecated: "location is no longer used",
}
}
// 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 NormalizeLocation(location interface{}) string {
input := location.(string)
return strings.Replace(strings.ToLower(input), " ", "", -1)
}
func SuppressLocationDiff(k, old, new string, d *schema.ResourceData) bool {
return NormalizeLocation(old) == NormalizeLocation(new)
}
func HashAzureLocation(location interface{}) int {
return hashcode.String(NormalizeLocation(location.(string)))
}