Skip to content

fix(cls): [117602221] support web tracking #2721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2721.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cls_topic: add `is_web_tracking`, `extends` params
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.952
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.962
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.964
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.860 h1:IU20AhN
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.860/go.mod h1:RP3NkBvKio1dFmCNKozHX9qmef57sUCfsTcE0FnCvjk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.952 h1:+4g+Wp3WKTf/QU814lF+kft4jP/NNUkggciB/n0joTM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.952/go.mod h1:OW+FNkQgeQTesREQ7iPA4g9V81cEb/NcWSYO6bYe2Qo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.962 h1:rkceP3tcjU0BCh9xloqZ5cuzDXP327YlQgWHXEaVgns=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.962/go.mod h1:OEg00w6fKlT/3Q/4UI13P5kEJU2IvZm3XMZGUYEKPPs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.414/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.524/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
Expand Down Expand Up @@ -950,6 +952,12 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.963 h1:lUVC
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.963/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.964 h1:ET3EulYQvWrdD5FNwOP+196w5Vbniy/uRGucM5ILExQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.964/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.962 h1:H7V/7lpplT3r5zW5/W+agrsJC8MCA1/f6zWWrMZYykU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.962/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.950 h1:gsBG5scMDYykLzPSj9aXCTxVjWE5lt+y6VwNAROf7Fw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.950/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.961 h1:UqinjIsO+Y48BQYSxrD6aHQe8SD+Wsbvj+jU9V9VvWM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.961/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860/go.mod h1:NZo1WplQcC314kMlCRUoy8NQju2BnolIJj7NAWgsuhY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
Expand Down
217 changes: 210 additions & 7 deletions tencentcloud/services/cls/resource_tc_cls_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func ResourceTencentCloudClsTopic() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudClsTopicCreate,
Read: resourceTencentCloudClsTopicRead,
Delete: resourceTencentCloudClsTopicDelete,
Update: resourceTencentCloudClsTopicUpdate,
Delete: resourceTencentCloudClsTopicDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand Down Expand Up @@ -82,6 +82,62 @@ func ResourceTencentCloudClsTopic() *schema.Resource {
Optional: true,
Description: "Log Topic Description.",
},
"is_web_tracking": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
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.",
},
"extends": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Log Subject Extension Information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"anonymous_access": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Log topic authentication free configuration information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"operations": {
Type: schema.TypeList,
Optional: true,
Description: "Operation list, supporting trackLog (JS/HTTP upload log) and realtimeProducer (kafka protocol upload log).",
Elem: &schema.Schema{Type: schema.TypeString},
},
"conditions": {
Type: schema.TypeList,
Optional: true,
Description: "Operation list, supporting trackLog (JS/HTTP upload log) and realtimeProducer (kafka protocol upload log).",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"attributes": {
Type: schema.TypeString,
Optional: true,
Description: "Condition attribute, currently only VpcID is supported.",
},
"rule": {
Type: schema.TypeInt,
Optional: true,
Description: "Conditional rule, 1: equal, 2: not equal.",
},
"condition_value": {
Type: schema.TypeString,
Optional: true,
Description: "The value of the corresponding conditional attribute.",
},
},
},
},
},
},
},
},
},
},
},
}
}
Expand All @@ -90,9 +146,10 @@ func resourceTencentCloudClsTopicCreate(d *schema.ResourceData, meta interface{}
defer tccommon.LogElapsed("resource.tencentcloud_cls_topic.create")()

var (
logId = tccommon.GetLogId(tccommon.ContextNil)
request = cls.NewCreateTopicRequest()
response *cls.CreateTopicResponse
logId = tccommon.GetLogId(tccommon.ContextNil)
request = cls.NewCreateTopicRequest()
response *cls.CreateTopicResponse
isWebTracking bool
)

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

if v, ok := d.GetOkExists("is_web_tracking"); ok {
request.IsWebTracking = helper.Bool(v.(bool))
isWebTracking = v.(bool)
}

if isWebTracking {
if dMap, ok := helper.InterfacesHeadMap(d, "extends"); ok {
topicExtendInfo := cls.TopicExtendInfo{}
if anonymousAccessMap, ok := helper.InterfaceToMap(dMap, "anonymous_access"); ok {
anonymousInfo := cls.AnonymousInfo{}
if v, ok := anonymousAccessMap["operations"]; ok {
tmpList := make([]*string, 0)
for _, operation := range v.([]interface{}) {
tmpList = append(tmpList, helper.String(operation.(string)))
}

anonymousInfo.Operations = tmpList
}

if v, ok := anonymousAccessMap["conditions"]; ok {
for _, condition := range v.([]interface{}) {
conditionMap := condition.(map[string]interface{})
conditionInfo := cls.ConditionInfo{}
if v, ok := conditionMap["attributes"]; ok {
conditionInfo.Attributes = helper.String(v.(string))
}

if v, ok := conditionMap["rule"]; ok {
conditionInfo.Rule = helper.IntUint64(v.(int))
}

if v, ok := conditionMap["condition_value"]; ok {
conditionInfo.ConditionValue = helper.String(v.(string))
}

anonymousInfo.Conditions = append(anonymousInfo.Conditions, &conditionInfo)
}
}

topicExtendInfo.AnonymousAccess = &anonymousInfo
}

request.Extends = &topicExtendInfo
}
} else {
if _, ok := helper.InterfacesHeadMap(d, "extends"); ok {
return fmt.Errorf("If `is_web_tracking` is false, Not support set `extends`.\n.")
}
}

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().CreateTopic(request)
if e != nil {
Expand Down Expand Up @@ -209,6 +316,50 @@ func resourceTencentCloudClsTopicRead(d *schema.ResourceData, meta interface{})
_ = d.Set("period", topic.Period)
_ = d.Set("hot_period", topic.HotPeriod)
_ = d.Set("describes", topic.Describes)
_ = d.Set("is_web_tracking", topic.IsWebTracking)

if *topic.IsWebTracking {
if topic.Extends != nil {
extendMap := map[string]interface{}{}
if topic.Extends.AnonymousAccess != nil {
anonymousAccessMap := map[string]interface{}{}
if topic.Extends.AnonymousAccess.Operations != nil {
operationList := make([]string, 0, len(topic.Extends.AnonymousAccess.Operations))
for _, v := range topic.Extends.AnonymousAccess.Operations {
operationList = append(operationList, *v)
}

anonymousAccessMap["operations"] = operationList
}

if topic.Extends.AnonymousAccess.Conditions != nil {
conditionList := []interface{}{}
for _, v := range topic.Extends.AnonymousAccess.Conditions {
conditionMap := map[string]interface{}{}
if v.Attributes != nil {
conditionMap["attributes"] = *v.Attributes
}

if v.Rule != nil {
conditionMap["rule"] = *v.Rule
}

if v.ConditionValue != nil {
conditionMap["condition_value"] = *v.ConditionValue
}

conditionList = append(conditionList, conditionMap)
}

anonymousAccessMap["conditions"] = conditionList
}

extendMap["anonymous_access"] = []interface{}{anonymousAccessMap}
}

_ = d.Set("extends", []interface{}{extendMap})
}
}

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

var (
logId = tccommon.GetLogId(tccommon.ContextNil)
request = cls.NewModifyTopicRequest()
id = d.Id()
logId = tccommon.GetLogId(tccommon.ContextNil)
request = cls.NewModifyTopicRequest()
id = d.Id()
isWebTracking bool
)

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

if v, ok := d.GetOkExists("is_web_tracking"); ok {
request.IsWebTracking = helper.Bool(v.(bool))
isWebTracking = v.(bool)
}

if isWebTracking {
if dMap, ok := helper.InterfacesHeadMap(d, "extends"); ok {
if anonymousAccessMap, ok := helper.InterfaceToMap(dMap, "anonymous_access"); ok {
topicExtendInfo := cls.TopicExtendInfo{}
anonymousInfo := cls.AnonymousInfo{}
if v, ok := anonymousAccessMap["operations"]; ok {
tmpList := make([]*string, 0)
for _, operation := range v.([]interface{}) {
tmpList = append(tmpList, helper.String(operation.(string)))
}

anonymousInfo.Operations = tmpList
}

if v, ok := anonymousAccessMap["conditions"]; ok {
for _, condition := range v.([]interface{}) {
conditionMap := condition.(map[string]interface{})
conditionInfo := cls.ConditionInfo{}
if v, ok := conditionMap["attributes"]; ok {
conditionInfo.Attributes = helper.String(v.(string))
}

if v, ok := conditionMap["rule"]; ok {
conditionInfo.Rule = helper.IntUint64(v.(int))
}

if v, ok := conditionMap["condition_value"]; ok {
conditionInfo.ConditionValue = helper.String(v.(string))
}

anonymousInfo.Conditions = append(anonymousInfo.Conditions, &conditionInfo)
}
}

topicExtendInfo.AnonymousAccess = &anonymousInfo
request.Extends = &topicExtendInfo
}
} else {
return fmt.Errorf("If `is_web_tracking` is true, Must set `extends` params.\n.")
}
} else {
if _, ok := helper.InterfacesHeadMap(d, "extends"); ok {
return fmt.Errorf("If `is_web_tracking` is false, Not support set `extends` params.\n.")
}
}

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().ModifyTopic(request)
if e != nil {
Expand Down
49 changes: 45 additions & 4 deletions tencentcloud/services/cls/resource_tc_cls_topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ Provides a resource to create a cls topic.

Example Usage

Create a standard cls topic

```hcl
resource "tencentcloud_cls_logset" "example" {
logset_name = "tf_example"
tags = {
"demo" = "test"
tags = {
tagKey = "tagValue"
}
}

Expand All @@ -20,8 +22,47 @@ resource "tencentcloud_cls_topic" "example" {
storage_type = "hot"
describes = "Test Demo."
hot_period = 10
tags = {
"test" = "test",
tags = {
tagKey = "tagValue"
}
}
```

Create a cls topic with web tracking

```hcl
resource "tencentcloud_cls_logset" "example" {
logset_name = "tf_example"
tags = {
tagKey = "tagValue"
}
}

resource "tencentcloud_cls_topic" "example" {
topic_name = "tf_example"
logset_id = tencentcloud_cls_logset.example.id
auto_split = false
max_split_partitions = 20
partition_count = 1
period = 30
storage_type = "hot"
describes = "Test Demo."
hot_period = 10
is_web_tracking = true

extends {
anonymous_access {
operations = ["trackLog", "realtimeProducer"]
conditions {
attributes = "VpcID"
rule = 1
condition_value = "vpc-ahr3xajx"
}
}
}

tags = {
tagKey = "tagValue"
}
}
```
Expand Down
Loading
Loading