/
schema.go
51 lines (44 loc) · 1.28 KB
/
schema.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
package location
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
// Schema returns the default Schema which should be used for Location fields
// where these are Required and Cannot be Changed
func Schema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: EnhancedValidate,
StateFunc: StateFunc,
DiffSuppressFunc: DiffSuppressFunc,
}
}
// SchemaOptional returns the Schema for a Location field where this can be optionally specified
func SchemaOptional() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
StateFunc: StateFunc,
DiffSuppressFunc: DiffSuppressFunc,
}
}
func SchemaComputed() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Computed: true,
}
}
func DiffSuppressFunc(_, old, new string, _ *schema.ResourceData) bool {
return Normalize(old) == Normalize(new)
}
func HashCode(location interface{}) int {
loc := location.(string)
return hashcode.String(Normalize(loc))
}
func StateFunc(location interface{}) string {
input := location.(string)
return Normalize(input)
}