Skip to content

Commit c97f362

Browse files
committed
add
1 parent 296cc1d commit c97f362

File tree

1 file changed

+83
-69
lines changed

1 file changed

+83
-69
lines changed

tencentcloud/services/cls/resource_tc_cls_topic.go

Lines changed: 83 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ func ResourceTencentCloudClsTopic() *schema.Resource {
9191
"extends": {
9292
Type: schema.TypeList,
9393
Optional: true,
94-
Computed: true,
9594
MaxItems: 1,
9695
Description: "Log Subject Extension Information.",
9796
Elem: &schema.Resource{
@@ -147,9 +146,10 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
147146
defer tccommon.LogElapsed("resource.tencentcloud_cls_topic.create")()
148147

149148
var (
150-
logId = tccommon.GetLogId(tccommon.ContextNil)
151-
request = cls.NewCreateTopicRequest()
152-
response *cls.CreateTopicResponse
149+
logId = tccommon.GetLogId(tccommon.ContextNil)
150+
request = cls.NewCreateTopicRequest()
151+
response *cls.CreateTopicResponse
152+
isWebTracking bool
153153
)
154154

155155
if v, ok := d.GetOk("logset_id"); ok {
@@ -203,45 +203,52 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
203203

204204
if v, ok := d.GetOkExists("is_web_tracking"); ok {
205205
request.IsWebTracking = helper.Bool(v.(bool))
206+
isWebTracking = v.(bool)
206207
}
207208

208-
if dMap, ok := helper.InterfacesHeadMap(d, "extends"); ok {
209-
topicExtendInfo := cls.TopicExtendInfo{}
210-
if anonymousAccessMap, ok := helper.InterfaceToMap(dMap, "anonymous_access"); ok {
211-
anonymousInfo := cls.AnonymousInfo{}
212-
if v, ok := anonymousAccessMap["operations"]; ok {
213-
tmpList := make([]*string, 0)
214-
for _, operation := range v.([]interface{}) {
215-
tmpList = append(tmpList, helper.String(operation.(string)))
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
216221
}
217222

218-
anonymousInfo.Operations = tmpList
219-
}
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+
}
220230

221-
if v, ok := anonymousAccessMap["conditions"]; ok {
222-
for _, condition := range v.([]interface{}) {
223-
conditionMap := condition.(map[string]interface{})
224-
conditionInfo := cls.ConditionInfo{}
225-
if v, ok := conditionMap["attributes"]; ok {
226-
conditionInfo.Attributes = helper.String(v.(string))
227-
}
231+
if v, ok := conditionMap["rule"]; ok {
232+
conditionInfo.Rule = helper.IntUint64(v.(int))
233+
}
228234

229-
if v, ok := conditionMap["rule"]; ok {
230-
conditionInfo.Rule = helper.IntUint64(v.(int))
231-
}
235+
if v, ok := conditionMap["condition_value"]; ok {
236+
conditionInfo.ConditionValue = helper.String(v.(string))
237+
}
232238

233-
if v, ok := conditionMap["condition_value"]; ok {
234-
conditionInfo.ConditionValue = helper.String(v.(string))
239+
anonymousInfo.Conditions = append(anonymousInfo.Conditions, &conditionInfo)
235240
}
236-
237-
anonymousInfo.Conditions = append(anonymousInfo.Conditions, &conditionInfo)
238241
}
242+
243+
topicExtendInfo.AnonymousAccess = &anonymousInfo
239244
}
240245

241-
topicExtendInfo.AnonymousAccess = &anonymousInfo
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.")
242251
}
243-
244-
request.Extends = &topicExtendInfo
245252
}
246253

247254
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
@@ -311,45 +318,47 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
311318
_ = d.Set("describes", topic.Describes)
312319
_ = d.Set("is_web_tracking", topic.IsWebTracking)
313320

314-
if topic.Extends != nil {
315-
extendMap := map[string]interface{}{}
316-
if topic.Extends.AnonymousAccess != nil {
317-
anonymousAccessMap := map[string]interface{}{}
318-
if topic.Extends.AnonymousAccess.Operations != nil {
319-
operationList := make([]string, 0, len(topic.Extends.AnonymousAccess.Operations))
320-
for _, v := range topic.Extends.AnonymousAccess.Operations {
321-
operationList = append(operationList, *v)
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
322333
}
323334

324-
anonymousAccessMap["operations"] = operationList
325-
}
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+
}
326342

327-
if topic.Extends.AnonymousAccess.Conditions != nil {
328-
conditionList := []interface{}{}
329-
for _, v := range topic.Extends.AnonymousAccess.Conditions {
330-
conditionMap := map[string]interface{}{}
331-
if v.Attributes != nil {
332-
conditionMap["attributes"] = *v.Attributes
333-
}
343+
if v.Rule != nil {
344+
conditionMap["rule"] = *v.Rule
345+
}
334346

335-
if v.Rule != nil {
336-
conditionMap["rule"] = *v.Rule
337-
}
347+
if v.ConditionValue != nil {
348+
conditionMap["condition_value"] = *v.ConditionValue
349+
}
338350

339-
if v.ConditionValue != nil {
340-
conditionMap["condition_value"] = *v.ConditionValue
351+
conditionList = append(conditionList, conditionMap)
341352
}
342353

343-
conditionList = append(conditionList, conditionMap)
354+
anonymousAccessMap["conditions"] = conditionList
344355
}
345356

346-
anonymousAccessMap["conditions"] = conditionList
357+
extendMap["anonymous_access"] = []interface{}{anonymousAccessMap}
347358
}
348359

349-
extendMap["anonymous_access"] = []interface{}{anonymousAccessMap}
360+
_ = d.Set("extends", []interface{}{extendMap})
350361
}
351-
352-
_ = d.Set("extends", []interface{}{extendMap})
353362
}
354363

355364
return nil
@@ -359,9 +368,10 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
359368
defer tccommon.LogElapsed("resource.tencentcloud_cls_topic.update")()
360369

361370
var (
362-
logId = tccommon.GetLogId(tccommon.ContextNil)
363-
request = cls.NewModifyTopicRequest()
364-
id = d.Id()
371+
logId = tccommon.GetLogId(tccommon.ContextNil)
372+
request = cls.NewModifyTopicRequest()
373+
id = d.Id()
374+
isWebTracking bool
365375
)
366376

367377
immutableArgs := []string{"partition_count", "storage_type"}
@@ -411,16 +421,15 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
411421
request.Describes = helper.String(d.Get("describes").(string))
412422
}
413423

414-
if d.HasChange("is_web_tracking") {
415-
if v, ok := d.GetOkExists("is_web_tracking"); ok {
416-
request.IsWebTracking = helper.Bool(v.(bool))
417-
}
424+
if v, ok := d.GetOkExists("is_web_tracking"); ok {
425+
request.IsWebTracking = helper.Bool(v.(bool))
426+
isWebTracking = v.(bool)
418427
}
419428

420-
if d.HasChange("extends") {
429+
if isWebTracking {
421430
if dMap, ok := helper.InterfacesHeadMap(d, "extends"); ok {
422-
topicExtendInfo := cls.TopicExtendInfo{}
423431
if anonymousAccessMap, ok := helper.InterfaceToMap(dMap, "anonymous_access"); ok {
432+
topicExtendInfo := cls.TopicExtendInfo{}
424433
anonymousInfo := cls.AnonymousInfo{}
425434
if v, ok := anonymousAccessMap["operations"]; ok {
426435
tmpList := make([]*string, 0)
@@ -452,9 +461,14 @@ func resourceTencentCloudClsTopicUpdate(d *schema.ResourceData, meta interface{}
452461
}
453462

454463
topicExtendInfo.AnonymousAccess = &anonymousInfo
464+
request.Extends = &topicExtendInfo
455465
}
456-
457-
request.Extends = &topicExtendInfo
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.")
458472
}
459473
}
460474

0 commit comments

Comments
 (0)