-
Notifications
You must be signed in to change notification settings - Fork 7
/
resource_meraki_networks_appliance_vlans.go
1161 lines (1086 loc) · 42.2 KB
/
resource_meraki_networks_appliance_vlans.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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package provider
// RESOURCE NORMAL
import (
"context"
"fmt"
"strconv"
"strings"
"log"
merakigosdk "github.com/meraki/dashboard-api-go/v3/sdk"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"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/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
"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-framework/types/basetypes"
)
var (
_ resource.Resource = &NetworksApplianceVLANsResource{}
_ resource.ResourceWithConfigure = &NetworksApplianceVLANsResource{}
)
func NewNetworksApplianceVLANsResource() resource.Resource {
return &NetworksApplianceVLANsResource{}
}
type NetworksApplianceVLANsResource struct {
client *merakigosdk.Client
}
func (r *NetworksApplianceVLANsResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
client := req.ProviderData.(MerakiProviderData).Client
r.client = client
}
// Metadata returns the data source type name.
func (r *NetworksApplianceVLANsResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_networks_appliance_vlans"
}
func (r *NetworksApplianceVLANsResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"appliance_ip": schema.StringAttribute{
MarkdownDescription: `The local IP of the appliance on the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"cidr": schema.StringAttribute{
MarkdownDescription: `CIDR of the pool of subnets. Applicable only for template network. Each network bound to the template will automatically pick a subnet from this pool to build its own VLAN.`,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"dhcp_boot_filename": schema.StringAttribute{
MarkdownDescription: `DHCP boot option for boot filename`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"dhcp_boot_next_server": schema.StringAttribute{
MarkdownDescription: `DHCP boot option to direct boot clients to the server to load the boot file from`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"dhcp_boot_options_enabled": schema.BoolAttribute{
MarkdownDescription: `Use DHCP boot options specified in other properties`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(),
},
},
"dhcp_handling": schema.StringAttribute{
MarkdownDescription: `The appliance's handling of DHCP requests on this VLAN. One of: 'Run a DHCP server', 'Relay DHCP to another server' or 'Do not respond to DHCP requests'`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.OneOf(
"Do not respond to DHCP requests",
"Relay DHCP to another server",
"Run a DHCP server",
),
},
},
"dhcp_lease_time": schema.StringAttribute{
MarkdownDescription: `The term of DHCP leases if the appliance is running a DHCP server on this VLAN. One of: '30 minutes', '1 hour', '4 hours', '12 hours', '1 day' or '1 week'`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.OneOf(
"1 day",
"1 hour",
"1 week",
"12 hours",
"30 minutes",
"4 hours",
),
},
},
"dhcp_options": schema.SetNestedAttribute{
MarkdownDescription: `The list of DHCP options that will be included in DHCP responses. Each object in the list should have "code", "type", and "value" properties.`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"code": schema.StringAttribute{
MarkdownDescription: `The code for the DHCP option. This should be an integer between 2 and 254.`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"type": schema.StringAttribute{
MarkdownDescription: `The type for the DHCP option. One of: 'text', 'ip', 'hex' or 'integer'`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.OneOf(
"hex",
"integer",
"ip",
"text",
),
},
},
"value": schema.StringAttribute{
MarkdownDescription: `The value for the DHCP option`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
},
},
"dhcp_relay_server_ips": schema.SetAttribute{
MarkdownDescription: `The IPs of the DHCP servers that DHCP requests should be relayed to`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
ElementType: types.StringType,
},
"dns_nameservers": schema.StringAttribute{
MarkdownDescription: `The DNS nameservers used for DHCP responses, either "upstream_dns", "google_dns", "opendns", or a newline seperated string of IP addresses or domain names`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
// "fixed_ip_assignments": schema.StringAttribute{
// //Todo interface
// MarkdownDescription: `The DHCP fixed IP assignments on the VLAN. This should be an object that contains mappings from MAC addresses to objects that themselves each contain "ip" and "name" string fields. See the sample request/response for more details.`,
// Computed: true,
// Optional: true,
// },
"group_policy_id": schema.StringAttribute{
MarkdownDescription: `The id of the desired group policy to apply to the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"id": schema.StringAttribute{
MarkdownDescription: `The VLAN ID of the VLAN`,
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
SuppressDiffString(),
},
},
"interface_id": schema.StringAttribute{
MarkdownDescription: `The interface ID of the VLAN`,
Computed: true,
},
"ipv6": schema.SingleNestedAttribute{
MarkdownDescription: `IPv6 configuration on the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
Attributes: map[string]schema.Attribute{
"enabled": schema.BoolAttribute{
MarkdownDescription: `Enable IPv6 on VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(),
},
},
"prefix_assignments": schema.SetNestedAttribute{
MarkdownDescription: `Prefix assignments on the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"autonomous": schema.BoolAttribute{
MarkdownDescription: `Auto assign a /64 prefix from the origin to the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(),
},
},
"origin": schema.SingleNestedAttribute{
MarkdownDescription: `The origin of the prefix`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
Attributes: map[string]schema.Attribute{
"interfaces": schema.SetAttribute{
MarkdownDescription: `Interfaces associated with the prefix`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
ElementType: types.StringType,
},
"type": schema.StringAttribute{
MarkdownDescription: `Type of the origin`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.OneOf(
"independent",
"internet",
),
},
},
},
},
"static_appliance_ip6": schema.StringAttribute{
MarkdownDescription: `Manual configuration of the IPv6 Appliance IP`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"static_prefix": schema.StringAttribute{
MarkdownDescription: `Manual configuration of a /64 prefix on the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
},
},
},
},
"mandatory_dhcp": schema.SingleNestedAttribute{
MarkdownDescription: `Mandatory DHCP will enforce that clients connecting to this VLAN must use the IP address assigned by the DHCP server. Clients who use a static IP address won't be able to associate. Only available on firmware versions 17.0 and above`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
Attributes: map[string]schema.Attribute{
"enabled": schema.BoolAttribute{
MarkdownDescription: `Enable Mandatory DHCP on VLAN.`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(),
},
},
},
},
"mask": schema.Int64Attribute{
MarkdownDescription: `Mask used for the subnet of all bound to the template networks. Applicable only for template network.`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Int64{
int64planmodifier.UseStateForUnknown(),
},
},
"name": schema.StringAttribute{
MarkdownDescription: `The name of the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"network_id": schema.StringAttribute{
MarkdownDescription: `networkId path parameter. Network ID`,
Required: true,
},
"reserved_ip_ranges": schema.SetNestedAttribute{
MarkdownDescription: `The DHCP reserved IP ranges on the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"comment": schema.StringAttribute{
MarkdownDescription: `A text comment for the reserved range`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"end": schema.StringAttribute{
MarkdownDescription: `The last IP in the reserved range`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"start": schema.StringAttribute{
MarkdownDescription: `The first IP in the reserved range`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
},
},
"subnet": schema.StringAttribute{
MarkdownDescription: `The subnet of the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"template_vlan_type": schema.StringAttribute{
MarkdownDescription: `Type of subnetting of the VLAN. Applicable only for template network.`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.OneOf(
"same",
"unique",
),
},
},
"vpn_nat_subnet": schema.StringAttribute{
MarkdownDescription: `The translated VPN subnet if VPN and VPN subnet translation are enabled on the VLAN`,
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
}
}
//path params to set ['vlanId']
//path params to assign NOT EDITABLE ['id']
func (r *NetworksApplianceVLANsResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
// Retrieve values from plan
var data NetworksApplianceVLANsRs
var item types.Object
resp.Diagnostics.Append(req.Plan.Get(ctx, &item)...)
if resp.Diagnostics.HasError() {
return
}
resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{
UnhandledNullAsEmpty: true,
UnhandledUnknownAsEmpty: true,
})...)
if resp.Diagnostics.HasError() {
return
}
//Has Paths
vvNetworkID := data.NetworkID.ValueString()
// network_id
vvID := data.ID.ValueString()
//Items
responseVerifyItem, restyResp1, err := r.client.Appliance.GetNetworkApplianceVLAN(vvNetworkID, vvID)
//Have Create
if err != nil || restyResp1 == nil {
if restyResp1.StatusCode() != 404 {
resp.Diagnostics.AddError(
"Failure when executing GetNetworkApplianceVLANs",
restyResp1.String(),
)
return
}
}
if responseVerifyItem != nil {
data = ResponseApplianceGetNetworkApplianceVLANItemToBodyRs(data, responseVerifyItem, false)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
return
}
dataRequest := data.toSdkApiRequestCreate(ctx)
response, restyResp2, err := r.client.Appliance.CreateNetworkApplianceVLAN(vvNetworkID, dataRequest)
if err != nil || restyResp2 == nil || response == nil {
if restyResp2 != nil {
resp.Diagnostics.AddError(
"Failure when executing CreateNetworkApplianceVLAN",
restyResp2.String(),
)
return
}
resp.Diagnostics.AddError(
"Failure when executing CreateNetworkApplianceVLAN",
err.Error(),
)
return
}
//Items
responseGet, restyResp1, err := r.client.Appliance.GetNetworkApplianceVLAN(vvNetworkID, vvID)
// Has item and has items
if err != nil || responseGet == nil {
if restyResp1 != nil {
resp.Diagnostics.AddError(
"Failure when executing GetNetworkApplianceVLANs",
restyResp1.String(),
)
return
}
resp.Diagnostics.AddError(
"Failure when executing GetNetworkApplianceVLANs",
err.Error(),
)
return
}
if responseGet != nil {
data = ResponseApplianceGetNetworkApplianceVLANItemToBodyRs(data, responseGet, false)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
return
} else {
if restyResp1 != nil {
resp.Diagnostics.AddError(
"Failure when executing GetNetworkApplianceVLAN",
restyResp1.String(),
)
return
}
}
}
func (r *NetworksApplianceVLANsResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var data NetworksApplianceVLANsRs
var item types.Object
resp.Diagnostics.Append(req.State.Get(ctx, &item)...)
if resp.Diagnostics.HasError() {
return
}
resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{
UnhandledNullAsEmpty: true,
UnhandledUnknownAsEmpty: true,
})...)
if resp.Diagnostics.HasError() {
return
}
//Has Paths
// Has Item2
vvNetworkID := data.NetworkID.ValueString()
// network_id
vvVLANID := data.ID.ValueString()
// vlan_id
responseGet, restyRespGet, err := r.client.Appliance.GetNetworkApplianceVLAN(vvNetworkID, vvVLANID)
if err != nil || restyRespGet == nil {
if restyRespGet != nil {
if restyRespGet.StatusCode() == 404 {
resp.Diagnostics.AddWarning(
"Resource not found",
"Deleting resource",
)
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError(
"Failure when executing GetNetworkApplianceVLAN",
err.Error(),
)
return
}
resp.Diagnostics.AddError(
"Failure when executing GetNetworkApplianceVLAN",
err.Error(),
)
return
}
data = ResponseApplianceGetNetworkApplianceVLANItemToBodyRs(data, responseGet, true)
diags := resp.State.Set(ctx, &data)
//update path params assigned
resp.Diagnostics.Append(diags...)
}
func (r *NetworksApplianceVLANsResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
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: attr_one,attr_two. Got: %q", req.ID),
)
return
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("network_id"), idParts[0])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...)
}
func (r *NetworksApplianceVLANsResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data NetworksApplianceVLANsRs
merge(ctx, req, resp, &data)
if resp.Diagnostics.HasError() {
return
}
//Has Paths
//Update
//Path Params
vvNetworkID := data.NetworkID.ValueString()
// network_id
vvVLANID := data.ID.ValueString()
dataRequest := data.toSdkApiRequestUpdate(ctx)
response, restyResp2, err := r.client.Appliance.UpdateNetworkApplianceVLAN(vvNetworkID, vvVLANID, dataRequest)
if err != nil || restyResp2 == nil || response == nil {
if restyResp2 != nil {
resp.Diagnostics.AddError(
"Failure when executing UpdateNetworkApplianceVLAN",
err.Error(),
)
return
}
resp.Diagnostics.AddError(
"Failure when executing UpdateNetworkApplianceVLAN",
err.Error(),
)
return
}
resp.Diagnostics.Append(req.Plan.Set(ctx, &data)...)
diags := resp.State.Set(ctx, &data)
resp.Diagnostics.Append(diags...)
}
func (r *NetworksApplianceVLANsResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var state NetworksApplianceVLANsRs
var item types.Object
resp.Diagnostics.Append(req.State.Get(ctx, &item)...)
if resp.Diagnostics.HasError() {
return
}
resp.Diagnostics.Append(item.As(ctx, &state, basetypes.ObjectAsOptions{
UnhandledNullAsEmpty: true,
UnhandledUnknownAsEmpty: true,
})...)
if resp.Diagnostics.HasError() {
return
}
vvNetworkID := state.NetworkID.ValueString()
vvVLANID := state.ID.ValueString()
_, err := r.client.Appliance.DeleteNetworkApplianceVLAN(vvNetworkID, vvVLANID)
if err != nil {
resp.Diagnostics.AddError(
"Failure when executing DeleteNetworkApplianceVLAN", err.Error())
return
}
resp.State.RemoveResource(ctx)
}
// TF Structs Schema
type NetworksApplianceVLANsRs struct {
NetworkID types.String `tfsdk:"network_id"`
ApplianceIP types.String `tfsdk:"appliance_ip"`
Cidr types.String `tfsdk:"cidr"`
DhcpBootFilename types.String `tfsdk:"dhcp_boot_filename"`
DhcpBootNextServer types.String `tfsdk:"dhcp_boot_next_server"`
DhcpBootOptionsEnabled types.Bool `tfsdk:"dhcp_boot_options_enabled"`
DhcpHandling types.String `tfsdk:"dhcp_handling"`
DhcpLeaseTime types.String `tfsdk:"dhcp_lease_time"`
DhcpOptions *[]ResponseApplianceGetNetworkApplianceVlanDhcpOptionsRs `tfsdk:"dhcp_options"`
DhcpRelayServerIPs types.Set `tfsdk:"dhcp_relay_server_ips"`
DNSNameservers types.String `tfsdk:"dns_nameservers"`
// FixedIPAssignments *ResponseApplianceGetNetworkApplianceVlanFixedIpAssignmentsRs `tfsdk:"fixed_ip_assignments"`
GroupPolicyID types.String `tfsdk:"group_policy_id"`
ID types.String `tfsdk:"id"`
InterfaceID types.String `tfsdk:"interface_id"`
IPv6 *ResponseApplianceGetNetworkApplianceVlanIpv6Rs `tfsdk:"ipv6"`
MandatoryDhcp *ResponseApplianceGetNetworkApplianceVlanMandatoryDhcpRs `tfsdk:"mandatory_dhcp"`
Mask types.Int64 `tfsdk:"mask"`
Name types.String `tfsdk:"name"`
ReservedIPRanges *[]ResponseApplianceGetNetworkApplianceVlanReservedIpRangesRs `tfsdk:"reserved_ip_ranges"`
Subnet types.String `tfsdk:"subnet"`
TemplateVLANType types.String `tfsdk:"template_vlan_type"`
VpnNatSubnet types.String `tfsdk:"vpn_nat_subnet"`
}
type ResponseApplianceGetNetworkApplianceVlanDhcpOptionsRs struct {
Code types.String `tfsdk:"code"`
Type types.String `tfsdk:"type"`
Value types.String `tfsdk:"value"`
}
type ResponseApplianceGetNetworkApplianceVlanFixedIpAssignmentsRs interface{}
type ResponseApplianceGetNetworkApplianceVlanIpv6Rs struct {
Enabled types.Bool `tfsdk:"enabled"`
PrefixAssignments *[]ResponseApplianceGetNetworkApplianceVlanIpv6PrefixAssignmentsRs `tfsdk:"prefix_assignments"`
}
type ResponseApplianceGetNetworkApplianceVlanIpv6PrefixAssignmentsRs struct {
Autonomous types.Bool `tfsdk:"autonomous"`
Origin *ResponseApplianceGetNetworkApplianceVlanIpv6PrefixAssignmentsOriginRs `tfsdk:"origin"`
StaticApplianceIP6 types.String `tfsdk:"static_appliance_ip6"`
StaticPrefix types.String `tfsdk:"static_prefix"`
}
type ResponseApplianceGetNetworkApplianceVlanIpv6PrefixAssignmentsOriginRs struct {
Interfaces types.Set `tfsdk:"interfaces"`
Type types.String `tfsdk:"type"`
}
type ResponseApplianceGetNetworkApplianceVlanMandatoryDhcpRs struct {
Enabled types.Bool `tfsdk:"enabled"`
}
type ResponseApplianceGetNetworkApplianceVlanReservedIpRangesRs struct {
Comment types.String `tfsdk:"comment"`
End types.String `tfsdk:"end"`
Start types.String `tfsdk:"start"`
}
// FromBody
func (r *NetworksApplianceVLANsRs) toSdkApiRequestCreate(ctx context.Context) *merakigosdk.RequestApplianceCreateNetworkApplianceVLAN {
log.Printf("ResquestCreate: %v", r.IPv6)
emptyString := ""
applianceIP := new(string)
if !r.ApplianceIP.IsUnknown() && !r.ApplianceIP.IsNull() {
*applianceIP = r.ApplianceIP.ValueString()
} else {
applianceIP = &emptyString
}
cidr := new(string)
if !r.Cidr.IsUnknown() && !r.Cidr.IsNull() {
*cidr = r.Cidr.ValueString()
} else {
cidr = &emptyString
}
groupPolicyID := new(string)
if !r.GroupPolicyID.IsUnknown() && !r.GroupPolicyID.IsNull() {
*groupPolicyID = r.GroupPolicyID.ValueString()
} else {
groupPolicyID = &emptyString
}
iD := new(string)
if !r.ID.IsUnknown() && !r.ID.IsNull() {
iD = r.ID.ValueStringPointer()
} else {
iD = &emptyString
}
var requestApplianceCreateNetworkApplianceVLANIPv6 *merakigosdk.RequestApplianceCreateNetworkApplianceVLANIPv6
if r.IPv6 != nil {
enabled := func() *bool {
if !r.IPv6.Enabled.IsUnknown() && !r.IPv6.Enabled.IsNull() {
return r.IPv6.Enabled.ValueBoolPointer()
}
return nil
}()
var requestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignments []merakigosdk.RequestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignments
if r.IPv6.PrefixAssignments != nil {
for _, rItem1 := range *r.IPv6.PrefixAssignments {
autonomous := func() *bool {
if !rItem1.Autonomous.IsUnknown() && !rItem1.Autonomous.IsNull() {
return rItem1.Autonomous.ValueBoolPointer()
}
return nil
}()
var requestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin *merakigosdk.RequestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin
if rItem1.Origin != nil {
var interfaces []string
rItem1.Origin.Interfaces.ElementsAs(ctx, &interfaces, false)
typeR := rItem1.Origin.Type.ValueString()
requestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin = &merakigosdk.RequestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin{
Interfaces: interfaces,
Type: typeR,
}
}
staticApplianceIP6 := rItem1.StaticApplianceIP6.ValueString()
staticPrefix := rItem1.StaticPrefix.ValueString()
requestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignments = append(requestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignments, merakigosdk.RequestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignments{
Autonomous: autonomous,
Origin: requestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin,
StaticApplianceIP6: staticApplianceIP6,
StaticPrefix: staticPrefix,
})
}
}
requestApplianceCreateNetworkApplianceVLANIPv6 = &merakigosdk.RequestApplianceCreateNetworkApplianceVLANIPv6{
Enabled: enabled,
PrefixAssignments: func() *[]merakigosdk.RequestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignments {
if len(requestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignments) > 0 {
return &requestApplianceCreateNetworkApplianceVLANIPv6PrefixAssignments
}
return nil
}(),
}
}
var requestApplianceCreateNetworkApplianceVLANMandatoryDhcp *merakigosdk.RequestApplianceCreateNetworkApplianceVLANMandatoryDhcp
if r.MandatoryDhcp != nil {
enabled := func() *bool {
if !r.MandatoryDhcp.Enabled.IsUnknown() && !r.MandatoryDhcp.Enabled.IsNull() {
return r.MandatoryDhcp.Enabled.ValueBoolPointer()
}
return nil
}()
requestApplianceCreateNetworkApplianceVLANMandatoryDhcp = &merakigosdk.RequestApplianceCreateNetworkApplianceVLANMandatoryDhcp{
Enabled: enabled,
}
}
mask := new(int64)
if !r.Mask.IsUnknown() && !r.Mask.IsNull() {
*mask = r.Mask.ValueInt64()
} else {
mask = nil
}
name := new(string)
if !r.Name.IsUnknown() && !r.Name.IsNull() {
*name = r.Name.ValueString()
} else {
name = &emptyString
}
subnet := new(string)
if !r.Subnet.IsUnknown() && !r.Subnet.IsNull() {
*subnet = r.Subnet.ValueString()
} else {
subnet = &emptyString
}
templateVLANType := new(string)
if !r.TemplateVLANType.IsUnknown() && !r.TemplateVLANType.IsNull() {
*templateVLANType = r.TemplateVLANType.ValueString()
} else {
templateVLANType = &emptyString
}
out := merakigosdk.RequestApplianceCreateNetworkApplianceVLAN{
ApplianceIP: *applianceIP,
Cidr: *cidr,
GroupPolicyID: *groupPolicyID,
ID: *iD,
IPv6: requestApplianceCreateNetworkApplianceVLANIPv6,
MandatoryDhcp: requestApplianceCreateNetworkApplianceVLANMandatoryDhcp,
Mask: int64ToIntPointer(mask),
Name: *name,
Subnet: *subnet,
TemplateVLANType: *templateVLANType,
}
return &out
}
func (r *NetworksApplianceVLANsRs) toSdkApiRequestUpdate(ctx context.Context) *merakigosdk.RequestApplianceUpdateNetworkApplianceVLAN {
applianceIP := ""
if !r.ApplianceIP.IsUnknown() && !r.ApplianceIP.IsNull() {
applianceIP = r.ApplianceIP.ValueString()
}
cidr := ""
if !r.Cidr.IsUnknown() && !r.Cidr.IsNull() {
cidr = r.Cidr.ValueString()
}
dhcpBootFilename := ""
if !r.DhcpBootFilename.IsUnknown() && !r.DhcpBootFilename.IsNull() {
dhcpBootFilename = r.DhcpBootFilename.ValueString()
}
dhcpBootNextServer := ""
if !r.DhcpBootNextServer.IsUnknown() && !r.DhcpBootNextServer.IsNull() {
dhcpBootNextServer = r.DhcpBootNextServer.ValueString()
}
var dhcpBootOptionsEnabled *bool
if !r.DhcpBootOptionsEnabled.IsUnknown() && !r.DhcpBootOptionsEnabled.IsNull() {
enabled := r.DhcpBootOptionsEnabled.ValueBool()
dhcpBootOptionsEnabled = &enabled
}
dhcpHandling := ""
if !r.DhcpHandling.IsUnknown() && !r.DhcpHandling.IsNull() {
dhcpHandling = r.DhcpHandling.ValueString()
}
dhcpLeaseTime := ""
if !r.DhcpLeaseTime.IsUnknown() && !r.DhcpLeaseTime.IsNull() {
dhcpLeaseTime = r.DhcpLeaseTime.ValueString()
}
var requestApplianceUpdateNetworkApplianceVLANDhcpOptions []merakigosdk.RequestApplianceUpdateNetworkApplianceVLANDhcpOptions
if r.DhcpOptions != nil {
for _, rItem1 := range *r.DhcpOptions {
code := rItem1.Code.ValueString()
typeR := rItem1.Type.ValueString()
value := rItem1.Value.ValueString()
requestApplianceUpdateNetworkApplianceVLANDhcpOptions = append(requestApplianceUpdateNetworkApplianceVLANDhcpOptions, merakigosdk.RequestApplianceUpdateNetworkApplianceVLANDhcpOptions{
Code: code,
Type: typeR,
Value: value,
})
}
}
var dhcpRelayServerIPs []string
r.DhcpRelayServerIPs.ElementsAs(ctx, &dhcpRelayServerIPs, false)
dNSNameservers := ""
if !r.DNSNameservers.IsUnknown() && !r.DNSNameservers.IsNull() {
dNSNameservers = r.DNSNameservers.ValueString()
}
// requestApplianceUpdateNetworkApplianceVLANFixedIPAssignments := r.FixedIPAssignments.ValueString()
// var intf interface{} = requestApplianceUpdateNetworkApplianceVLANFixedIPAssignments
// requestApplianceUpdateNetworkApplianceVLANFixedIPAssignments2, ok := intf.(merakigosdk.RequestApplianceUpdateNetworkApplianceVLANFixedIPAssignments)
// if !ok {
// requestApplianceUpdateNetworkApplianceVLANFixedIPAssignments2 = nil
// }
groupPolicyID := ""
if !r.GroupPolicyID.IsUnknown() && !r.GroupPolicyID.IsNull() {
groupPolicyID = r.GroupPolicyID.ValueString()
}
var requestApplianceUpdateNetworkApplianceVLANIPv6 *merakigosdk.RequestApplianceUpdateNetworkApplianceVLANIPv6
if r.IPv6 != nil {
enabled := func() *bool {
if !r.IPv6.Enabled.IsUnknown() && !r.IPv6.Enabled.IsNull() {
return r.IPv6.Enabled.ValueBoolPointer()
}
return nil
}()
var requestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignments []merakigosdk.RequestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignments
if r.IPv6.PrefixAssignments != nil && len(*r.IPv6.PrefixAssignments) > 0 {
for _, rItem1 := range *r.IPv6.PrefixAssignments {
autonomous := func() *bool {
if !rItem1.Autonomous.IsUnknown() && !rItem1.Autonomous.IsNull() {
return rItem1.Autonomous.ValueBoolPointer()
}
return nil
}()
var requestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin *merakigosdk.RequestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin
if rItem1.Origin != nil {
var interfaces []string
rItem1.Origin.Interfaces.ElementsAs(ctx, &interfaces, false)
typeR := rItem1.Origin.Type.ValueString()
requestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin = &merakigosdk.RequestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin{
Interfaces: interfaces,
Type: typeR,
}
}
staticApplianceIP6 := rItem1.StaticApplianceIP6.ValueString()
staticPrefix := rItem1.StaticPrefix.ValueString()
requestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignments = append(requestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignments, merakigosdk.RequestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignments{
Autonomous: autonomous,
Origin: requestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignmentsOrigin,
StaticApplianceIP6: staticApplianceIP6,
StaticPrefix: staticPrefix,
})
}
}
requestApplianceUpdateNetworkApplianceVLANIPv6 = &merakigosdk.RequestApplianceUpdateNetworkApplianceVLANIPv6{
Enabled: enabled,
PrefixAssignments: func() *[]merakigosdk.RequestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignments {
if len(requestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignments) > 0 {
return &requestApplianceUpdateNetworkApplianceVLANIPv6PrefixAssignments
}
return nil
}(),
}
}
var requestApplianceUpdateNetworkApplianceVLANMandatoryDhcp *merakigosdk.RequestApplianceUpdateNetworkApplianceVLANMandatoryDhcp
if r.MandatoryDhcp != nil {
enabled := func() *bool {
if !r.MandatoryDhcp.Enabled.IsUnknown() && !r.MandatoryDhcp.Enabled.IsNull() {
return r.MandatoryDhcp.Enabled.ValueBoolPointer()
}
return nil
}()
requestApplianceUpdateNetworkApplianceVLANMandatoryDhcp = &merakigosdk.RequestApplianceUpdateNetworkApplianceVLANMandatoryDhcp{
Enabled: enabled,
}
}
mask := new(int64)
if !r.Mask.IsUnknown() && !r.Mask.IsNull() {
*mask = r.Mask.ValueInt64()
}
name := ""
if !r.Name.IsUnknown() && !r.Name.IsNull() {
name = r.Name.ValueString()
}
var requestApplianceUpdateNetworkApplianceVLANReservedIPRanges []merakigosdk.RequestApplianceUpdateNetworkApplianceVLANReservedIPRanges
if r.ReservedIPRanges != nil {
for _, rItem1 := range *r.ReservedIPRanges {
comment := rItem1.Comment.ValueString()
end := rItem1.End.ValueString()
start := rItem1.Start.ValueString()
requestApplianceUpdateNetworkApplianceVLANReservedIPRanges = append(requestApplianceUpdateNetworkApplianceVLANReservedIPRanges, merakigosdk.RequestApplianceUpdateNetworkApplianceVLANReservedIPRanges{
Comment: comment,
End: end,
Start: start,
})
}
}
subnet := ""
if !r.Subnet.IsUnknown() && !r.Subnet.IsNull() {
subnet = r.Subnet.ValueString()
}
templateVLANType := ""
if !r.TemplateVLANType.IsUnknown() && !r.TemplateVLANType.IsNull() {
templateVLANType = r.TemplateVLANType.ValueString()
}