@@ -378,6 +378,7 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
378
378
if err != nil {
379
379
return err
380
380
}
381
+
381
382
if ! has {
382
383
return fmt .Errorf ("[CRITAL] vpn_gateway_id %s doesn't exist" , d .Get ("vpn_gateway_id" ).(string ))
383
384
}
@@ -396,16 +397,19 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
396
397
}
397
398
request .VpcId = helper .String ("" )
398
399
}
400
+
399
401
request .VpnGatewayId = helper .String (d .Get ("vpn_gateway_id" ).(string ))
400
402
request .CustomerGatewayId = helper .String (d .Get ("customer_gateway_id" ).(string ))
401
403
request .PreShareKey = helper .String (d .Get ("pre_share_key" ).(string ))
402
404
if v , ok := d .GetOk ("dpd_enable" ); ok {
403
405
dpdEnable := v .(int )
404
406
request .DpdEnable = helper .IntInt64 (dpdEnable )
405
407
}
408
+
406
409
if v , ok := d .GetOk ("dpd_action" ); ok {
407
410
request .DpdAction = helper .String (v .(string ))
408
411
}
412
+
409
413
if v , ok := d .GetOk ("dpd_timeout" ); ok {
410
414
request .DpdTimeout = helper .String (strconv .Itoa (v .(int )))
411
415
}
@@ -418,22 +422,26 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
418
422
request .NegotiationType = helper .String (v .(string ))
419
423
}
420
424
421
- //set up SecurityPolicyDatabases
425
+ //set up SecurityPolicyDatabases
422
426
if v , ok := d .GetOk ("security_group_policy" ); ok {
423
- sgps := v .(* schema.Set ).List ()
424
- request .SecurityPolicyDatabases = make ([]* vpc.SecurityPolicyDatabase , 0 , len (sgps ))
425
- for _ , v := range sgps {
426
- m := v .(map [string ]interface {})
427
- var sgp vpc.SecurityPolicyDatabase
428
- local := m ["local_cidr_block" ].(string )
429
- sgp .LocalCidrBlock = & local
430
- // list
431
- remoteCidrBlocks := m ["remote_cidr_block" ].(* schema.Set ).List ()
432
- for _ , vv := range remoteCidrBlocks {
433
- remoteCidrBlock := vv .(string )
434
- sgp .RemoteCidrBlock = append (sgp .RemoteCidrBlock , & remoteCidrBlock )
427
+ for _ , item := range v .(* schema.Set ).List () {
428
+ if dMap , ok := item .(map [string ]interface {}); ok && dMap != nil {
429
+ var sgp vpc.SecurityPolicyDatabase
430
+ if v , ok := dMap ["local_cidr_block" ].(string ); ok && v != "" {
431
+ sgp .LocalCidrBlock = & v
432
+ }
433
+
434
+ if v , ok := dMap ["remote_cidr_block" ].(* schema.Set ); ok {
435
+ remoteCidrBlocks := v .List ()
436
+ for _ , rcb := range remoteCidrBlocks {
437
+ if v , ok := rcb .(string ); ok && v != "" {
438
+ sgp .RemoteCidrBlock = append (sgp .RemoteCidrBlock , & v )
439
+ }
440
+ }
441
+ }
442
+
443
+ request .SecurityPolicyDatabases = append (request .SecurityPolicyDatabases , & sgp )
435
444
}
436
- request .SecurityPolicyDatabases = append (request .SecurityPolicyDatabases , & sgp )
437
445
}
438
446
}
439
447
@@ -457,6 +465,7 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
457
465
return fmt .Errorf ("ike_local_fqdn_name need to be set when ike_local_identity is `FQDN`" )
458
466
}
459
467
}
468
+
460
469
if * ikeOptionsSpecification .LocalIdentity == svcvpc .VPN_IKE_IDENTITY_ADDRESS {
461
470
if v , ok := d .GetOk ("ike_remote_address" ); ok {
462
471
ikeOptionsSpecification .RemoteAddress = helper .String (v .(string ))
@@ -493,9 +502,11 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
493
502
if v , ok := d .GetOk ("enable_health_check" ); ok {
494
503
request .EnableHealthCheck = helper .Bool (v .(bool ))
495
504
}
505
+
496
506
if v , ok := d .GetOk ("health_check_local_ip" ); ok {
497
507
request .HealthCheckLocalIp = helper .String (v .(string ))
498
508
}
509
+
499
510
if v , ok := d .GetOk ("health_check_remote_ip" ); ok {
500
511
request .HealthCheckRemoteIp = helper .String (v .(string ))
501
512
}
@@ -564,20 +575,27 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
564
575
err = resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
565
576
result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseVpcClient ().CreateVpnConnection (request )
566
577
if e != nil {
567
- log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " ,
568
- logId , request .GetAction (), request .ToJsonString (), e .Error ())
578
+ log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " , logId , request .GetAction (), request .ToJsonString (), e .Error ())
569
579
return tccommon .RetryError (e )
580
+ } else {
581
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
570
582
}
583
+
584
+ if result == nil || result .Response == nil {
585
+ return resource .NonRetryableError (fmt .Errorf ("Create VPN connection failed, Response is nil." ))
586
+ }
587
+
571
588
response = result
572
589
return nil
573
590
})
591
+
574
592
if err != nil {
575
593
log .Printf ("[CRITAL]%s create VPN connection failed, reason:%s\n " , logId , err .Error ())
576
594
return err
577
595
}
578
596
579
597
if response .Response .VpnConnection == nil {
580
- return fmt .Errorf ("VPN connection id is nil" )
598
+ return fmt .Errorf ("VpnConnection is nil. " )
581
599
}
582
600
583
601
vpnConnectionId := ""
@@ -589,28 +607,31 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
589
607
if v , ok := d .GetOk ("vpn_gateway_id" ); ok {
590
608
params ["vpn-gateway-id" ] = v .(string )
591
609
}
610
+
592
611
if v , ok := d .GetOk ("vpc_id" ); ok && * gateway .Type != "CCN" {
593
612
params ["vpc-id" ] = v .(string )
594
613
}
614
+
595
615
if v , ok := d .GetOk ("customer_gateway_id" ); ok {
596
616
params ["customer-gateway-id" ] = v .(string )
597
617
}
618
+
598
619
for k , v := range params {
599
620
filter := & vpc.Filter {
600
621
Name : helper .String (k ),
601
622
Values : []* string {helper .String (v )},
602
623
}
624
+
603
625
idRequest .Filters = append (idRequest .Filters , filter )
604
626
}
627
+
605
628
offset := uint64 (0 )
606
629
idRequest .Offset = & offset
607
630
608
631
err = resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
609
632
result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseVpcClient ().DescribeVpnConnections (idRequest )
610
-
611
633
if e != nil {
612
- log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " ,
613
- logId , idRequest .GetAction (), idRequest .ToJsonString (), e .Error ())
634
+ log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " , logId , idRequest .GetAction (), idRequest .ToJsonString (), e .Error ())
614
635
return tccommon .RetryError (e , tccommon .InternalError )
615
636
} else {
616
637
if len (result .Response .VpnConnectionSet ) == 0 || * result .Response .VpnConnectionSet [0 ].VpnConnectionId == "" {
@@ -629,7 +650,7 @@ func resourceTencentCloudVpnConnectionCreate(d *schema.ResourceData, meta interf
629
650
}
630
651
631
652
if vpnConnectionId == "" {
632
- return fmt .Errorf ("VPN connection id is nil" )
653
+ return fmt .Errorf ("VPN connection id is nil. " )
633
654
}
634
655
635
656
d .SetId (vpnConnectionId )
0 commit comments