forked from hashicorp/terraform
/
schema_metadata.go
110 lines (102 loc) · 4.41 KB
/
schema_metadata.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package kubernetes
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
)
func metadataFields(objectName string) map[string]*schema.Schema {
return map[string]*schema.Schema{
"annotations": {
Type: schema.TypeMap,
Description: fmt.Sprintf("An unstructured key value map stored with the %s that may be used to store arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations", objectName),
Optional: true,
ValidateFunc: validateAnnotations,
},
"generation": {
Type: schema.TypeInt,
Description: "A sequence number representing a specific generation of the desired state.",
Computed: true,
},
"labels": {
Type: schema.TypeMap,
Description: fmt.Sprintf("Map of string keys and values that can be used to organize and categorize (scope and select) the %s. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels", objectName),
Optional: true,
ValidateFunc: validateLabels,
},
"name": {
Type: schema.TypeString,
Description: fmt.Sprintf("Name of the %s, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names", objectName),
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validateName,
},
"resource_version": {
Type: schema.TypeString,
Description: fmt.Sprintf("An opaque value that represents the internal version of this %s that can be used by clients to determine when %s has changed. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#concurrency-control-and-consistency", objectName, objectName),
Computed: true,
},
"self_link": {
Type: schema.TypeString,
Description: fmt.Sprintf("A URL representing this %s.", objectName),
Computed: true,
},
"uid": {
Type: schema.TypeString,
Description: fmt.Sprintf("The unique in time and space value for this %s. More info: http://kubernetes.io/docs/user-guide/identifiers#uids", objectName),
Computed: true,
},
}
}
func metadataSchema(objectName string, generatableName bool) *schema.Schema {
fields := metadataFields(objectName)
if generatableName {
fields["generate_name"] = &schema.Schema{
Type: schema.TypeString,
Description: "Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#idempotency",
Optional: true,
ForceNew: true,
ValidateFunc: validateGenerateName,
ConflictsWith: []string{"metadata.name"},
}
fields["name"].ConflictsWith = []string{"metadata.generate_name"}
}
return &schema.Schema{
Type: schema.TypeList,
Description: fmt.Sprintf("Standard %s's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata", objectName),
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: fields,
},
}
}
func namespacedMetadataSchema(objectName string, generatableName bool) *schema.Schema {
fields := metadataFields(objectName)
fields["namespace"] = &schema.Schema{
Type: schema.TypeString,
Description: fmt.Sprintf("Namespace defines the space within which name of the %s must be unique.", objectName),
Optional: true,
ForceNew: true,
Default: "default",
}
if generatableName {
fields["generate_name"] = &schema.Schema{
Type: schema.TypeString,
Description: "Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#idempotency",
Optional: true,
ForceNew: true,
ValidateFunc: validateGenerateName,
ConflictsWith: []string{"metadata.name"},
}
fields["name"].ConflictsWith = []string{"metadata.generate_name"}
}
return &schema.Schema{
Type: schema.TypeList,
Description: fmt.Sprintf("Standard %s's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata", objectName),
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: fields,
},
}
}