-
Notifications
You must be signed in to change notification settings - Fork 7
/
resource_schema.go
128 lines (110 loc) · 3.02 KB
/
resource_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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package common
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/utils/fmtp"
)
// TagsSchema returns the schema to use for tags.
func TagsSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
}
}
// TagsForceNewSchema returns the schema to use for tags with ForceNew
func TagsForceNewSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
}
}
// TagsComputedSchema returns the schema to use for tags as an attribute
func TagsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
}
}
func SchemaChargingMode(conflicts []string) *schema.Schema {
resourceSchema := schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"prePaid", "postPaid",
}, false),
ConflictsWith: conflicts,
}
return &resourceSchema
}
func SchemaPeriodUnit(conflicts []string) *schema.Schema {
resourceSchema := schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
RequiredWith: []string{"period"},
ValidateFunc: validation.StringInSlice([]string{
"month", "year",
}, false),
ConflictsWith: conflicts,
}
return &resourceSchema
}
func SchemaPeriod(conflicts []string) *schema.Schema {
resourceSchema := schema.Schema{
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
RequiredWith: []string{"period_unit"},
ValidateFunc: validation.IntBetween(1, 9),
ConflictsWith: conflicts,
}
return &resourceSchema
}
func SchemaAutoRenew(conflicts []string) *schema.Schema {
resourceSchema := schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"true", "false",
}, false),
ConflictsWith: conflicts,
}
return &resourceSchema
}
func SchemaAutoRenewUpdatable(conflicts []string) *schema.Schema {
resourceSchema := schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"true", "false",
}, false),
ConflictsWith: conflicts,
}
return &resourceSchema
}
func SchemaAutoPay(conflicts []string) *schema.Schema {
resourceSchema := schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"true", "false",
}, false),
ConflictsWith: conflicts,
Deprecated: "Deprecated",
}
return &resourceSchema
}
func ValidatePrePaidChargeInfo(d *schema.ResourceData) error {
if _, ok := d.GetOk("period_unit"); !ok {
return fmtp.Errorf("both of `period, period_unit` must be specified in prePaid charging mode")
}
return nil
}