/
resource_ndfc_network.go
591 lines (532 loc) · 22.5 KB
/
resource_ndfc_network.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Mozilla Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://mozilla.org/MPL/2.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: MPL-2.0
// Code generated by "gen/generator.go"; DO NOT EDIT.
package provider
//template:begin imports
import (
"context"
"fmt"
"regexp"
"strings"
"sync"
"time"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/netascode/go-nd"
"github.com/netascode/terraform-provider-ndfc/internal/provider/helpers"
"github.com/tidwall/sjson"
)
//template:end imports
//template:begin model
// Ensure provider defined types fully satisfy framework interfaces
var _ resource.Resource = &NetworkResource{}
var _ resource.ResourceWithImportState = &NetworkResource{}
func NewNetworkResource() resource.Resource {
return &NetworkResource{}
}
type NetworkResource struct {
client *nd.Client
updateMutex *sync.Mutex
}
func (r *NetworkResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_network"
}
func (r *NetworkResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
// This description is used by the documentation generator and the language server.
MarkdownDescription: helpers.NewAttributeDescription("This resource can manage a Network.").String,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The id of the object",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"fabric_name": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("The name of the fabric").String,
Optional: true,
},
"network_name": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("The name of the network").String,
Required: true,
},
"display_name": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Customized name of the network. By default, it will be same as the network name").String,
Optional: true,
Computed: true,
},
"network_id": schema.Int64Attribute{
MarkdownDescription: helpers.NewAttributeDescription("VNI ID of the network").AddIntegerRangeDescription(1, 16777214).String,
Optional: true,
Computed: true,
Validators: []validator.Int64{
int64validator.Between(1, 16777214),
},
},
"network_template": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("The name of the network template").AddDefaultValueDescription("Default_Network_Universal").String,
Optional: true,
Computed: true,
Default: stringdefault.StaticString("Default_Network_Universal"),
},
"network_extension_template": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("The name of the network extension template. Applicable to Switch(es) with role Border").AddDefaultValueDescription("Default_Network_Extension_Universal").String,
Optional: true,
Computed: true,
Default: stringdefault.StaticString("Default_Network_Extension_Universal"),
},
"vrf_name": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("The name of the vrf").String,
Required: true,
},
"gateway_ipv4_address": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Gateway IPv4 address, for example `192.0.2.1/24`").String,
Optional: true,
},
"vlan_id": schema.Int64Attribute{
MarkdownDescription: helpers.NewAttributeDescription("VLAN ID").AddIntegerRangeDescription(2, 4094).String,
Optional: true,
Computed: true,
Validators: []validator.Int64{
int64validator.Between(2, 4094),
},
},
"gateway_ipv6_address": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Gateway IPv6 addresses, for example `2001:db8::1/64,2001:db9::1/64`").String,
Optional: true,
},
"layer2_only": schema.BoolAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Layer-2 only flag").AddDefaultValueDescription("false").String,
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
"arp_suppression": schema.BoolAttribute{
MarkdownDescription: helpers.NewAttributeDescription("ARP suppression is only supported if SVI is present when Layer-2-Only is not enabled. NX-OS Specific").String,
Optional: true,
},
"ingress_replication": schema.BoolAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Ingress replication flag").AddDefaultValueDescription("false").String,
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
"multicast_group": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Multicast group address").String,
Optional: true,
Computed: true,
},
"dhcp_relay_servers": schema.ListNestedAttribute{
MarkdownDescription: helpers.NewAttributeDescription("List of DHCP relay servers").String,
Optional: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"address": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Server IP V4 Address").String,
Optional: true,
},
"vrf": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("If management vrf, enter 'management'. If default/global vrf, enter 'default'.").String,
Optional: true,
},
},
},
Validators: []validator.List{
listvalidator.SizeAtMost(16),
},
},
"dhcp_relay_loopback_id": schema.Int64Attribute{
MarkdownDescription: helpers.NewAttributeDescription("Loopback ID for DHCP Relay interface").AddIntegerRangeDescription(0, 1023).String,
Optional: true,
Validators: []validator.Int64{
int64validator.Between(0, 1023),
},
},
"vlan_name": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("VLAN name").String,
Optional: true,
Validators: []validator.String{
stringvalidator.RegexMatches(regexp.MustCompile(`^[^\?,\\,\s]{1,128}$`), ""),
},
},
"interface_description": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Interface description").String,
Optional: true,
},
"mtu": schema.Int64Attribute{
MarkdownDescription: helpers.NewAttributeDescription("Interface MTU").AddIntegerRangeDescription(68, 9216).AddDefaultValueDescription("9216").String,
Optional: true,
Computed: true,
Validators: []validator.Int64{
int64validator.Between(68, 9216),
},
Default: int64default.StaticInt64(9216),
},
"loopback_routing_tag": schema.Int64Attribute{
MarkdownDescription: helpers.NewAttributeDescription("Loopback routing tag").AddIntegerRangeDescription(0, 4294967295).AddDefaultValueDescription("12345").String,
Optional: true,
Computed: true,
Validators: []validator.Int64{
int64validator.Between(0, 4294967295),
},
Default: int64default.StaticInt64(12345),
},
"trm": schema.BoolAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Enable Tenant Routed Multicast").String,
Optional: true,
},
"secondary_gateway_1": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Secondary gateway 1").String,
Optional: true,
},
"secondary_gateway_2": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Secondary gateway 2").String,
Optional: true,
},
"secondary_gateway_3": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Secondary gateway 3").String,
Optional: true,
},
"secondary_gateway_4": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Secondary gateway 4").String,
Optional: true,
},
"route_target_both": schema.BoolAttribute{
MarkdownDescription: helpers.NewAttributeDescription("L2 VNI Route-Target Both Enable").AddDefaultValueDescription("false").String,
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
"netflow": schema.BoolAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Netflow is supported only if it is enabled on fabric. For NX-OS only").AddDefaultValueDescription("false").String,
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
"svi_netflow_monitor": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Applicable only if 'Layer 2 Only' is not enabled. Provide monitor name defined in fabric setting for Layer 3 Record. For NX-OS only").String,
Optional: true,
},
"vlan_netflow_monitor": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Provide monitor name defined in fabric setting for Layer 3 Record. For NX-OS only").String,
Optional: true,
},
"l3_gatway_border": schema.BoolAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Enable L3 Gateway on Border").AddDefaultValueDescription("false").String,
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
"attachments": schema.SetNestedAttribute{
MarkdownDescription: helpers.NewAttributeDescription("A list of attachments").String,
Optional: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"serial_number": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Serial number of switch to attach").String,
Required: true,
},
"attach_switch_ports": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Comma separated list of attached switchports").String,
Optional: true,
},
"detach_switch_ports": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Comma separated list of detached switchports").String,
Optional: true,
},
"vlan_id": schema.Int64Attribute{
MarkdownDescription: helpers.NewAttributeDescription("Override VLAN ID. `-1` to use VLAN ID defined at VRF level").AddIntegerRangeDescription(-1, 4092).AddDefaultValueDescription("-1").String,
Optional: true,
Computed: true,
Validators: []validator.Int64{
int64validator.Between(-1, 4092),
},
Default: int64default.StaticInt64(-1),
},
"freeform_config": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("This field covers any configuration not included in overlay templates which is needed as part of this VRF attachment").String,
Optional: true,
},
},
},
},
},
}
}
func (r *NetworkResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
r.client = req.ProviderData.(*NdfcProviderData).Client
r.updateMutex = req.ProviderData.(*NdfcProviderData).UpdateMutex
}
//template:end model
func (r *NetworkResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var plan Network
// Read plan
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString()))
// Create object
body := plan.toBody(ctx)
r.updateMutex.Lock()
res, err := r.client.Post(plan.getPath(), body)
r.updateMutex.Unlock()
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String()))
return
}
plan.Id = types.StringValue(plan.FabricName.ValueString() + "/" + plan.NetworkName.ValueString())
if len(plan.Attachments) > 0 {
// attach
res, err = r.client.Get(fmt.Sprintf("%vattachments?network-names=%v", plan.getPath(), plan.NetworkName.ValueString()))
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve network attachments, got error: %s, %s", err, res.String()))
return
}
bodyAttachments := plan.toBodyAttachments(ctx, res)
r.updateMutex.Lock()
res, err = r.client.Post(plan.getPath()+"attachments", bodyAttachments)
r.updateMutex.Unlock()
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure network attachments, got error: %s, %s", err, res.String()))
return
}
// deploy
diags = r.Deploy(ctx, plan, "DEPLOYED")
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}
res, err = r.client.Get(fmt.Sprintf("%v%v", plan.getPath(), plan.NetworkName.ValueString()))
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String()))
return
}
plan.fromBody(ctx, res)
tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Id.ValueString()))
diags = resp.State.Set(ctx, &plan)
resp.Diagnostics.Append(diags...)
}
func (r *NetworkResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var state Network
// Read state
diags := req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.String()))
res, err := r.client.Get(fmt.Sprintf("%v%v", state.getPath(), state.NetworkName.ValueString()))
if err != nil {
if strings.Contains(err.Error(), "StatusCode 400") || strings.Contains(err.Error(), "StatusCode 500") {
resp.State.RemoveResource(ctx)
return
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String()))
return
}
}
state.fromBody(ctx, res)
res, err = r.client.Get(fmt.Sprintf("%vattachments?network-names=%v", state.getPath(), state.NetworkName.ValueString()))
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve network attachments, got error: %s, %s", err, res.String()))
return
}
state.fromBodyAttachments(ctx, res, false)
tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Id.ValueString()))
diags = resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)
}
func (r *NetworkResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var plan, state Network
// Read plan
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
// Read state
diags = req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString()))
plan.NetworkId = state.NetworkId
body := plan.toBody(ctx)
r.updateMutex.Lock()
res, err := r.client.Put(fmt.Sprintf("%v%v", plan.getPath(), plan.NetworkName.ValueString()), body)
r.updateMutex.Unlock()
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String()))
return
}
if len(plan.Attachments) > 0 {
// attach
res, err = r.client.Get(fmt.Sprintf("%vattachments?network-names=%v", plan.getPath(), plan.NetworkName.ValueString()))
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve network attachments, got error: %s, %s", err, res.String()))
return
}
bodyAttachments := plan.toBodyAttachments(ctx, res)
r.updateMutex.Lock()
res, err = r.client.Post(plan.getPath()+"attachments", bodyAttachments)
r.updateMutex.Unlock()
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure network attachments, got error: %s, %s", err, res.String()))
return
}
// deploy
diags = r.Deploy(ctx, plan, "DEPLOYED")
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}
res, err = r.client.Get(fmt.Sprintf("%v%v", plan.getPath(), plan.NetworkName.ValueString()))
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String()))
return
}
plan.fromBody(ctx, res)
tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.Id.ValueString()))
diags = resp.State.Set(ctx, &plan)
resp.Diagnostics.Append(diags...)
}
func (r *NetworkResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var state Network
// Read state
diags := req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString()))
if len(state.Attachments) > 0 {
// detach everything
res, err := r.client.Get(fmt.Sprintf("%vattachments?network-names=%v", state.getPath(), state.NetworkName.ValueString()))
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve network attachments, got error: %s, %s", err, res.String()))
return
}
state.Attachments = make([]NetworkAttachments, 0)
bodyAttachments := state.toBodyAttachments(ctx, res)
r.updateMutex.Lock()
res, err = r.client.Post(state.getPath()+"attachments", bodyAttachments)
r.updateMutex.Unlock()
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure network attachments, got error: %s, %s", err, res.String()))
return
}
// deploy
diags = r.Deploy(ctx, state, "NA")
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
} else {
// if there is an ongoing deploy, wait for it to finish
diags = r.WaitForStatus(ctx, state, "NA")
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}
// delete network
res, err := r.client.Delete(fmt.Sprintf("%v%v", state.getPath(), state.NetworkName.ValueString()), "")
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String()))
return
}
tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString()))
resp.State.RemoveResource(ctx)
}
func (r *NetworkResource) Deploy(ctx context.Context, state Network, expectedStatus string) diag.Diagnostics {
var diags diag.Diagnostics
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Deploy", state.Id.ValueString()))
body := ""
body, _ = sjson.Set(body, "networkNames", state.NetworkName.ValueString())
r.updateMutex.Lock()
defer r.updateMutex.Unlock()
res, err := r.client.Post(state.getPath()+"deployments", body)
if err != nil {
diags.AddError("Client Error", fmt.Sprintf("Failed to deploy network, got error: %s, %s", err, res.String()))
return diags
}
d := r.WaitForStatus(ctx, state, expectedStatus)
diags.Append(d...)
if diags.HasError() {
return diags
}
tflog.Debug(ctx, fmt.Sprintf("%s: Deploy finished successfully", state.Id.ValueString()))
return diags
}
func (r *NetworkResource) WaitForStatus(ctx context.Context, state Network, expectedStatus string) diag.Diagnostics {
var diags diag.Diagnostics
status := ""
for i := 0; i < (helpers.FABRIC_DEPLOY_TIMEOUT / 5); i++ {
res, err := r.client.Get(state.getPath())
if err != nil {
diags.AddError("Client Error", fmt.Sprintf("Failed to retrieve networks, got error: %s, %s", err, res.String()))
return diags
}
status = res.Get(`#(networkName="` + state.NetworkName.ValueString() + `").networkStatus`).String()
if status == expectedStatus {
break
}
time.Sleep(5 * time.Second)
}
if status != expectedStatus {
diags.AddError("Client Error", fmt.Sprintf("Network deployment timed out, got status: %s", status))
return diags
}
return diags
}
//template:begin import
func (r *NetworkResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
idParts := strings.Split(req.ID, ":")
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
resp.Diagnostics.AddError(
"Unexpected Import Identifier",
fmt.Sprintf("Expected import identifier with format: '<fabric_name>:<network_name>'. Got: %q", req.ID),
)
return
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("fabric_name"), idParts[0])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("network_name"), idParts[1])...)
}
//template:end import