Skip to content

Commit bdbaf2a

Browse files
authored
fix(cls): [117602221] support web tracking (#2721)
* add * add * add * add * add * add
1 parent 0b950f5 commit bdbaf2a

File tree

8 files changed

+407
-15
lines changed

8 files changed

+407
-15
lines changed

.changelog/2721.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_cls_topic: add `is_web_tracking`, `extends` params
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ require (
4545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
48-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.952
48+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.962
4949
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.964
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.860 h1:IU20AhN
862862
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.860/go.mod h1:RP3NkBvKio1dFmCNKozHX9qmef57sUCfsTcE0FnCvjk=
863863
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.952 h1:+4g+Wp3WKTf/QU814lF+kft4jP/NNUkggciB/n0joTM=
864864
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.952/go.mod h1:OW+FNkQgeQTesREQ7iPA4g9V81cEb/NcWSYO6bYe2Qo=
865+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.962 h1:rkceP3tcjU0BCh9xloqZ5cuzDXP327YlQgWHXEaVgns=
866+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.962/go.mod h1:OEg00w6fKlT/3Q/4UI13P5kEJU2IvZm3XMZGUYEKPPs=
865867
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.414/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
866868
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
867869
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.524/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
@@ -950,6 +952,12 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.963 h1:lUVC
950952
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.963/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
951953
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.964 h1:ET3EulYQvWrdD5FNwOP+196w5Vbniy/uRGucM5ILExQ=
952954
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.964/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
955+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.962 h1:H7V/7lpplT3r5zW5/W+agrsJC8MCA1/f6zWWrMZYykU=
956+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.962/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
957+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.950 h1:gsBG5scMDYykLzPSj9aXCTxVjWE5lt+y6VwNAROf7Fw=
958+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.950/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
959+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.961 h1:UqinjIsO+Y48BQYSxrD6aHQe8SD+Wsbvj+jU9V9VvWM=
960+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.961/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
953961
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
954962
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860/go.mod h1:NZo1WplQcC314kMlCRUoy8NQju2BnolIJj7NAWgsuhY=
955963
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=

tencentcloud/services/cls/resource_tc_cls_topic.go

Lines changed: 210 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func ResourceTencentCloudClsTopic() *schema.Resource {
1818
return &schema.Resource{
1919
Create: resourceTencentCloudClsTopicCreate,
2020
Read: resourceTencentCloudClsTopicRead,
21-
Delete: resourceTencentCloudClsTopicDelete,
2221
Update: resourceTencentCloudClsTopicUpdate,
22+
Delete: resourceTencentCloudClsTopicDelete,
2323
Importer: &schema.ResourceImporter{
2424
State: schema.ImportStatePassthrough,
2525
},
@@ -82,6 +82,62 @@ func ResourceTencentCloudClsTopic() *schema.Resource {
8282
Optional: true,
8383
Description: "Log Topic Description.",
8484
},
85+
"is_web_tracking": {
86+
Type: schema.TypeBool,
87+
Optional: true,
88+
Computed: true,
89+
Description: "No authentication switch. False: closed; True: Enable. The default is false. After activation, anonymous access to the log topic will be supported for specified operations.",
90+
},
91+
"extends": {
92+
Type: schema.TypeList,
93+
Optional: true,
94+
MaxItems: 1,
95+
Description: "Log Subject Extension Information.",
96+
Elem: &schema.Resource{
97+
Schema: map[string]*schema.Schema{
98+
"anonymous_access": {
99+
Type: schema.TypeList,
100+
Optional: true,
101+
MaxItems: 1,
102+
Description: "Log topic authentication free configuration information.",
103+
Elem: &schema.Resource{
104+
Schema: map[string]*schema.Schema{
105+
"operations": {
106+
Type: schema.TypeList,
107+
Optional: true,
108+
Description: "Operation list, supporting trackLog (JS/HTTP upload log) and realtimeProducer (kafka protocol upload log).",
109+
Elem: &schema.Schema{Type: schema.TypeString},
110+
},
111+
"conditions": {
112+
Type: schema.TypeList,
113+
Optional: true,
114+
Description: "Operation list, supporting trackLog (JS/HTTP upload log) and realtimeProducer (kafka protocol upload log).",
115+
Elem: &schema.Resource{
116+
Schema: map[string]*schema.Schema{
117+
"attributes": {
118+
Type: schema.TypeString,
119+
Optional: true,
120+
Description: "Condition attribute, currently only VpcID is supported.",
121+
},
122+
"rule": {
123+
Type: schema.TypeInt,
124+
Optional: true,
125+
Description: "Conditional rule, 1: equal, 2: not equal.",
126+
},
127+
"condition_value": {
128+
Type: schema.TypeString,
129+
Optional: true,
130+
Description: "The value of the corresponding conditional attribute.",
131+
},
132+
},
133+
},
134+
},
135+
},
136+
},
137+
},
138+
},
139+
},
140+
},
85141
},
86142
}
87143
}
@@ -90,9 +146,10 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
90146
defer tccommon.LogElapsed("resource.tencentcloud_cls_topic.create")()
91147

92148
var (
93-
logId = tccommon.GetLogId(tccommon.ContextNil)
94-
request = cls.NewCreateTopicRequest()
95-
response *cls.CreateTopicResponse
149+
logId = tccommon.GetLogId(tccommon.ContextNil)
150+
request = cls.NewCreateTopicRequest()
151+
response *cls.CreateTopicResponse
152+
isWebTracking bool
96153
)
97154

98155
if v, ok := d.GetOk("logset_id"); ok {
@@ -144,6 +201,56 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
144201
request.Describes = helper.String("")
145202
}
146203

204+
if v, ok := d.GetOkExists("is_web_tracking"); ok {
205+
request.IsWebTracking = helper.Bool(v.(bool))
206+
isWebTracking = v.(bool)
207+
}
208+
209+
if isWebTracking {
210+
if dMap, ok := helper.InterfacesHeadMap(d, "extends"); ok {
211+
topicExtendInfo := cls.TopicExtendInfo{}
212+
if anonymousAccessMap, ok := helper.InterfaceToMap(dMap, "anonymous_access"); ok {
213+
anonymousInfo := cls.AnonymousInfo{}
214+
if v, ok := anonymousAccessMap["operations"]; ok {
215+
tmpList := make([]*string, 0)
216+
for _, operation := range v.([]interface{}) {
217+
tmpList = append(tmpList, helper.String(operation.(string)))
218+
}
219+
220+
anonymousInfo.Operations = tmpList
221+
}
222+
223+
if v, ok := anonymousAccessMap["conditions"]; ok {
224+
for _, condition := range v.([]interface{}) {
225+
conditionMap := condition.(map[string]interface{})
226+
conditionInfo := cls.ConditionInfo{}
227+
if v, ok := conditionMap["attributes"]; ok {
228+
conditionInfo.Attributes = helper.String(v.(string))
229+
}
230+
231+
if v, ok := conditionMap["rule"]; ok {
232+
conditionInfo.Rule = helper.IntUint64(v.(int))
233+
}
234+
235+
if v, ok := conditionMap["condition_value"]; ok {
236+
conditionInfo.ConditionValue = helper.String(v.(string))
237+
}
238+
239+
anonymousInfo.Conditions = append(anonymousInfo.Conditions, &conditionInfo)
240+
}
241+
}
242+
243+
topicExtendInfo.AnonymousAccess = &anonymousInfo
244+
}
245+
246+
request.Extends = &topicExtendInfo
247+
}
248+
} else {
249+
if _, ok := helper.InterfacesHeadMap(d, "extends"); ok {
250+
return fmt.Errorf("If `is_web_tracking` is false, Not support set `extends`.\n.")
251+
}
252+
}
253+
147254
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
148255
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().CreateTopic(request)
149256
if e != nil {
@@ -209,6 +316,50 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
209316
_ = d.Set("period", topic.Period)
210317
_ = d.Set("hot_period", topic.HotPeriod)
211318
_ = d.Set("describes", topic.Describes)
319+
_ = d.Set("is_web_tracking", topic.IsWebTracking)
320+
321+
if *topic.IsWebTracking {
322+
if topic.Extends != nil {
323+
extendMap := map[string]interface{}{}
324+
if topic.Extends.AnonymousAccess != nil {
325+
anonymousAccessMap := map[string]interface{}{}
326+
if topic.Extends.AnonymousAccess.Operations != nil {
327+
operationList := make([]string, 0, len(topic.Extends.AnonymousAccess.Operations))
328+
for _, v := range topic.Extends.AnonymousAccess.Operations {
329+
operationList = append(operationList, *v)
330+
}
331+
332+
anonymousAccessMap["operations"] = operationList
333+
}
334+
335+
if topic.Extends.AnonymousAccess.Conditions != nil {
336+
conditionList := []interface{}{}
337+
for _, v := range topic.Extends.AnonymousAccess.Conditions {
338+
conditionMap := map[string]interface{}{}
339+
if v.Attributes != nil {
340+
conditionMap["attributes"] = *v.Attributes
341+
}
342+
343+
if v.Rule != nil {
344+
conditionMap["rule"] = *v.Rule
345+
}
346+
347+
if v.ConditionValue != nil {
348+
conditionMap["condition_value"] = *v.ConditionValue
349+
}
350+
351+
conditionList = append(conditionList, conditionMap)
352+
}
353+
354+
anonymousAccessMap["conditions"] = conditionList
355+
}
356+
357+
extendMap["anonymous_access"] = []interface{}{anonymousAccessMap}
358+
}
359+
360+
_ = d.Set("extends", []interface{}{extendMap})
361+
}
362+
}
212363

213364
return nil
214365
}
@@ -217,9 +368,10 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
217368
defer tccommon.LogElapsed("resource.tencentcloud_cls_topic.update")()
218369

219370
var (
220-
logId = tccommon.GetLogId(tccommon.ContextNil)
221-
request = cls.NewModifyTopicRequest()
222-
id = d.Id()
371+
logId = tccommon.GetLogId(tccommon.ContextNil)
372+
request = cls.NewModifyTopicRequest()
373+
id = d.Id()
374+
isWebTracking bool
223375
)
224376

225377
immutableArgs := []string{"partition_count", "storage_type"}
@@ -269,6 +421,57 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
269421
request.Describes = helper.String(d.Get("describes").(string))
270422
}
271423

