@@ -152,6 +152,8 @@ import (
152
152
"log"
153
153
"sync"
154
154
155
+ "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
156
+
155
157
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
156
158
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
157
159
"github.com/pkg/errors"
@@ -253,6 +255,30 @@ func resourceTencentCloudClbInstance() *schema.Resource {
253
255
Computed : true ,
254
256
Description : "Vpc information of backend services are attached the CLB instance. Only supports `OPEN` CLBs." ,
255
257
},
258
+ "snat_pro" : {
259
+ Type : schema .TypeBool ,
260
+ Optional : true ,
261
+ Description : "Indicates whether Binding IPs of other VPCs feature switch." ,
262
+ },
263
+ "snat_ips" : {
264
+ Type : schema .TypeList ,
265
+ Optional : true ,
266
+ Description : "Snat Ip List, required with `snat_pro=true`. NOTE: This argument cannot be read and modified here because dynamic ip is untraceable, please import resource `tencentcloud_clb_snat_ip` to handle fixed ips." ,
267
+ Elem : & schema.Resource {
268
+ Schema : map [string ]* schema.Schema {
269
+ "ip" : {
270
+ Type : schema .TypeString ,
271
+ Optional : true ,
272
+ Description : "Snat IP address, If set to empty will auto allocated." ,
273
+ },
274
+ "subnet_id" : {
275
+ Type : schema .TypeString ,
276
+ Required : true ,
277
+ Description : "Snat subnet ID." ,
278
+ },
279
+ },
280
+ },
281
+ },
256
282
"tags" : {
257
283
Type : schema .TypeMap ,
258
284
Optional : true ,
@@ -366,6 +392,24 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
366
392
request .AddressIPVersion = helper .String (v .(string ))
367
393
}
368
394
395
+ if v , ok := d .GetOk ("snat_pro" ); ok {
396
+ request .SnatPro = helper .Bool (v .(bool ))
397
+ }
398
+
399
+ if v , ok := d .Get ("snat_ips" ).([]interface {}); ok && len (v ) > 0 {
400
+ for i := range v {
401
+ item := v [i ].(map [string ]interface {})
402
+ subnetId := item ["subnet_id" ].(string )
403
+ snatIp := & clb.SnatIp {
404
+ SubnetId : & subnetId ,
405
+ }
406
+ if v , ok := item ["ip" ].(string ); ok && v != "" {
407
+ snatIp .Ip = & v
408
+ }
409
+ request .SnatIps = append (request .SnatIps , snatIp )
410
+ }
411
+ }
412
+
369
413
v , ok := d .GetOk ("internet_charge_type" )
370
414
bv , bok := d .GetOk ("internet_bandwidth_max_out" )
371
415
pv , pok := d .GetOk ("bandwidth_package_id" )
@@ -613,6 +657,10 @@ func resourceTencentCloudClbInstanceRead(d *schema.ResourceData, meta interface{
613
657
_ = d .Set ("log_set_id" , instance .LogSetId )
614
658
_ = d .Set ("log_topic_id" , instance .LogTopicId )
615
659
660
+ if _ , ok := d .GetOk ("snat_pro" ); ok {
661
+ _ = d .Set ("snat_pro" , instance .SnatPro )
662
+ }
663
+
616
664
tcClient := meta .(* TencentCloudClient ).apiV3Conn
617
665
tagService := & TagService {client : tcClient }
618
666
tags , err := tagService .DescribeResourceTags (ctx , "clb" , "clb" , tcClient .Region , d .Id ())
@@ -631,15 +679,19 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
631
679
defer clbActionMu .Unlock ()
632
680
633
681
logId := getLogId (contextNil )
682
+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
634
683
635
684
d .Partial (true )
636
685
637
686
clbId := d .Id ()
687
+ request := clb .NewModifyLoadBalancerAttributesRequest ()
688
+ request .LoadBalancerId = helper .String (clbId )
638
689
clbName := ""
639
690
targetRegionInfo := clb.TargetRegionInfo {}
640
691
internet := clb.InternetAccessible {}
641
692
changed := false
642
693
isLoadBalancerPassToTgt := false
694
+ snatPro := d .Get ("snat_pro" ).(bool )
643
695
644
696
if d .HasChange ("clb_name" ) {
645
697
changed = true
@@ -651,6 +703,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
651
703
if flag {
652
704
return fmt .Errorf ("[CHECK][CLB instance][Update] check: Same CLB name %s exists!" , clbName )
653
705
}
706
+ request .LoadBalancerName = helper .String (clbName )
654
707
}
655
708
656
709
if d .HasChange ("target_region_info_region" ) || d .HasChange ("target_region_info_vpc_id" ) {
@@ -664,6 +717,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
664
717
Region : & region ,
665
718
VpcId : & vpcId ,
666
719
}
720
+ request .TargetRegionInfo = & targetRegionInfo
667
721
}
668
722
669
723
if d .HasChange ("internet_charge_type" ) || d .HasChange ("internet_bandwidth_max_out" ) {
@@ -679,28 +733,25 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
679
733
if bandwidth > 0 {
680
734
internet .InternetMaxBandwidthOut = helper .IntInt64 (bandwidth )
681
735
}
736
+ request .InternetChargeInfo = & internet
682
737
}
683
738
684
739
if d .HasChange ("load_balancer_pass_to_target" ) {
685
740
changed = true
686
741
isLoadBalancerPassToTgt = d .Get ("load_balancer_pass_to_target" ).(bool )
742
+ request .LoadBalancerPassToTarget = & isLoadBalancerPassToTgt
743
+ }
744
+
745
+ if d .HasChange ("snat_pro" ) {
746
+ changed = true
747
+ request .SnatPro = & snatPro
748
+ }
749
+
750
+ if d .HasChange ("snat_ips" ) {
751
+ return fmt .Errorf ("`snat_ips`" )
687
752
}
688
753
689
754
if changed {
690
- request := clb .NewModifyLoadBalancerAttributesRequest ()
691
- request .LoadBalancerId = helper .String (clbId )
692
- if d .HasChange ("clb_name" ) {
693
- request .LoadBalancerName = helper .String (clbName )
694
- }
695
- if d .HasChange ("target_region_info_region" ) || d .HasChange ("target_region_info_vpc_id" ) {
696
- request .TargetRegionInfo = & targetRegionInfo
697
- }
698
- if d .HasChange ("internet_charge_type" ) || d .HasChange ("internet_bandwidth_max_out" ) {
699
- request .InternetChargeInfo = & internet
700
- }
701
- if d .HasChange ("load_balancer_pass_to_target" ) {
702
- request .LoadBalancerPassToTarget = & isLoadBalancerPassToTgt
703
- }
704
755
err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
705
756
response , e := meta .(* TencentCloudClient ).apiV3Conn .UseClbClient ().ModifyLoadBalancerAttributes (request )
706
757
if e != nil {
@@ -720,18 +771,6 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
720
771
log .Printf ("[CRITAL]%s update CLB instance failed, reason:%+v" , logId , err )
721
772
return err
722
773
}
723
- if d .HasChange ("clb_name" ) {
724
- d .SetPartial ("clb_name" )
725
- }
726
- if d .HasChange ("clb_vips" ) {
727
- d .SetPartial ("clb_vips" )
728
- }
729
- if d .HasChange ("target_region_info_region" ) {
730
- d .SetPartial ("target_region_info_region" )
731
- }
732
- if d .HasChange ("target_region_info_vpc_id" ) {
733
- d .SetPartial ("target_region_info_vpc_id" )
734
- }
735
774
}
736
775
737
776
if d .HasChange ("security_groups" ) {
@@ -794,7 +833,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
794
833
return err
795
834
}
796
835
}
797
- ctx := context . WithValue ( context . TODO (), logIdKey , logId )
836
+
798
837
if d .HasChange ("tags" ) {
799
838
800
839
oldValue , newValue := d .GetChange ("tags" )
@@ -875,3 +914,15 @@ func checkSameName(name string, meta interface{}) (flag bool, errRet error) {
875
914
errRet = err
876
915
return
877
916
}
917
+
918
+ func snatIpSetInitFn (i interface {}) int {
919
+ item := i .(map [string ]interface {})
920
+ subnet := item ["subnet_id" ].(string )
921
+ allocatedIp := item ["allocated_snat_ip" ].(string )
922
+ ip , ok := item ["ip" ].(string )
923
+
924
+ if ! ok || ip == "" {
925
+ ip = allocatedIp
926
+ }
927
+ return hashcode .String (subnet + ip )
928
+ }
0 commit comments