@@ -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 {
0 commit comments