-
Notifications
You must be signed in to change notification settings - Fork 154
/
data_source_huaweicloud_cc_support_binding_global_connection_bandwidths.go
309 lines (295 loc) · 10.3 KB
/
data_source_huaweicloud_cc_support_binding_global_connection_bandwidths.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// Generated by PMS #134
package cc
import (
"context"
"strings"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/tidwall/gjson"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/filters"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/httphelper"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/schemas"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)
func DataSourceCcSupportBindingGlobalConnectionBandwidths() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceCcSupportBindingGlobalConnectionBandwidthsRead,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `Specifies the region in which to query the resource. If omitted, the provider-level region will be used.`,
},
"binding_service": {
Type: schema.TypeString,
Required: true,
Description: `Specifies the binding service.`,
},
"local_area": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the local access point.`,
},
"remote_area": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the remote access point.`,
},
"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the enterprise project ID.`,
},
"gcb_id": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the global connection bandwidth ID.`,
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the global connection bandwidth name.`,
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the global connection bandwidth type.`,
},
"charge_mode": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the billing option.`,
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: `Specifies the global connection bandwidth size.`,
},
"sla_level": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the class of a global connection bandwidth.`,
},
"admin_state": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the global connection bandwidth status.`,
},
"globalconnection_bandwidths": {
Type: schema.TypeList,
Computed: true,
Description: `The global connection bandwidth list.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: `The global connection bandwidth ID.`,
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: `The global connection bandwidth name.`,
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: `The global connection bandwidth description.`,
},
"domain_id": {
Type: schema.TypeString,
Computed: true,
Description: `The ID of the account that the global connection bandwidth belongs to.`,
},
"bordercross": {
Type: schema.TypeBool,
Computed: true,
Description: `Whether the global connection bandwidth is used for cross-border communications.`,
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: `The type of a global connection bandwidth.`,
},
"binding_service": {
Type: schema.TypeString,
Computed: true,
Description: `The type of the binding service.`,
},
"enterprise_project_id": {
Type: schema.TypeString,
Computed: true,
Description: `The ID of the enterprise project that the global connection bandwidth belongs to.`,
},
"charge_mode": {
Type: schema.TypeString,
Computed: true,
Description: `The billing option. By default, billing by bandwidth is enabled.`,
},
"size": {
Type: schema.TypeInt,
Computed: true,
Description: `The range of a global connection bandwidth, in Mbit/s.`,
},
"sla_level": {
Type: schema.TypeString,
Computed: true,
Description: `The class of a global connection bandwidth.`,
},
"local_site_code": {
Type: schema.TypeString,
Computed: true,
Description: `The code of the local access point.`,
},
"remote_site_code": {
Type: schema.TypeString,
Computed: true,
Description: `The code of the remote access point.`,
},
"frozen": {
Type: schema.TypeBool,
Computed: true,
Description: `Whether a global connection bandwidth is frozen.`,
},
"spec_code_id": {
Type: schema.TypeString,
Computed: true,
Description: `The UUID of a line specification code.`,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: `Time when the resource was created.`,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: `Time when the resource was updated.`,
},
"enable_share": {
Type: schema.TypeBool,
Computed: true,
Description: `Whether a global connection bandwidth can be used by multiple instances.`,
},
"local_area": {
Type: schema.TypeString,
Computed: true,
Description: `The name of a local access point.`,
},
"remote_area": {
Type: schema.TypeString,
Computed: true,
Description: `The name of a remote access point.`,
},
"admin_state": {
Type: schema.TypeString,
Computed: true,
Description: `The global connection bandwidth status.`,
},
},
},
},
},
}
}
type SupportBindingGlobalConnectionBandwidthsDSWrapper struct {
*schemas.ResourceDataWrapper
Config *config.Config
}
func newSupportBindingGlobalConnectionBandwidthsDSWrapper(
d *schema.ResourceData,
meta interface{},
) *SupportBindingGlobalConnectionBandwidthsDSWrapper {
return &SupportBindingGlobalConnectionBandwidthsDSWrapper{
ResourceDataWrapper: schemas.NewSchemaWrapper(d),
Config: meta.(*config.Config),
}
}
func dataSourceCcSupportBindingGlobalConnectionBandwidthsRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
wrapper := newSupportBindingGlobalConnectionBandwidthsDSWrapper(d, meta)
lisSupBinConBanRst, err := wrapper.ListSupportBindingConnectionBandwidths()
if err != nil {
return diag.FromErr(err)
}
id, err := uuid.GenerateUUID()
if err != nil {
return diag.FromErr(err)
}
d.SetId(id)
err = wrapper.listSupportBindingConnectionBandwidthsToSchema(lisSupBinConBanRst)
if err != nil {
return diag.FromErr(err)
}
return nil
}
// @API CC GET /v3/{domain_id}/gcb/gcbandwidths/support-bindings
func (w *SupportBindingGlobalConnectionBandwidthsDSWrapper) ListSupportBindingConnectionBandwidths() (*gjson.Result, error) {
client, err := w.NewClient(w.Config, "cc")
if err != nil {
return nil, err
}
uri := "/v3/{domain_id}/gcb/gcbandwidths/support-bindings"
uri = strings.ReplaceAll(uri, "{domain_id}", w.Config.DomainID)
params := map[string]any{
"enterprise_project_id": w.Get("enterprise_project_id"),
"local_area": w.Get("local_area"),
"remote_area": w.Get("remote_area"),
"binding_service": w.Get("binding_service"),
}
params = utils.RemoveNil(params)
return httphelper.New(client).
Method("GET").
URI(uri).
Query(params).
MarkerPager("globalconnection_bandwidths", "page_info.next_marker", "marker").
Filter(
filters.New().From("globalconnection_bandwidths").
Where("id", "=", w.Get("gcb_id")).
Where("name", "=", w.Get("name")).
Where("size", "=", w.Get("size")).
Where("sla_level", "=", w.Get("sla_level")).
Where("type", "=", w.Get("type")).
Where("charge_mode", "=", w.Get("charge_mode")).
Where("admin_state", "=", w.Get("admin_state")),
).
Request().
Result()
}
func (w *SupportBindingGlobalConnectionBandwidthsDSWrapper) listSupportBindingConnectionBandwidthsToSchema(body *gjson.Result) error {
d := w.ResourceData
mErr := multierror.Append(nil,
d.Set("region", w.Config.GetRegion(w.ResourceData)),
d.Set("globalconnection_bandwidths", schemas.SliceToList(body.Get("globalconnection_bandwidths"),
func(gloBan gjson.Result) any {
return map[string]any{
"id": gloBan.Get("id").Value(),
"name": gloBan.Get("name").Value(),
"description": gloBan.Get("description").Value(),
"domain_id": gloBan.Get("domain_id").Value(),
"bordercross": gloBan.Get("bordercross").Value(),
"type": gloBan.Get("type").Value(),
"binding_service": gloBan.Get("binding_service").Value(),
"enterprise_project_id": gloBan.Get("enterprise_project_id").Value(),
"charge_mode": gloBan.Get("charge_mode").Value(),
"size": gloBan.Get("size").Value(),
"sla_level": gloBan.Get("sla_level").Value(),
"local_site_code": gloBan.Get("local_site_code").Value(),
"remote_site_code": gloBan.Get("remote_site_code").Value(),
"frozen": gloBan.Get("frozen").Value(),
"spec_code_id": gloBan.Get("spec_code_id").Value(),
"created_at": gloBan.Get("created_at").Value(),
"updated_at": gloBan.Get("updated_at").Value(),
"enable_share": gloBan.Get("enable_share").Value(),
"local_area": gloBan.Get("local_area").Value(),
"remote_area": gloBan.Get("remote_area").Value(),
"admin_state": gloBan.Get("admin_state").Value(),
}
},
)),
)
return mErr.ErrorOrNil()
}