@@ -91,6 +91,52 @@ resource "tencentcloud_clb_instance" "open_clb1" {
91
91
~
92
92
```
93
93
94
+ CREATE instance with log
95
+ ```hcl
96
+ resource "tencentcloud_vpc" "vpc_test" {
97
+ name = "clb-test"
98
+ cidr_block = "10.0.0.0/16"
99
+ }
100
+
101
+ resource "tencentcloud_route_table" "rtb_test" {
102
+ name = "clb-test"
103
+ vpc_id = "${tencentcloud_vpc.vpc_test.id}"
104
+ }
105
+
106
+ resource "tencentcloud_subnet" "subnet_test" {
107
+ name = "clb-test"
108
+ cidr_block = "10.0.1.0/24"
109
+ availability_zone = "ap-guangzhou-3"
110
+ vpc_id = "${tencentcloud_vpc.vpc_test.id}"
111
+ route_table_id = "${tencentcloud_route_table.rtb_test.id}"
112
+ }
113
+
114
+ resource "tencentcloud_clb_log_set" "set" {
115
+ period = 7
116
+ }
117
+
118
+ resource "tencentcloud_clb_log_topic" "topic" {
119
+ log_set_id = "${tencentcloud_clb_log_set.set.id}"
120
+ topic_name = "clb-topic"
121
+ }
122
+
123
+ resource "tencentcloud_clb_instance" "internal_clb" {
124
+ network_type = "INTERNAL"
125
+ clb_name = "myclb"
126
+ project_id = 0
127
+ vpc_id = "${tencentcloud_vpc.vpc_test.id}"
128
+ subnet_id = "${tencentcloud_subnet.subnet_test.id}"
129
+ load_balancer_pass_to_target = true
130
+ log_set_id = "${tencentcloud_clb_log_set.set.id}"
131
+ log_topic_id = "${tencentcloud_clb_log_topic.topic.id}"
132
+
133
+ tags = {
134
+ test = "tf"
135
+ }
136
+ }
137
+
138
+ ```
139
+
94
140
Import
95
141
96
142
CLB instance can be imported using the id, e.g.
@@ -239,6 +285,16 @@ func resourceTencentCloudClbInstance() *schema.Resource {
239
285
Optional : true ,
240
286
Description : "Setting slave zone id of cross available zone disaster recovery, only applicable to open CLB. this zone will undertake traffic when the master is down." ,
241
287
},
288
+ "log_set_id" : {
289
+ Type : schema .TypeString ,
290
+ Optional : true ,
291
+ Description : "The id of log set." ,
292
+ },
293
+ "log_topic_id" : {
294
+ Type : schema .TypeString ,
295
+ Optional : true ,
296
+ Description : "The id of log topic." ,
297
+ },
242
298
},
243
299
}
244
300
}
@@ -422,6 +478,38 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
422
478
}
423
479
}
424
480
481
+ if v , ok := d .GetOk ("log_set_id" ); ok {
482
+ if u , ok := d .GetOk ("log_topic_id" ); ok {
483
+ logRequest := clb .NewSetLoadBalancerClsLogRequest ()
484
+ logRequest .LoadBalancerId = helper .String (clbId )
485
+ logRequest .LogSetId = helper .String (v .(string ))
486
+ logRequest .LogTopicId = helper .String (u .(string ))
487
+ err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
488
+ logResponse , e := meta .(* TencentCloudClient ).apiV3Conn .UseClbClient ().SetLoadBalancerClsLog (logRequest )
489
+ if e != nil {
490
+ return retryError (e )
491
+ } else {
492
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
493
+ logId , logRequest .GetAction (), logRequest .ToJsonString (), logResponse .ToJsonString ())
494
+ requestId := * logResponse .Response .RequestId
495
+
496
+ retryErr := waitForTaskFinish (requestId , meta .(* TencentCloudClient ).apiV3Conn .UseClbClient ())
497
+ if retryErr != nil {
498
+ return retryError (errors .WithStack (retryErr ))
499
+ }
500
+ }
501
+ return nil
502
+ })
503
+ if err != nil {
504
+ log .Printf ("[CRITAL]%s set CLB instance log failed, reason:%+v" , logId , err )
505
+ return err
506
+ }
507
+
508
+ } else {
509
+ return fmt .Errorf ("log_topic_id and log_set_id must be set together." )
510
+ }
511
+ }
512
+
425
513
if targetRegionInfoRegion != "" {
426
514
isLoadBalancePassToTgt := d .Get ("load_balancer_pass_to_target" ).(bool )
427
515
targetRegionInfo := clb.TargetRegionInfo {
@@ -504,6 +592,7 @@ func resourceTencentCloudClbInstanceRead(d *schema.ResourceData, meta interface{
504
592
_ = d .Set ("target_region_info_vpc_id" , instance .TargetRegionInfo .VpcId )
505
593
_ = d .Set ("project_id" , instance .ProjectId )
506
594
_ = d .Set ("security_groups" , helper .StringsInterfaces (instance .SecureGroups ))
595
+
507
596
if instance .VipIsp != nil {
508
597
_ = d .Set ("vip_isp" , instance .VipIsp )
509
598
}
@@ -519,6 +608,8 @@ func resourceTencentCloudClbInstanceRead(d *schema.ResourceData, meta interface{
519
608
_ = d .Set ("master_zone_id" , instance .MasterZone )
520
609
_ = d .Set ("zone_id" , instance .MasterZone )
521
610
_ = d .Set ("slave_zone_id" , instance .MasterZone )
611
+ _ = d .Set ("log_set_id" , instance .LogSetId )
612
+ _ = d .Set ("log_topic_id" , instance .LogTopicId )
522
613
523
614
tcClient := meta .(* TencentCloudClient ).apiV3Conn
524
615
tagService := & TagService {client : tcClient }
@@ -672,6 +763,35 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
672
763
}
673
764
d .SetPartial ("security_groups" )
674
765
}
766
+
767
+ if d .HasChange ("log_set_id" ) || d .HasChange ("log_topic_id" ) {
768
+ logSetId := d .Get ("log_set_id" )
769
+ logTopicId := d .Get ("log_topic_id" )
770
+ logRequest := clb .NewSetLoadBalancerClsLogRequest ()
771
+ logRequest .LoadBalancerId = helper .String (clbId )
772
+ logRequest .LogSetId = helper .String (logSetId .(string ))
773
+ logRequest .LogTopicId = helper .String (logTopicId .(string ))
774
+ err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
775
+ logResponse , e := meta .(* TencentCloudClient ).apiV3Conn .UseClbClient ().SetLoadBalancerClsLog (logRequest )
776
+ if e != nil {
777
+ return retryError (e )
778
+ } else {
779
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
780
+ logId , logRequest .GetAction (), logRequest .ToJsonString (), logResponse .ToJsonString ())
781
+ requestId := * logResponse .Response .RequestId
782
+
783
+ retryErr := waitForTaskFinish (requestId , meta .(* TencentCloudClient ).apiV3Conn .UseClbClient ())
784
+ if retryErr != nil {
785
+ return retryError (errors .WithStack (retryErr ))
786
+ }
787
+ }
788
+ return nil
789
+ })
790
+ if err != nil {
791
+ log .Printf ("[CRITAL]%s set CLB instance log failed, reason:%+v" , logId , err )
792
+ return err
793
+ }
794
+ }
675
795
ctx := context .WithValue (context .TODO (), logIdKey , logId )
676
796
if d .HasChange ("tags" ) {
677
797
0 commit comments