-
Notifications
You must be signed in to change notification settings - Fork 4
/
resource_aws_cloud_router_connection.go
738 lines (715 loc) · 27.1 KB
/
resource_aws_cloud_router_connection.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
package provider
import (
"context"
"errors"
"fmt"
"reflect"
"time"
"github.com/PacketFabric/terraform-provider-packetfabric/internal/packetfabric"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceRouterConnectionAws() *schema.Resource {
return &schema.Resource{
CreateContext: resourceRouterConnectionAwsCreate,
ReadContext: resourceRouterConnectionAwsRead,
UpdateContext: resourceRouterConnectionAwsUpdate,
DeleteContext: resourceRouterConnectionAwsDelete,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(60 * time.Minute),
Update: schema.DefaultTimeout(60 * time.Minute),
Read: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(60 * time.Minute),
},
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"circuit_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Circuit ID of the target cloud router. This starts with \"PF-L3-CUST-\".",
},
"bgp_settings_uuid": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "BGP session ID generated when the cloud-side connection is provisioned by PacketFabric.",
},
"aws_account_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"PF_AWS_ACCOUNT_ID", "AWS_ACCOUNT_ID"}, nil),
Description: "The AWS account ID to connect with. Must be 12 characters long. " +
"Can also be set with the PF_AWS_ACCOUNT_ID or AWS_ACCOUNT_ID environment variables.",
},
"account_uuid": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DefaultFunc: schema.EnvDefaultFunc("PF_ACCOUNT_ID", nil),
ValidateFunc: validation.IsUUID,
Description: "The UUID for the billing account that should be billed. " +
"Can also be set with the PF_ACCOUNT_ID environment variable.",
},
"maybe_nat": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: "Set this to true if you intend to use NAT on this connection. Defaults: false",
},
"maybe_dnat": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: "Set this to true if you intend to use DNAT on this connection. Defaults: false",
},
"description": {
Type: schema.TypeString,
Required: true,
Description: "A brief description of this connection.",
},
"pop": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The POP in which you want to provision the connection.",
},
"zone": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The desired availability zone of the connection.\n\n\tExample: \"A\"",
},
"is_public": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Default: false,
Description: "Whether PacketFabric should allocate a public IP address for this connection. Set this to true if you intend to use a public VIF on the AWS side. ",
},
"speed": {
Type: schema.TypeString,
Required: true,
Description: "The desired speed of the new connection.\n\n\t Available: 50Mbps 100Mbps 200Mbps 300Mbps 400Mbps 500Mbps 1Gbps 2Gbps 5Gbps 10Gbps",
},
"subscription_term": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
ValidateFunc: validation.IntInSlice([]int{1, 12, 24, 36}),
Description: "Subscription term of the Cloud Router Connection\n\n\tEnum: [\"1\", \"12\", \"24\", \"36\"] ",
},
"published_quote_line_uuid": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.IsUUID,
Description: "UUID of the published quote line which this connection should be associated.",
},
"po_number": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 32),
Description: "Purchase order number or identifier of a service.",
},
"labels": {
Type: schema.TypeSet,
Optional: true,
Description: "Label value linked to an object.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"cloud_provider_connection_id": {
Type: schema.TypeString,
Computed: true,
Description: "The cloud provider specific connection ID, eg. the Amazon connection ID of the cloud router connection.\n\t\tExample: dxcon-fgadaaa1",
},
"vlan_id_pf": {
Type: schema.TypeInt,
Computed: true,
Description: "PacketFabric VLAN ID.",
},
"cloud_settings": {
Type: schema.TypeList,
Optional: true,
Description: "Provision the Cloud side of the connection with PacketFabric.",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"credentials_uuid": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.IsUUID,
Description: "The UUID of the credentials to be used with this connection.",
},
"aws_region": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The AWS region that should be used.",
},
"mtu": {
Type: schema.TypeInt,
Optional: true,
Default: 1500,
ValidateFunc: validation.IntInSlice([]int{1500, 9001}),
Description: "Maximum Transmission Unit this port supports (size of the largest supported PDU).\n\n\tEnum: [\"1500\", \"9001\"] ",
},
"aws_vif_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"private", "transit", "public"}, false),
Description: "The type of VIF to use for this connection.",
},
"aws_gateways": {
Type: schema.TypeList,
Optional: true,
MaxItems: 2,
Description: "Only for Private or Transit VIF.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"directconnect", "private", "transit"}, false),
Description: "The type of this AWS Gateway.",
},
"name": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The name of the AWS Gateway, required if creating a new DirectConnect Gateway.",
},
"id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The ID of the AWS Gateway to be used.",
},
"asn": {
Type: schema.TypeInt,
Optional: true,
Description: "The ASN of the AWS Gateway to be used.",
},
"vpc_id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The AWS VPC ID this Gateway should be associated with. Required for private and transit Gateways.",
},
"subnet_ids": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "An array of subnet IDs to associate with this Gateway. Required for transit Gateways.",
},
},
},
},
"bgp_settings": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"md5": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The MD5 value of the authenticated BGP sessions. Required for AWS.",
},
"l3_address": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The prefix of the customer router. Required for public VIFs.",
},
"remote_address": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The prefix of the remote router. Required for public VIFs.",
},
"local_preference": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The local preference for this instance. When the same route is received in multiple locations, those with a higher local preference value are preferred by the cloud router. It is used when type = in.\n\n\tAvailable range is 1 through 4294967295. ",
},
"med": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The Multi-Exit Discriminator of this instance. When the same route is advertised in multiple locations, those with a lower MED are preferred by the peer AS. It is used when type = out.\n\n\tAvailable range is 1 through 4294967295. ",
},
"as_prepend": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(1, 5),
Description: "The BGP prepend value for this instance. It is used when type = out.\n\n\tAvailable range is 1 through 5. ",
},
"orlonger": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether to use exact match or longer for all prefixes. ",
},
"bfd_interval": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(3, 30000),
Description: "If you are using BFD, this is the interval (in milliseconds) at which to send test packets to peers.\n\n\tAvailable range is 3 through 30000. ",
},
"bfd_multiplier": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(2, 16),
Description: "If you are using BFD, this is the number of consecutive packets that can be lost before BFD considers a peer down and shuts down BGP.\n\n\tAvailable range is 2 through 16. ",
},
"disabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether this BGP session is disabled. ",
},
"nat": {
Type: schema.TypeSet,
MaxItems: 1,
Optional: true,
Description: "Translate the source or destination IP address.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pre_nat_sources": {
Type: schema.TypeList,
Optional: true,
Description: "If using NAT overload, this is the prefixes from the cloud that you want to associate with the NAT pool.\n\n\tExample: 10.0.0.0/24",
Elem: &schema.Schema{
Type: schema.TypeString,
Description: "IP prefix using CIDR format.",
},
},
"pool_prefixes": {
Type: schema.TypeList,
Optional: true,
Description: "If using NAT overload, all prefixes that are NATed on this connection will be translated to the pool prefix address.\n\n\tExample: 10.0.0.0/32",
Elem: &schema.Schema{
Type: schema.TypeString,
Description: "IP prefix using CIDR format.",
},
},
"direction": {
Type: schema.TypeString,
Optional: true,
Default: "output",
ValidateFunc: validation.StringInSlice([]string{"output", "input"}, true),
Description: "If using NAT overload, the direction of the NAT connection (input=ingress, output=egress). \n\t\tEnum: output, input. ",
},
"nat_type": {
Type: schema.TypeString,
Optional: true,
Default: "overload",
ValidateFunc: validation.StringInSlice([]string{"overload", "inline_dnat"}, true),
Description: "The NAT type of the NAT connection, source NAT (overload) or destination NAT (inline_dnat). \n\t\tEnum: overload, inline_dnat. ",
},
"dnat_mappings": {
Type: schema.TypeSet,
Optional: true,
Description: "Translate the destination IP address.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"private_prefix": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateIPAddressWithPrefix,
Description: "Post-translation IP prefix.",
},
"public_prefix": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateIPAddressWithPrefix,
Description: "Pre-translation IP prefix.",
},
"conditional_prefix": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateIPAddressWithPrefix,
Description: "Post-translation prefix must be equal to or included within the conditional IP prefix.",
},
},
},
},
},
},
},
"prefixes": {
Type: schema.TypeSet,
Required: true,
Description: "The list of BGP prefixes",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"prefix": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateIPAddressWithPrefix,
Description: "The actual IP Prefix of this instance.",
},
"match_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"exact", "orlonger"}, true),
Description: "The match type of this prefix.\n\n\tEnum: `\"exact\"` `\"orlonger\"` ",
},
"as_prepend": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(1, 5),
Description: "The BGP prepend value of this prefix. It is used when type = out.\n\n\tAvailable range is 1 through 5. ",
},
"med": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The MED of this prefix. It is used when type = out.\n\n\tAvailable range is 1 through 4294967295. ",
},
"local_preference": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The local_preference of this prefix. It is used when type = in.\n\n\tAvailable range is 1 through 4294967295. ",
},
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"in", "out"}, true),
Description: "Whether this prefix is in (Allowed Prefixes from Cloud) or out (Allowed Prefixes to Cloud).\n\t\tEnum: in, out.",
},
},
},
},
},
},
},
},
},
},
"etl": {
Type: schema.TypeFloat,
Computed: true,
Description: "Early Termination Liability (ETL) fees apply when terminating a service before its term ends. ETL is prorated to the remaining contract days.",
},
},
CustomizeDiff: customdiff.Sequence(
func(_ context.Context, d *schema.ResourceDiff, m interface{}) error {
if d.Id() == "" {
return nil
}
if _, ok := d.GetOk("cloud_settings"); !ok {
return nil
}
attributes := []string{
"cloud_settings.0.aws_region",
"cloud_settings.0.aws_vif_type",
"cloud_settings.0.aws_gateways",
}
for _, attribute := range attributes {
oldRaw, newRaw := d.GetChange(attribute)
if oldRaw != nil && !reflect.DeepEqual(oldRaw, newRaw) {
return fmt.Errorf("updating %s in-place is not supported, delete and recreate the resource with the updated values", attribute)
}
}
return nil
},
),
Importer: &schema.ResourceImporter{
StateContext: CloudRouterImportStatePassthroughContext,
},
}
}
func resourceRouterConnectionAwsCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*packetfabric.PFClient)
c.Ctx = ctx
var diags diag.Diagnostics
awsConn := extractAwsConnection(d)
if cid, ok := d.GetOk("circuit_id"); ok {
cloudSettingsList := d.Get("cloud_settings").([]interface{})
if len(cloudSettingsList) != 0 {
cloudSettings := cloudSettingsList[0].(map[string]interface{})
bgpSettingsList := cloudSettings["bgp_settings"].([]interface{})
if len(bgpSettingsList) != 0 {
bgpSettings := bgpSettingsList[0].(map[string]interface{})
prefixesValue := bgpSettings["prefixes"]
prefixesSet := prefixesValue.(*schema.Set)
prefixesList := prefixesSet.List()
if err := validatePrefixes(prefixesList); err != nil {
return diag.FromErr(err)
}
}
}
resp, err := c.CreateAwsConnection(awsConn, cid.(string))
if err != nil {
return diag.FromErr(err)
}
if err := checkCloudRouterConnectionStatus(c, cid.(string), resp.CloudCircuitID); err != nil {
return diag.FromErr(err)
}
if resp != nil {
d.SetId(resp.CloudCircuitID)
_ = d.Set("subscription_term", resp.Billing.SubscriptionTerm)
if _, ok := d.GetOk("cloud_settings"); !ok {
time.Sleep(90 * time.Second) // wait for the connection to show on AWS
resp, err := c.ReadCloudRouterConnection(cid.(string), resp.CloudCircuitID)
if err != nil {
diags = diag.FromErr(err)
return diags
}
if resp.CloudProviderConnectionID == "" || resp.CloudSettings.VlanIDPf == 0 {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Incomplete Cloud Information",
Detail: "The cloud_provider_connection_id and/or vlan_id_pf are currently unavailable.",
})
return diags
} else {
_ = d.Set("cloud_provider_connection_id", resp.CloudProviderConnectionID)
_ = d.Set("vlan_id_pf", resp.CloudSettings.VlanIDPf)
}
}
if _, ok := d.GetOk("cloud_settings"); ok {
// Extract the BGP settings UUID
resp, err := c.ReadCloudRouterConnection(cid.(string), resp.CloudCircuitID)
if err != nil {
diags = diag.FromErr(err)
return diags
}
if len(resp.BgpStateList) > 0 {
_ = d.Set("bgp_settings_uuid", resp.BgpStateList[0].BgpSettingsUUID)
}
}
if labels, ok := d.GetOk("labels"); ok {
diagnostics, created := createLabels(c, d.Id(), labels)
if !created {
return diagnostics
}
}
}
} else {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Circuit ID not present",
Detail: "Please provide a valid Circuit ID.",
})
}
return diags
}
func resourceRouterConnectionAwsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*packetfabric.PFClient)
c.Ctx = ctx
var diags diag.Diagnostics
circuitID, ok := d.GetOk("circuit_id")
if !ok {
return diag.FromErr(errors.New("please provide a valid Circuit ID"))
}
cloudConnCID := d.Get("id")
resp, err := c.ReadCloudRouterConnection(circuitID.(string), cloudConnCID.(string))
if err != nil {
return diag.FromErr(err)
}
_ = d.Set("account_uuid", resp.AccountUUID)
_ = d.Set("circuit_id", resp.CloudRouterCircuitID)
_ = d.Set("subscription_term", resp.SubscriptionTerm)
_ = d.Set("description", resp.Description)
_ = d.Set("speed", resp.Speed)
_ = d.Set("pop", resp.CloudProvider.Pop)
_ = d.Set("zone", resp.Zone)
_ = d.Set("aws_account_id", resp.CloudSettings.AwsAccountID)
_ = d.Set("po_number", resp.PONumber)
if resp.CloudSettings.PublicIP != "" {
_ = d.Set("is_public", true)
} else {
_ = d.Set("is_public", false)
}
if _, ok := d.GetOk("cloud_settings"); ok {
// Extract the BGP settings UUID
var bgpSettingsUUID string
if len(resp.BgpStateList) > 0 {
bgpSettingsUUID = resp.BgpStateList[0].BgpSettingsUUID
_ = d.Set("bgp_settings_uuid", bgpSettingsUUID)
}
bgp, err := c.GetBgpSessionBy(circuitID.(string), cloudConnCID.(string), bgpSettingsUUID)
if err != nil {
return diag.FromErr(errors.New("could not retrieve bgp session"))
}
cloudSettings := make(map[string]interface{})
cloudSettings["credentials_uuid"] = resp.CloudSettings.CredentialsUUID
cloudSettings["aws_region"] = resp.CloudSettings.AwsRegion
if _, ok := d.GetOk("cloud_settings.0.mtu"); ok {
cloudSettings["mtu"] = resp.CloudSettings.Mtu
}
cloudSettings["aws_vif_type"] = resp.CloudSettings.AwsVifType
bgpSettings := make(map[string]interface{})
if bgp != nil {
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.remote_asn"); ok {
bgpSettings["remote_asn"] = bgp.RemoteAsn
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.l3_address"); ok {
bgpSettings["l3_address"] = bgp.L3Address
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.remote_address"); ok {
bgpSettings["remote_address"] = bgp.RemoteAddress
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.disabled"); ok {
bgpSettings["disabled"] = bgp.Disabled
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.orlonger"); ok {
bgpSettings["orlonger"] = bgp.Orlonger
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.md5"); ok {
bgpSettings["md5"] = bgp.Md5
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.med"); ok {
bgpSettings["med"] = bgp.Med
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.as_prepend"); ok {
bgpSettings["as_prepend"] = bgp.AsPrepend
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.local_preference"); ok {
bgpSettings["local_preference"] = bgp.LocalPreference
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.bfd_interval"); ok {
bgpSettings["bfd_interval"] = bgp.BfdInterval
}
if _, ok := d.GetOk("cloud_settings.0.bgp_settings.0.bfd_multiplier"); ok {
bgpSettings["bfd_multiplier"] = bgp.BfdMultiplier
}
if bgp.Nat != nil {
nat := flattenNatConfiguration(bgp.Nat)
bgpSettings["nat"] = nat
}
prefixes := flattenPrefixConfiguration(bgp.Prefixes)
bgpSettings["prefixes"] = prefixes
}
cloudSettings["bgp_settings"] = bgpSettings
awsGateways := make([]map[string]interface{}, len(resp.CloudSettings.AwsGateways))
for i, gateway := range resp.CloudSettings.AwsGateways {
awsGateway := make(map[string]interface{})
awsGateway["type"] = gateway.Type
awsGateway["name"] = gateway.Name
awsGateway["id"] = gateway.ID
awsGateway["asn"] = gateway.Asn
awsGateway["vpc_id"] = gateway.VpcID
awsGateway["subnet_ids"] = gateway.SubnetIDs
awsGateway["allowed_prefixes"] = gateway.AllowedPrefixes
awsGateways[i] = awsGateway
}
cloudSettings["aws_gateways"] = awsGateways
_ = d.Set("cloud_settings", cloudSettings)
} else {
if resp.CloudProviderConnectionID == "" || resp.CloudSettings.VlanIDPf == 0 {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Incomplete Cloud Information",
Detail: "The cloud_provider_connection_id and/or vlan_id_pf are currently unavailable.",
})
return diags
} else {
_ = d.Set("cloud_provider_connection_id", resp.CloudProviderConnectionID)
_ = d.Set("vlan_id_pf", resp.CloudSettings.VlanIDPf)
}
}
// unsetFields: published_quote_line_uuid
if _, ok := d.GetOk("labels"); ok {
labels, err2 := getLabels(c, d.Id())
if err2 != nil {
return diag.FromErr(err2)
}
_ = d.Set("labels", labels)
}
etl, err := c.GetEarlyTerminationLiability(d.Id())
if err != nil {
return diag.FromErr(err)
}
if etl > 0 {
_ = d.Set("etl", etl)
}
return diags
}
func resourceRouterConnectionAwsUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
return resourceCloudRouterConnUpdate(ctx, d, m)
}
func resourceRouterConnectionAwsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
return resourceCloudRouterConnDelete(ctx, d, m)
}
func extractAwsConnection(d *schema.ResourceData) packetfabric.AwsConnection {
awsConn := packetfabric.AwsConnection{}
if awsAccountID, ok := d.GetOk("aws_account_id"); ok {
awsConn.AwsAccountID = awsAccountID.(string)
}
if accountUUID, ok := d.GetOk("account_uuid"); ok {
awsConn.AccountUUID = accountUUID.(string)
}
if maybeNat, ok := d.GetOk("maybe_nat"); ok {
awsConn.MaybeNat = maybeNat.(bool)
}
if maybeDNat, ok := d.GetOk("maybe_dnat"); ok {
awsConn.MaybeDNat = maybeDNat.(bool)
}
if description, ok := d.GetOk("description"); ok {
awsConn.Description = description.(string)
}
if pop, ok := d.GetOk("pop"); ok {
awsConn.Pop = pop.(string)
}
if zone, ok := d.GetOk("zone"); ok {
awsConn.Zone = zone.(string)
}
if isPublic, ok := d.GetOk("is_public"); ok {
awsConn.IsPublic = isPublic.(bool)
}
if subscriptionTerm, ok := d.GetOk("subscription_term"); ok {
awsConn.SubscriptionTerm = subscriptionTerm.(int)
}
if speed, ok := d.GetOk("speed"); ok {
awsConn.Speed = speed.(string)
}
if publishedQuoteLineUUID, ok := d.GetOk("published_quote_line_uuid"); ok {
awsConn.PublishedQuoteLineUUID = publishedQuoteLineUUID.(string)
}
if poNumber, ok := d.GetOk("po_number"); ok {
awsConn.PONumber = poNumber.(string)
}
if cloudSettingsList, ok := d.GetOk("cloud_settings"); ok {
cs := cloudSettingsList.([]interface{})[0].(map[string]interface{})
awsConn.CloudSettings = extractAwsRouterCloudConnSettings(cs)
}
return awsConn
}
func extractAwsRouterCloudConnSettings(cs map[string]interface{}) *packetfabric.CloudSettings {
cloudSettings := &packetfabric.CloudSettings{}
cloudSettings.CredentialsUUID = cs["credentials_uuid"].(string)
if awsRegion, ok := cs["aws_region"]; ok {
cloudSettings.AwsRegion = awsRegion.(string)
}
cloudSettings.AwsVifType = cs["aws_vif_type"].(string)
if awsGateways, ok := cs["aws_gateways"]; ok {
cloudSettings.AwsGateways = extractAwsGateways(awsGateways.([]interface{}))
}
if mtu, ok := cs["mtu"]; ok {
cloudSettings.Mtu = mtu.(int)
}
if bgpSettings, ok := cs["bgp_settings"]; ok {
bgpSettingsMap := bgpSettings.([]interface{})[0].(map[string]interface{})
cloudSettings.BgpSettings = extractRouterConnBgpSettings(bgpSettingsMap)
}
return cloudSettings
}