424+
if v, ok := d.GetOkExists("is_web_tracking"); ok {
425+
request.IsWebTracking = helper.Bool(v.(bool))
426+
isWebTracking = v.(bool)
427+
}
428+
429+
if isWebTracking {
430+
if dMap, ok := helper.InterfacesHeadMap(d, "extends"); ok {
431+
if anonymousAccessMap, ok := helper.InterfaceToMap(dMap, "anonymous_access"); ok {
432+
topicExtendInfo := cls.TopicExtendInfo{}
433+
anonymousInfo := cls.AnonymousInfo{}
434+
if v, ok := anonymousAccessMap["operations"]; ok {
435+
tmpList := make([]*string, 0)
436+
for _, operation := range v.([]interface{}) {
437+
tmpList = append(tmpList, helper.String(operation.(string)))
438+
}
439+
440+
anonymousInfo.Operations = tmpList
441+
}
442+
443+
if v, ok := anonymousAccessMap["conditions"]; ok {
444+
for _, condition := range v.([]interface{}) {
445+
conditionMap := condition.(map[string]interface{})
446+
conditionInfo := cls.ConditionInfo{}
447+
if v, ok := conditionMap["attributes"]; ok {
448+
conditionInfo.Attributes = helper.String(v.(string))
449+
}
450+
451+
if v, ok := conditionMap["rule"]; ok {
452+
conditionInfo.Rule = helper.IntUint64(v.(int))
453+
}
454+
455+
if v, ok := conditionMap["condition_value"]; ok {
456+
conditionInfo.ConditionValue = helper.String(v.(string))
457+
}
458+
459+
anonymousInfo.Conditions = append(anonymousInfo.Conditions, &conditionInfo)
460+
}
461+
}
462+
463+
topicExtendInfo.AnonymousAccess = &anonymousInfo
464+
request.Extends = &topicExtendInfo
465+
}
466+
} else {
467+
return fmt.Errorf("If `is_web_tracking` is true, Must set `extends` params.\n.")
468+
}
469+
} else {
470+
if _, ok := helper.InterfacesHeadMap(d, "extends"); ok {
471+
return fmt.Errorf("If `is_web_tracking` is false, Not support set `extends` params.\n.")
472+
}
473+
}
474+
272475
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
273476
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().ModifyTopic(request)
274477
if e != nil {

tencentcloud/services/cls/resource_tc_cls_topic.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ Provides a resource to create a cls topic.
22

33
Example Usage
44

5+
Create a standard cls topic
6+
57
```hcl
68
resource "tencentcloud_cls_logset" "example" {
79
logset_name = "tf_example"
8-
tags = {
9-
"demo" = "test"
10+
tags = {
11+
tagKey = "tagValue"
1012
}
1113
}
1214
@@ -20,8 +22,47 @@ resource "tencentcloud_cls_topic" "example" {
2022
storage_type = "hot"
2123
describes = "Test Demo."
2224
hot_period = 10
23-
tags = {
24-
"test" = "test",
25+
tags = {
26+
tagKey = "tagValue"
27+
}
28+
}
29+
```
30+
31+
Create a cls topic with web tracking
32+
33+
```hcl
34+
resource "tencentcloud_cls_logset" "example" {
35+
logset_name = "tf_example"
36+
tags = {
37+
tagKey = "tagValue"
38+
}
39+
}
40+
41+
resource "tencentcloud_cls_topic" "example" {
42+
topic_name = "tf_example"
43+
logset_id = tencentcloud_cls_logset.example.id
44+
auto_split = false
45+
max_split_partitions = 20
46+
partition_count = 1
47+
period = 30
48+
storage_type = "hot"
49+
describes = "Test Demo."
50+
hot_period = 10
51+
is_web_tracking = true
52+
53+
extends {
54+
anonymous_access {
55+
operations = ["trackLog", "realtimeProducer"]
56+
conditions {
57+
attributes = "VpcID"
58+
rule = 1
59+
condition_value = "vpc-ahr3xajx"
60+
}
61+
}
62+
}
63+
64+
tags = {
65+
tagKey = "tagValue"
2566
}
2667
}
2768
```

0 commit comments

Comments
 (0)