/
resource_aviatrix_transit_gateway.go
3418 lines (3172 loc) · 133 KB
/
resource_aviatrix_transit_gateway.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 aviatrix
import (
"context"
"errors"
"fmt"
"log"
"strconv"
"strings"
"sync"
"time"
"github.com/AviatrixSystems/terraform-provider-aviatrix/v2/goaviatrix"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
const (
defaultLearnedCidrApprovalMode = "gateway"
defaultBgpPollingTime = 50
defaultBgpHoldTime = 180
)
func resourceAviatrixTransitGateway() *schema.Resource {
return &schema.Resource{
Create: resourceAviatrixTransitGatewayCreate,
Read: resourceAviatrixTransitGatewayRead,
Update: resourceAviatrixTransitGatewayUpdate,
Delete: resourceAviatrixTransitGatewayDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
SchemaVersion: 1,
MigrateState: resourceAviatrixTransitGatewayMigrateState,
Schema: map[string]*schema.Schema{
"cloud_type": {
Type: schema.TypeInt,
Required: true,
Description: "Type of cloud service provider, requires an integer value. Use 1 for AWS.",
ValidateFunc: validateCloudType,
},
"account_name": {
Type: schema.TypeString,
Required: true,
Description: "This parameter represents the name of a Cloud-Account in Aviatrix controller.",
},
"gw_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Name of the gateway which is going to be created.",
},
"vpc_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "VPC-ID/VNet-Name of cloud provider.",
DiffSuppressFunc: DiffSuppressFuncGatewayVpcId,
},
"vpc_reg": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Region of cloud provider.",
},
"gw_size": {
Type: schema.TypeString,
Required: true,
Description: "Size of the gateway instance.",
},
"subnet": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.IsCIDR,
Description: "Public Subnet Name.",
},
"zone": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateAzureAZ,
Description: "Availability Zone. Only available for cloud_type = 8 (Azure). Must be in the form 'az-n', for example, 'az-2'.",
},
"insane_mode_az": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "AZ of subnet being created for Insane Mode Transit Gateway. Required for AWS if insane_mode is enabled.",
},
"allocate_new_eip": {
Type: schema.TypeBool,
Optional: true,
Default: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return d.Get("enable_private_oob").(bool) || d.Get("private_mode_lb_vpc_id").(string) != ""
},
Description: "If false, reuse an idle address in Elastic IP pool for this gateway. " +
"Otherwise, allocate a new Elastic IP and use it for this gateway.",
},
"ha_subnet": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.IsCIDR,
Description: "HA Subnet. Required for enabling HA for AWS/AWSGov/AWSChina/Azure/OCI/Alibaba Cloud. " +
"Optional for enabling HA for GCP gateway.",
},
"ha_zone": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "HA Zone. Required if enabling HA for GCP. Optional for Azure.",
},
"ha_insane_mode_az": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "AZ of subnet being created for Insane Mode Transit HA Gateway. Required for AWS if insane_mode is enabled and ha_subnet is set.",
},
"ha_gw_size": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "HA Gateway Size. Mandatory if HA is enabled (ha_subnet is set).",
},
"single_az_ha": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Set to 'enabled' if this feature is desired.",
},
"single_ip_snat": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable or disable Source NAT feature in 'single_ip' mode for this container.",
},
"tag_list": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Default: nil,
Deprecated: "Use tags instead.",
Description: "Instance tag of cloud provider.",
},
"enable_hybrid_connection": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Sign of readiness for TGW connection.",
},
"connected_transit": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Specify Connected Transit status.",
},
"insane_mode": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable Insane Mode for Transit. Valid values: true, false. Supported for AWS/AWSGov, GCP, Azure and OCI. If insane mode is enabled, gateway size has to at least be c5 size for AWS and Standard_D3_v2 size for Azure.",
},
"enable_firenet": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Specify whether to enable firenet interfaces or not.",
},
"enable_gateway_load_balancer": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable firenet interfaces with AWS Gateway Load Balancer. Only valid when `enable_firenet` or `enable_transit_firenet`" +
" are set to true and `cloud_type` = 1 (AWS). Currently AWS Gateway Load Balancer is only supported " +
"in AWS regions us-west-2 and us-east-1. Valid values: true or false. Default value: false.",
},
"enable_vpc_dns_server": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable vpc_dns_server for Gateway. Valid values: true, false.",
},
"enable_advertise_transit_cidr": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Switch to Enable/Disable advertise transit VPC network CIDR.",
},
"bgp_manual_spoke_advertise_cidrs": {
Type: schema.TypeString,
Optional: true,
Default: "",
DiffSuppressFunc: DiffSuppressFuncIgnoreSpaceInString,
Description: "Intended CIDR list to be advertised to external bgp router.",
},
"enable_encrypt_volume": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable encrypt gateway EBS volume. Only supported for AWS and AWSGov providers. Valid values: true, false. Default value: false.",
},
"customized_spoke_vpc_routes": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "A list of comma separated CIDRs to be customized for the spoke VPC routes. When configured, " +
"it will replace all learned routes in VPC routing tables, including RFC1918 and non-RFC1918 CIDRs. " +
"It applies to all spoke gateways attached to this transit gateway.",
},
"filtered_spoke_vpc_routes": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "A list of comma separated CIDRs to be filtered from the spoke VPC route table. When configured, " +
"filtering CIDR(s) or it’s subnet will be deleted from VPC routing tables as well as from spoke gateway’s " +
"routing table. It applies to all spoke gateways attached to this transit gateway.",
},
"excluded_advertised_spoke_routes": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "A list of comma separated CIDRs to be advertised to on-prem as 'Excluded CIDR List'. " +
"When configured, it inspects all the advertised CIDRs from its spoke gateways and " +
"remove those included in the 'Excluded CIDR List'.",
},
"customized_transit_vpc_routes": {
Type: schema.TypeSet,
Optional: true,
Description: "A list of CIDRs to be customized for the transit VPC routes. " +
"When configured, it will replace all learned routes in VPC routing tables, including RFC1918 and non-RFC1918 CIDRs." +
"To be effective, `enable_advertise_transit_cidr` or firewall management access for a transit firenet gateway must be enabled.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"customer_managed_keys": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "Customer managed key ID.",
},
"enable_egress_transit_firenet": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Specify whether to enable egress transit firenet interfaces or not.",
},
"enable_preserve_as_path": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable preserve as_path when advertising manual summary cidrs on transit gateway.",
},
"enable_transit_firenet": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Specify whether to enable transit firenet interfaces or not.",
},
"lan_vpc_id": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: DiffSuppressFuncGCPVpcId,
Description: "LAN VPC ID. Only used for GCP Transit FireNet.",
},
"lan_private_subnet": {
Type: schema.TypeString,
Optional: true,
Description: "LAN Private Subnet. Only used for GCP Transit FireNet.",
},
"enable_learned_cidrs_approval": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Switch to enable/disable encrypted transit approval for transit Gateway. Valid values: true, false.",
},
"learned_cidrs_approval_mode": {
Type: schema.TypeString,
Optional: true,
Default: defaultLearnedCidrApprovalMode,
ValidateFunc: validation.StringInSlice([]string{"gateway", "connection"}, false),
Description: "Set the learned CIDRs approval mode. Only valid when 'enable_learned_cidrs_approval' is " +
"set to true. If set to 'gateway', learned CIDR approval applies to ALL connections. If set to " +
"'connection', learned CIDR approval is configured on a per connection basis. When configuring per " +
"connection, use the enable_learned_cidrs_approval attribute within the connection resource to " +
"toggle learned CIDR approval. Valid values: 'gateway' or 'connection'. Default value: 'gateway'.",
},
"approved_learned_cidrs": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.IsCIDR,
},
Optional: true,
Description: "Approved learned CIDRs. Available as of provider version R2.21+.",
},
"bgp_polling_time": {
Type: schema.TypeString,
Optional: true,
Default: "50",
Description: "BGP route polling time. Unit is in seconds. Valid values are between 10 and 50.",
},
"prepend_as_path": {
Type: schema.TypeList,
Optional: true,
RequiredWith: []string{"local_as_number"},
Description: "List of AS numbers to populate BGP AP_PATH field when it advertises to VGW or peer devices.",
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: goaviatrix.ValidateASN,
},
},
"bgp_ecmp": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable Equal Cost Multi Path (ECMP) routing for the next hop.",
},
"enable_s2c_rx_balancing": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable S2C receive packet CPU re-balancing on transit gateway.",
},
"enable_segmentation": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable segmentation to allow association of transit gateway to security domains.",
},
"enable_active_standby": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enables Active-Standby Mode, available only with HA enabled.",
},
"enable_active_standby_preemptive": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enables Preemptive Mode for Active-Standby, available only with Active-Standby enabled.",
},
"enable_monitor_gateway_subnets": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable [monitor gateway subnets](https://docs.aviatrix.com/HowTos/gateway.html#monitor-gateway-subnet). " +
"Only valid for cloud_type = 1 (AWS) or 256 (AWSGov). Valid values: true, false. Default value: false.",
},
"monitor_exclude_list": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "A set of monitored instance ids. Only valid when 'enable_monitor_gateway_subnets' = true.",
},
"enable_bgp_over_lan": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
Description: "Pre-allocate a network interface(eth4) for \"BGP over LAN\" functionality. Only valid for cloud_type = 4 (GCP) and 8 (Azure). Valid values: true or false. Default value: false. Available as of provider version R2.18+",
},
"bgp_lan_interfaces": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: "Interfaces to run BGP protocol on top of the ethernet interface, to connect to the onprem/remote peer. Only available for GCP Transit.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vpc_id": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: DiffSuppressFuncGCPVpcId,
Description: "VPC-ID of GCP cloud provider.",
},
"subnet": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.IsCIDR,
Description: "Subnet Info.",
},
},
},
},
"ha_bgp_lan_interfaces": {
Type: schema.TypeList,
Optional: true,
Description: "Interfaces to run BGP protocol on top of the ethernet interface, to connect to the onprem/remote peer. Only available for GCP HA Transit.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vpc_id": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: DiffSuppressFuncGCPVpcId,
Description: "VPC-ID of GCP cloud provider.",
},
"subnet": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.IsCIDR,
Description: "Subnet Info.",
},
},
},
},
"bgp_lan_interfaces_count": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(1),
Description: "Number of interfaces that will be created for BGP over LAN enabled Azure transit.",
},
"enable_private_oob": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable private OOB.",
},
"oob_management_subnet": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.IsCIDR,
Description: "OOB management subnet.",
},
"oob_availability_zone": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "OOB subnet availability zone.",
},
"ha_oob_management_subnet": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.IsCIDR,
Description: "OOB HA management subnet.",
},
"ha_oob_availability_zone": {
Type: schema.TypeString,
Optional: true,
Description: "OOB HA availability zone.",
},
"enable_jumbo_frame": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Enable jumbo frame support for transit gateway. Valid values: true or false. Default value: true.",
},
"bgp_hold_time": {
Type: schema.TypeInt,
Optional: true,
Default: defaultBgpHoldTime,
ValidateFunc: validation.IntBetween(12, 360),
Description: "BGP Hold Time.",
},
"enable_transit_summarize_cidr_to_tgw": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable summarize CIDR to TGW.",
},
"enable_multi_tier_transit": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable Multi-tier Transit mode on transit gateway.",
},
"tags": {
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Description: "A map of tags to assign to the transit gateway.",
ConflictsWith: []string{"tag_list"},
},
"enable_spot_instance": {
Type: schema.TypeBool,
Optional: true,
Description: "Enable spot instance. NOT supported for production deployment.",
RequiredWith: []string{"spot_price"},
},
"spot_price": {
Type: schema.TypeString,
Optional: true,
Description: "Price for spot instance. NOT supported for production deployment.",
RequiredWith: []string{"enable_spot_instance"},
},
"rx_queue_size": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"1K", "2K", "4K", "8K", "16K"}, false),
Description: "Gateway ethernet interface RX queue size. Supported for AWS related clouds only.",
},
"private_mode_lb_vpc_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Private Mode Controller load balancer VPC ID. Required when private mode is enabled for the Controller.",
ConflictsWith: []string{"allocate_new_eip"},
},
"private_mode_subnet_zone": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Private Mode subnet availability zone.",
},
"ha_private_mode_subnet_zone": {
Type: schema.TypeString,
Optional: true,
Description: " Private Mode HA subnet availability zone.",
},
"availability_domain": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "Availability domain for OCI.",
},
"fault_domain": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "Fault domain for OCI.",
},
"ha_availability_domain": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "HA availability domain for OCI.",
},
"ha_fault_domain": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "HA fault domain for OCI.",
},
"eip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.IsIPAddress,
Description: "Required when allocate_new_eip is false. It uses specified EIP for this gateway.",
},
"ha_eip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.IsIPAddress,
Description: "Public IP address that you want assigned to the HA Transit Gateway.",
},
"azure_eip_name_resource_group": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The name of the public IP address and its resource group in Azure to assign to this Transit Gateway.",
ValidateFunc: validateAzureEipNameResourceGroup,
},
"ha_azure_eip_name_resource_group": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The name of the public IP address and its resource group in Azure to assign to the HA Transit Gateway.",
ValidateFunc: validateAzureEipNameResourceGroup,
},
"local_as_number": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Changes the Aviatrix Transit Gateway ASN number before you setup Aviatrix Transit Gateway connection configurations.",
ValidateFunc: goaviatrix.ValidateASN,
},
"tunnel_detection_time": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(20, 600),
Description: "The IPSec tunnel down detection time for the transit gateway.",
},
"software_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "software_version can be used to set the desired software version of the gateway. " +
"If set, we will attempt to update the gateway to the specified version. " +
"If left blank, the gateway software version will continue to be managed through the aviatrix_controller_config resource.",
},
"ha_software_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "ha_software_version can be used to set the desired software version of the HA gateway. " +
"If set, we will attempt to update the gateway to the specified version. " +
"If left blank, the gateway software version will continue to be managed through the aviatrix_controller_config resource.",
},
"image_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "image_version can be used to set the desired image version of the gateway. " +
"If set, we will attempt to update the gateway to the specified version.",
},
"ha_image_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "ha_image_version can be used to set the desired image version of the HA gateway. " +
"If set, we will attempt to update the gateway to the specified version.",
},
"security_group_id": {
Type: schema.TypeString,
Computed: true,
Description: "Security group used for the transit gateway.",
},
"ha_security_group_id": {
Type: schema.TypeString,
Computed: true,
Description: "HA security group used for the transit gateway.",
},
"cloud_instance_id": {
Type: schema.TypeString,
Computed: true,
Description: "Instance ID of the transit gateway.",
},
"private_ip": {
Type: schema.TypeString,
Computed: true,
Description: "Private IP address of the transit gateway created.",
},
"ha_cloud_instance_id": {
Type: schema.TypeString,
Computed: true,
Description: "Cloud instance ID of HA transit gateway.",
},
"ha_gw_name": {
Type: schema.TypeString,
Computed: true,
Description: "Aviatrix transit gateway unique name of HA transit gateway.",
},
"ha_private_ip": {
Type: schema.TypeString,
Computed: true,
Description: "Private IP address of HA transit gateway.",
},
"lan_interface_cidr": {
Type: schema.TypeString,
Computed: true,
Description: "Transit gateway lan interface cidr.",
},
"ha_lan_interface_cidr": {
Type: schema.TypeString,
Computed: true,
Description: "Transit gateway lan interface cidr for the HA gateway.",
},
"bgp_lan_ip_list": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Description: "List of available BGP LAN interface IPs for transit external device connection creation. " +
"Only supports GCP and Azure. Available as of provider version R2.21.0+.",
},
"ha_bgp_lan_ip_list": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Description: "List of available BGP LAN interface IPs for transit external device HA connection creation. " +
"Only supports GCP and Azure. Available as of provider version R2.21.0+.",
},
"public_ip": {
Type: schema.TypeString,
Computed: true,
Description: "Public IP address of the Transit Gateway created.",
},
"ha_public_ip": {
Type: schema.TypeString,
Computed: true,
Description: "Public IP address of the HA Transit Gateway.",
},
},
}
}
func resourceAviatrixTransitGatewayCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
gateway := &goaviatrix.TransitVpc{
CloudType: d.Get("cloud_type").(int),
AccountName: d.Get("account_name").(string),
GwName: d.Get("gw_name").(string),
VpcID: d.Get("vpc_id").(string),
VpcSize: d.Get("gw_size").(string),
Subnet: d.Get("subnet").(string),
EnableHybridConnection: d.Get("enable_hybrid_connection").(bool),
EnableSummarizeCidrToTgw: d.Get("enable_transit_summarize_cidr_to_tgw").(bool),
AvailabilityDomain: d.Get("availability_domain").(string),
FaultDomain: d.Get("fault_domain").(string),
ApprovedLearnedCidrs: getStringSet(d, "approved_learned_cidrs"),
}
enableNAT := d.Get("single_ip_snat").(bool)
if enableNAT {
gateway.EnableNAT = "yes"
} else {
gateway.EnableNAT = "no"
}
singleAZ := d.Get("single_az_ha").(bool)
if singleAZ {
gateway.SingleAzHa = "enabled"
} else {
gateway.SingleAzHa = "disabled"
}
connectedTransit := d.Get("connected_transit").(bool)
if connectedTransit {
gateway.ConnectedTransit = "yes"
} else {
gateway.ConnectedTransit = "no"
}
cloudType := d.Get("cloud_type").(int)
zone := d.Get("zone").(string)
if !goaviatrix.IsCloudType(cloudType, goaviatrix.Azure) && zone != "" {
return fmt.Errorf("attribute 'zone' is only for use with cloud_type = 8 (Azure)")
}
if zone != "" {
// The API uses the same string field to hold both subnet and zone
// parameters.
gateway.Subnet = fmt.Sprintf("%s~~%s~~", d.Get("subnet").(string), zone)
}
if goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes|goaviatrix.GCPRelatedCloudTypes|goaviatrix.OCIRelatedCloudTypes|goaviatrix.AliCloudRelatedCloudTypes) {
gateway.VpcID = d.Get("vpc_id").(string)
if gateway.VpcID == "" {
return fmt.Errorf("'vpc_id' cannot be empty for creating a transit gw")
}
} else if goaviatrix.IsCloudType(cloudType, goaviatrix.AzureArmRelatedCloudTypes) {
gateway.VNetNameResourceGroup = d.Get("vpc_id").(string)
if gateway.VNetNameResourceGroup == "" {
return fmt.Errorf("'vpc_id' cannot be empty for creating a transit gw")
}
} else {
return fmt.Errorf("invalid cloud type, it can only be AWS (1), GCP (4), Azure (8), OCI (16), AzureGov (32), AWSGov (256), AWSChina (1024), AzureChina (2048), Alibaba Cloud (8192), AWS Top Secret (16384) or AWS Secret (32768)")
}
if goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes|goaviatrix.AzureArmRelatedCloudTypes|goaviatrix.OCIRelatedCloudTypes|goaviatrix.AliCloudRelatedCloudTypes) {
gateway.VpcRegion = d.Get("vpc_reg").(string)
} else if goaviatrix.IsCloudType(cloudType, goaviatrix.GCPRelatedCloudTypes) {
// for gcp, rest api asks for "zone" rather than vpc region
gateway.Zone = d.Get("vpc_reg").(string)
} else {
return fmt.Errorf("invalid cloud type, it can only be AWS (1), GCP (4), Azure (8), OCI (16), AzureGov (32), AWSGov (256), AWSChina (1024), AzureChina (2048), Alibaba Cloud (8192), AWS Top Secret (16384) or AWS Secret (32768)")
}
insaneMode := d.Get("insane_mode").(bool)
if insaneMode {
// Insane Mode encryption is not supported in China regions
if !goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes|goaviatrix.GCPRelatedCloudTypes|
goaviatrix.AzureArmRelatedCloudTypes|goaviatrix.OCIRelatedCloudTypes) {
return fmt.Errorf("insane_mode is only supported for AWS (1), GCP (4), Azure (8), OCI (16), AzureGov (32), AWSGov (256), AWS China (1024), AzureChina (2048), AWS Top Secret (16384) and AWS Secret (32768)")
}
if goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes) {
if d.Get("insane_mode_az").(string) == "" {
return fmt.Errorf("insane_mode_az needed if insane_mode is enabled for AWS (1), AWSGov (256), AWS China (1024), AWS Top Secret (16384) or AWS Secret (32768)")
}
if d.Get("ha_subnet").(string) != "" && d.Get("ha_insane_mode_az").(string) == "" {
return fmt.Errorf("ha_insane_mode_az needed if insane_mode is enabled for AWS (1), AWSGov (256), AWS China (1024), AWS Top Secret (16384) or AWS Secret (32768) clouds and ha_subnet is set")
}
// Append availability zone to subnet
var strs []string
insaneModeAz := d.Get("insane_mode_az").(string)
strs = append(strs, gateway.Subnet, insaneModeAz)
gateway.Subnet = strings.Join(strs, "~~")
}
gateway.InsaneMode = "on"
} else {
gateway.InsaneMode = "off"
}
if goaviatrix.IsCloudType(cloudType, goaviatrix.OCIRelatedCloudTypes) && (gateway.AvailabilityDomain == "" || gateway.FaultDomain == "") {
return fmt.Errorf("'availability_domain' and 'fault_domain' are required for OCI")
}
if !goaviatrix.IsCloudType(cloudType, goaviatrix.OCIRelatedCloudTypes) && (gateway.AvailabilityDomain != "" || gateway.FaultDomain != "") {
return fmt.Errorf("'availability_domain' and 'fault_domain' are only valid for OCI")
}
haSubnet := d.Get("ha_subnet").(string)
haZone := d.Get("ha_zone").(string)
haAvailabilityDomain := d.Get("ha_availability_domain").(string)
haFaultDomain := d.Get("ha_fault_domain").(string)
if haZone != "" && !goaviatrix.IsCloudType(cloudType, goaviatrix.GCPRelatedCloudTypes|goaviatrix.AzureArmRelatedCloudTypes) {
return fmt.Errorf("'ha_zone' is only valid for GCP and Azure providers when enabling HA")
}
if goaviatrix.IsCloudType(cloudType, goaviatrix.GCPRelatedCloudTypes) && haSubnet != "" && haZone == "" {
return fmt.Errorf("'ha_zone' must be set to enable HA on GCP, cannot enable HA with only 'ha_subnet'")
}
if goaviatrix.IsCloudType(cloudType, goaviatrix.AzureArmRelatedCloudTypes) && haSubnet == "" && haZone != "" {
return fmt.Errorf("'ha_subnet' must be provided to enable HA on Azure, cannot enable HA with only 'ha_zone'")
}
haGwSize := d.Get("ha_gw_size").(string)
if haSubnet == "" && haZone == "" && haGwSize != "" {
return fmt.Errorf("'ha_gw_size' is only required if enabling HA")
}
if haGwSize == "" && haSubnet != "" {
return fmt.Errorf("A valid non empty ha_gw_size parameter is mandatory for this resource if " +
"ha_subnet is set")
}
if haSubnet != "" {
if goaviatrix.IsCloudType(cloudType, goaviatrix.OCIRelatedCloudTypes) && (haAvailabilityDomain == "" || haFaultDomain == "") {
return fmt.Errorf("'ha_availability_domain' and 'ha_fault_domain' are required to enable Peering HA on OCI")
}
if !goaviatrix.IsCloudType(cloudType, goaviatrix.OCIRelatedCloudTypes) && (haAvailabilityDomain != "" || haFaultDomain != "") {
return fmt.Errorf("'ha_availability_domain' and 'ha_fault_domain' are only valid for OCI")
}
}
enableEncryptVolume := d.Get("enable_encrypt_volume").(bool)
customerManagedKeys := d.Get("customer_managed_keys").(string)
if enableEncryptVolume && !goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes) {
return fmt.Errorf("'enable_encrypt_volume' is only supported for AWS (1), AWSGov (256), AWSChina (1024), AWS Top Secret (16384) or AWS Secret (32768) providers")
}
if customerManagedKeys != "" {
if !enableEncryptVolume {
return fmt.Errorf("'customer_managed_keys' should be empty since Encrypt Volume is not enabled")
}
gateway.EncVolume = "no"
}
if !enableEncryptVolume && goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes) {
gateway.EncVolume = "no"
}
enableFireNet := d.Get("enable_firenet").(bool)
enableGatewayLoadBalancer := d.Get("enable_gateway_load_balancer").(bool)
enableTransitFireNet := d.Get("enable_transit_firenet").(bool)
if enableFireNet && enableTransitFireNet {
return fmt.Errorf("can't enable firenet function and transit firenet function at the same time")
}
lanVpcID := d.Get("lan_vpc_id").(string)
lanPrivateSubnet := d.Get("lan_private_subnet").(string)
// Transit FireNet function is not supported for AWS China or Azure China
if enableFireNet && goaviatrix.IsCloudType(cloudType, goaviatrix.AWSChina|goaviatrix.AzureChina) {
return fmt.Errorf("'enable_firenet' is not supported in AWSChina (1024) or AzureChina (2048)")
}
if enableTransitFireNet {
// Transit FireNet function is not supported for Azure China
if !goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes|goaviatrix.GCPRelatedCloudTypes|goaviatrix.AzureArmRelatedCloudTypes^goaviatrix.AzureChina|goaviatrix.OCIRelatedCloudTypes) {
return fmt.Errorf("'enable_transit_firenet' is only supported in AWS (1), GCP (4), Azure (8), OCI (16), AzureGov (32), AWSGov (256), AWS China (1024), AWS Top Secret (16384) and AWS Secret (32768)")
}
if goaviatrix.IsCloudType(cloudType, goaviatrix.GCPRelatedCloudTypes|goaviatrix.AzureArmRelatedCloudTypes) {
gateway.EnableTransitFireNet = "on"
}
if goaviatrix.IsCloudType(cloudType, goaviatrix.GCPRelatedCloudTypes) {
if lanVpcID == "" || lanPrivateSubnet == "" {
return fmt.Errorf("'lan_vpc_id' and 'lan_private_subnet' are required when 'cloud_type' = 4 (GCP) and 'enable_transit_firenet' = true")
}
gateway.LanVpcID = lanVpcID
gateway.LanPrivateSubnet = lanPrivateSubnet
}
}
if (!enableTransitFireNet || !goaviatrix.IsCloudType(cloudType, goaviatrix.GCPRelatedCloudTypes)) && (lanVpcID != "" || lanPrivateSubnet != "") {
return fmt.Errorf("'lan_vpc_id' and 'lan_private_subnet' are only valid when 'cloud_type' = 4 (GCP) and 'enable_transit_firenet' = true")
}
if enableGatewayLoadBalancer && !enableFireNet && !enableTransitFireNet {
return fmt.Errorf("'enable_gateway_load_balancer' is only valid when 'enable_firenet' or 'enable_transit_firenet' is set to true")
}
if enableGatewayLoadBalancer && !goaviatrix.IsCloudType(cloudType, goaviatrix.AWS) {
return fmt.Errorf("'enable_gateway_load_balancer' is only supported by AWS (1)")
}
enableEgressTransitFireNet := d.Get("enable_egress_transit_firenet").(bool)
// Transit FireNet function is not supported for Azure China
if enableEgressTransitFireNet && !goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes|goaviatrix.GCPRelatedCloudTypes|goaviatrix.AzureArmRelatedCloudTypes^goaviatrix.AzureChina|goaviatrix.OCIRelatedCloudTypes) {
return fmt.Errorf("'enable_egress_transit_firenet' is only supported by AWS (1), GCP (4), Azure (8), OCI (16), AzureGov (32), AWSGov (256), AWS China (1024), AWS Top Secret (16384) and AWS Secret (32768)")
}
if enableEgressTransitFireNet && !enableTransitFireNet {
return fmt.Errorf("'enable_egress_transit_firenet' requires 'enable_transit_firenet' to be set to true")
}
if enableEgressTransitFireNet && connectedTransit {
return fmt.Errorf("'enable_egress_transit_firenet' requires 'connected_transit' to be set to false")
}
enableTransitPreserveAsPath := d.Get("enable_preserve_as_path").(bool)
learnedCidrsApproval := d.Get("enable_learned_cidrs_approval").(bool)
if learnedCidrsApproval {
gateway.LearnedCidrsApproval = "on"
}
if learnedCidrsApproval && d.Get("learned_cidrs_approval_mode").(string) == "connection" {
return fmt.Errorf("'enable_learned_cidrs_approval' must be false if 'learned_cidrs_approval_mode' is set to 'connection'")
}
if !learnedCidrsApproval && len(gateway.ApprovedLearnedCidrs) != 0 {
return fmt.Errorf("'approved_learned_cidrs' must be empty if 'enable_learned_cidrs_approval' is false")
}
enableMonitorSubnets := d.Get("enable_monitor_gateway_subnets").(bool)
var excludedInstances []string
for _, v := range d.Get("monitor_exclude_list").(*schema.Set).List() {
excludedInstances = append(excludedInstances, v.(string))
}
// Enable monitor gateway subnets does not work with AWSChina
if enableMonitorSubnets && !goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes^goaviatrix.AWSChina) {
return fmt.Errorf("'enable_monitor_gateway_subnets' is only valid for AWS (1), AWSGov (256), AWS Top Secret (16384) or AWS Secret (32768)")
}
if !enableMonitorSubnets && len(excludedInstances) != 0 {
return fmt.Errorf("'monitor_exclude_list' must be empty if 'enable_monitor_gateway_subnets' is false")
}
bgpOverLan := d.Get("enable_bgp_over_lan").(bool)
if bgpOverLan && !(goaviatrix.IsCloudType(cloudType, goaviatrix.AzureArmRelatedCloudTypes|goaviatrix.GCP)) {
return fmt.Errorf("'enable_bgp_over_lan' is only valid for GCP (4), Azure (8), AzureGov (32) or AzureChina (2048)")
}
bgpLanInterfacesCount := d.Get("bgp_lan_interfaces_count").(int)
if bgpLanInterfacesCount != 1 && (!bgpOverLan || !goaviatrix.IsCloudType(cloudType, goaviatrix.AzureArmRelatedCloudTypes)) {
return fmt.Errorf("'bgp_lan_interfaces_count' is only valid for BGP over LAN enabled transit for Azure (8), AzureGov (32) or AzureChina (2048)")
}
var bgpLanVpcID []string
var bgpLanSpecifySubnet []string
var haBgpLanVpcID []string
var haBgpLanSpecifySubnet []string
for _, bgpInterface := range d.Get("bgp_lan_interfaces").([]interface{}) {
item := bgpInterface.(map[string]interface{})
bgpLanVpcID = append(bgpLanVpcID, item["vpc_id"].(string))
bgpLanSpecifySubnet = append(bgpLanSpecifySubnet, item["subnet"].(string))
}
for _, haBgpInterface := range d.Get("ha_bgp_lan_interfaces").([]interface{}) {
item := haBgpInterface.(map[string]interface{})
haBgpLanVpcID = append(haBgpLanVpcID, item["vpc_id"].(string))
haBgpLanSpecifySubnet = append(haBgpLanSpecifySubnet, item["subnet"].(string))
}
if !bgpOverLan && len(bgpLanVpcID) != 0 {
return fmt.Errorf("'bgp_lan_interfaces' is only valid with enable_bgp_over_lan being set true")
}
if (!bgpOverLan || haSubnet == "") && len(haBgpLanVpcID) != 0 {
return fmt.Errorf("'ha_bgp_lan_interfaces' is only valid with enable_bgp_over_lan is set true and HA is enabled")
}
if (len(bgpLanVpcID) != 0 || len(haBgpLanVpcID) != 0) && !(goaviatrix.IsCloudType(cloudType, goaviatrix.GCP)) {
return fmt.Errorf("'bgp_lan_interfaces' and 'ha_bgp_lan_interfaces' are only valid for GCP (4)")
}
if bgpOverLan {
gateway.BgpOverLan = "on"
if goaviatrix.IsCloudType(cloudType, goaviatrix.GCP) {
if len(bgpLanVpcID) == 0 {
return fmt.Errorf("missing bgp_lan_interfaces for creating GCP transit gateway with BGP over LAN enabled")
}
if (haSubnet != "" || haZone != "") && len(haBgpLanVpcID) == 0 {
return fmt.Errorf("missing ha_bgp_lan_interfaces for creating GCP HA transit gateway with BGP over LAN enabled")
}
gateway.BgpLanVpcID = strings.Join(bgpLanVpcID, ",")
gateway.BgpLanSpecifySubnet = strings.Join(bgpLanSpecifySubnet, ",")
} else if goaviatrix.IsCloudType(cloudType, goaviatrix.AzureArmRelatedCloudTypes) {
gateway.BgpLanInterfacesCount = bgpLanInterfacesCount
}
}
enablePrivateOob := d.Get("enable_private_oob").(bool)
oobManagementSubnet := d.Get("oob_management_subnet").(string)
oobAvailabilityZone := d.Get("oob_availability_zone").(string)
haOobManagementSubnet := d.Get("ha_oob_management_subnet").(string)
haOobAvailabilityZone := d.Get("ha_oob_availability_zone").(string)
if enablePrivateOob {
if !goaviatrix.IsCloudType(cloudType, goaviatrix.AWSRelatedCloudTypes) {
return fmt.Errorf("'enable_private_oob' is only valid for AWS (1), AWSGov (256) AWSChina (1024),, AWS Top Secret (16384) or AWS Secret (32768)")
}
if oobAvailabilityZone == "" {
return fmt.Errorf("\"oob_availability_zone\" is required if \"enable_private_oob\" is true")
}
if oobManagementSubnet == "" {
return fmt.Errorf("\"oob_management_subnet\" is required if \"enable_private_oob\" is true")
}
if haSubnet != "" {
if haOobAvailabilityZone == "" {
return fmt.Errorf("\"ha_oob_availability_zone\" is required if \"enable_private_oob\" is true and \"ha_subnet\" is provided")
}
if haOobManagementSubnet == "" {
return fmt.Errorf("\"ha_oob_management_subnet\" is required if \"enable_private_oob\" is true and \"ha_subnet\" is provided")
}
} else {
if haOobAvailabilityZone != "" {
return fmt.Errorf("\"ha_oob_availability_zone\" must be empty if \"ha_subnet\" is empty")
}
if haOobManagementSubnet != "" {
return fmt.Errorf("\"ha_oob_management_sbunet\" must be empty if \"ha_subnet\" is empty")
}
}
gateway.EnablePrivateOob = "on"