/
vdc_schema.go
273 lines (262 loc) · 8.92 KB
/
vdc_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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package vdc
import (
"fmt"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
superschema "github.com/FrangipaneTeam/terraform-plugin-framework-superschema"
"github.com/orange-cloudavenue/cloudavenue-sdk-go/v1/infrapi/rules"
)
const seeVDCRules = "See [Rules](https://registry.terraform.io/providers/orange-cloudavenue/cloudavenue/latest/docs/resources/vdc#rules) for more information."
/*
vdcSchema
This function is used to create the superschema for the vdc resource and datasource.
*/
func vdcSchema() superschema.Schema {
return superschema.Schema{
Common: superschema.SchemaDetails{
MarkdownDescription: "Provides a Cloud Avenue vDC (Virtual Data Center) ",
},
Resource: superschema.SchemaDetails{
MarkdownDescription: "resource. This can be used to create, update and delete vDC.\n\n",
},
DataSource: superschema.SchemaDetails{
MarkdownDescription: "data source. This can be used to reference a vDC and use its data within other resources or data sources.",
},
Attributes: map[string]superschema.Attribute{
"timeouts": &superschema.TimeoutAttribute{
Resource: &superschema.ResourceTimeoutAttribute{
Create: true,
Read: true,
Delete: true,
Update: true,
},
},
"id": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The ID of the vDC.",
Computed: true,
},
},
"name": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The name of the vDC.",
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(2, 27),
},
},
Resource: &schemaR.StringAttribute{
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
},
"description": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "A description of the vDC.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"cpu_speed_in_mhz": superschema.SuperInt64Attribute{
Common: &schemaR.Int64Attribute{
MarkdownDescription: "Specifies the clock frequency, in Mhz, for any virtual CPU that is allocated to a VM.",
},
Resource: &schemaR.Int64Attribute{
Required: true,
MarkdownDescription: seeVDCRules,
},
DataSource: &schemaD.Int64Attribute{
Computed: true,
},
},
"cpu_allocated": superschema.SuperInt64Attribute{
Common: &schemaR.Int64Attribute{
MarkdownDescription: "CPU capacity in *MHz* that is committed to be available or used as a limit in PAYG mode.",
},
Resource: &schemaR.Int64Attribute{
MarkdownDescription: seeVDCRules,
Required: true,
},
DataSource: &schemaD.Int64Attribute{
Computed: true,
},
},
"memory_allocated": superschema.SuperInt64Attribute{
Common: &schemaR.Int64Attribute{
MarkdownDescription: "Memory capacity in Gb that is committed to be available or used as a limit in PAYG mode.",
},
Resource: &schemaR.Int64Attribute{
Required: true,
},
DataSource: &schemaD.Int64Attribute{
Computed: true,
},
},
"service_class": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The service class of the vDC.",
},
Resource: &schemaR.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
stringvalidator.OneOf(func() []string {
var serviceClasses []string
for _, sC := range rules.ALLServiceClasses {
serviceClasses = append(serviceClasses, string(sC))
}
return serviceClasses
}()...),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"disponibility_class": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The disponibility class of the vDC.",
},
Resource: &schemaR.StringAttribute{
Required: true,
MarkdownDescription: "The disponibility class available are different depending on the service class. " + seeVDCRules,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
stringvalidator.OneOf(func() []string {
var disponibilityClasses []string
for _, dC := range rules.ALLDisponibilityClasses {
disponibilityClasses = append(disponibilityClasses, string(dC))
}
return disponibilityClasses
}()...),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"billing_model": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "Choose Billing model of compute resources.",
},
Resource: &schemaR.StringAttribute{
Required: true,
MarkdownDescription: "The billing model available are different depending on the service class. " + seeVDCRules,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
stringvalidator.OneOf(func() []string {
var billingModels []string
for _, bM := range rules.ALLBillingModels {
billingModels = append(billingModels, string(bM))
}
return billingModels
}()...),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"storage_billing_model": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "Choose Billing model of storage resources.",
},
Resource: &schemaR.StringAttribute{
Required: true,
MarkdownDescription: "The billing model available are different depending on the service class. " + seeVDCRules,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
stringvalidator.OneOf(func() []string {
var billingModels []string
for _, bM := range rules.ALLStorageBillingModels {
billingModels = append(billingModels, string(bM))
}
return billingModels
}()...),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"storage_profiles": superschema.SuperSetNestedAttributeOf[vdcResourceModelVDCStorageProfile]{
Common: &schemaR.SetNestedAttribute{
MarkdownDescription: "List of storage profiles for this vDC.",
},
Resource: &schemaR.SetNestedAttribute{
Required: true,
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
},
},
DataSource: &schemaD.SetNestedAttribute{
Computed: true,
},
Attributes: map[string]superschema.Attribute{
"class": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The storage class of the storage profile.",
},
Resource: &schemaR.StringAttribute{
Required: true,
MarkdownDescription: "The storage class available are different depending on the service class. " + seeVDCRules + " Value must be one of " + func() string {
var storageClasses string
for i, sC := range rules.ALLStorageProfilesClass {
if i == len(rules.ALLStorageProfilesClass)-1 {
storageClasses += fmt.Sprintf("`%s`", string(sC))
} else {
storageClasses += fmt.Sprintf("`%s`, ", string(sC))
}
}
return storageClasses
}() + " or custom storage profile class delivered by Cloud Avenue.",
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"limit": superschema.SuperInt64Attribute{
Common: &schemaR.Int64Attribute{
MarkdownDescription: "Max number in *Gb* of units allocated for this storage profile.",
},
Resource: &schemaR.Int64Attribute{
Required: true,
},
DataSource: &schemaD.Int64Attribute{
Computed: true,
},
},
"default": superschema.SuperBoolAttribute{
Common: &schemaR.BoolAttribute{
MarkdownDescription: "Set this storage profile as default for this vDC. Only one storage profile can be default per vDC.",
},
Resource: &schemaR.BoolAttribute{
Required: true,
},
DataSource: &schemaD.BoolAttribute{
Computed: true,
},
},
},
},
},
}
}