Skip to content

Commit 1ed229e

Browse files
committed
add
1 parent b0444ab commit 1ed229e

11 files changed

+373
-35
lines changed

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.1073
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
48-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1135
48+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148
4949
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1148
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1128
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1078 h1:6yf63s
869869
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1078/go.mod h1:D0n69Y0uDnHt31Wp5Z+uqmgBzr8xTZhrXPJ6d6KJL6E=
870870
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1135 h1:FTWpacOgtZCLC3Kwdf9gOpG2yYzfEzjKHsCR2k89LD0=
871871
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1135/go.mod h1:upjXJ5ISzUgxChOoUUcr9tQd8PB7FG3rFtMrxhozYzU=
872+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148 h1:tPQHJE07DGCJWrQJklrkrF0CasB86M7AEb0PrkXNjAM=
873+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148/go.mod h1:dnj7aObyt7kqbM7vgHsvSpubXLjGc70Wos708PsdcEo=
872874
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.414/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
873875
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
874876
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.524/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=

tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2.go

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ func ResourceTencentCloudClsCloudProductLogTaskV2() *schema.Resource {
5858
"logset_name": {
5959
Type: schema.TypeString,
6060
Optional: true,
61+
ForceNew: true,
6162
Computed: true,
6263
Description: "Log set name, required if `logset_id` is not filled in. If the log set does not exist, it will be automatically created.",
6364
},
6465

6566
"topic_name": {
6667
Type: schema.TypeString,
6768
Optional: true,
69+
ForceNew: true,
6870
Computed: true,
6971
Description: "The name of the log topic is required when `topic_id` is not filled in. If the log theme does not exist, it will be automatically created.",
7072
},
@@ -79,13 +81,15 @@ func ResourceTencentCloudClsCloudProductLogTaskV2() *schema.Resource {
7981
"logset_id": {
8082
Type: schema.TypeString,
8183
Optional: true,
84+
ForceNew: true,
8285
Computed: true,
8386
Description: "Log set ID.",
8487
},
8588

8689
"topic_id": {
8790
Type: schema.TypeString,
8891
Optional: true,
92+
ForceNew: true,
8993
Computed: true,
9094
Description: "Log theme ID.",
9195
},
@@ -215,7 +219,7 @@ func resourceTencentCloudClsCloudProductLogTaskV2Read(d *schema.ResourceData, me
215219
return err
216220
}
217221

218-
if respData == nil {
222+
if respData == nil || len(respData.Tasks) < 1 {
219223
d.SetId("")
220224
log.Printf("[WARN]%s resource `cls_cloud_product_log_task` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
221225
return nil
@@ -226,37 +230,35 @@ func resourceTencentCloudClsCloudProductLogTaskV2Read(d *schema.ResourceData, me
226230
_ = d.Set("log_type", logType)
227231
_ = d.Set("cloud_product_region", cloudProductRegion)
228232

229-
if len(respData.Tasks) > 0 {
230-
if respData.Tasks[0].ClsRegion != nil {
231-
_ = d.Set("cls_region", respData.Tasks[0].ClsRegion)
232-
}
233+
if respData.Tasks[0].ClsRegion != nil {
234+
_ = d.Set("cls_region", respData.Tasks[0].ClsRegion)
235+
}
233236

234-
if respData.Tasks[0].Extend != nil {
235-
_ = d.Set("extend", respData.Tasks[0].Extend)
236-
}
237+
if respData.Tasks[0].Extend != nil {
238+
_ = d.Set("extend", respData.Tasks[0].Extend)
239+
}
237240

238-
if respData.Tasks[0].LogsetId != nil {
239-
_ = d.Set("logset_id", respData.Tasks[0].LogsetId)
240-
info, err := service.DescribeClsLogset(ctx, *respData.Tasks[0].LogsetId)
241-
if err != nil {
242-
return err
243-
}
241+
if respData.Tasks[0].LogsetId != nil {
242+
_ = d.Set("logset_id", respData.Tasks[0].LogsetId)
243+
info, err := service.DescribeClsLogset(ctx, *respData.Tasks[0].LogsetId)
244+
if err != nil {
245+
return err
246+
}
244247

245-
if info.LogsetName != nil {
246-
_ = d.Set("logset_name", info.LogsetName)
247-
}
248+
if info.LogsetName != nil {
249+
_ = d.Set("logset_name", info.LogsetName)
248250
}
251+
}
249252

250-
if respData.Tasks[0].TopicId != nil {
251-
_ = d.Set("topic_id", respData.Tasks[0].TopicId)
252-
info, err := service.DescribeClsTopicById(ctx, *respData.Tasks[0].TopicId)
253-
if err != nil {
254-
return err
255-
}
253+
if respData.Tasks[0].TopicId != nil {
254+
_ = d.Set("topic_id", respData.Tasks[0].TopicId)
255+
info, err := service.DescribeClsTopicById(ctx, *respData.Tasks[0].TopicId)
256+
if err != nil {
257+
return err
258+
}
256259

257-
if info.TopicName != nil {
258-
_ = d.Set("topic_name", info.TopicName)
259-
}
260+
if info.TopicName != nil {
261+
_ = d.Set("topic_name", info.TopicName)
260262
}
261263
}
262264

@@ -278,7 +280,7 @@ func resourceTencentCloudClsCloudProductLogTaskV2Update(d *schema.ResourceData,
278280
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
279281
)
280282

281-
immutableArgs := []string{"instance_id", "assumer_name", "log_type", "cloud_product_region", "cls_region", "logset_name", "topic_name", "logset_id", "topic_id"}
283+
immutableArgs := []string{"instance_id", "assumer_name", "log_type", "cloud_product_region", "cls_region"}
282284
for _, v := range immutableArgs {
283285
if d.HasChange(v) {
284286
return fmt.Errorf("argument `%s` cannot be changed", v)
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
Provides a resource to create a cls cloud product log task
22

3-
~> **NOTE:** Using this resource will create new `logset` and `topic`
3+
~> **NOTE:** In the destruction of resources, if cascading deletion of logset and topic is required, please set `force_delete` to `true`.
44

55
Example Usage
66

7+
Create log delivery using the default newly created logset and topic
8+
79
```hcl
8-
resource "tencentcloud_cls_cloud_product_log_task" "example" {
9-
instance_id = "postgres-1p7xvpc1"
10+
resource "tencentcloud_cls_cloud_product_log_task_v2" "example" {
11+
instance_id = "postgres-0an6hpv3"
1012
assumer_name = "PostgreSQL"
1113
log_type = "PostgreSQL-SLOW"
1214
cloud_product_region = "gz"
1315
cls_region = "ap-guangzhou"
1416
logset_name = "tf-example"
1517
topic_name = "tf-example"
18+
force_delete = true
19+
}
20+
```
21+
22+
Create log delivery using existing logset and topic
23+
24+
```hcl
25+
resource "tencentcloud_cls_cloud_product_log_task_v2" "example" {
26+
instance_id = "postgres-0an6hpv3"
27+
assumer_name = "PostgreSQL"
28+
log_type = "PostgreSQL-SLOW"
29+
cloud_product_region = "gz"
30+
cls_region = "ap-guangzhou"
31+
logset_id = "ca5b4f56-1174-4eee-bc4c-69e48e0e8c45"
32+
topic_id = "d8177ca9-466b-42f4-a110-5933daf0a83a"
33+
force_delete = false
1634
}
1735
```
1836

@@ -21,5 +39,5 @@ Import
2139
cls cloud product log task can be imported using the id, e.g.
2240

2341
```
24-
terraform import tencentcloud_cls_cloud_product_log_task.example postgres-1p7xvpc1#PostgreSQL#PostgreSQL-SLOW#gz
42+
terraform import tencentcloud_cls_cloud_product_log_task_v2.example postgres-1p7xvpc1#PostgreSQL#PostgreSQL-SLOW#gz
2543
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package cls_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
9+
)
10+
11+
// go test -i; go test -test.run TestAccTencentCloudNeedFixClsCloudProductLogTaskV2Resource_basic -v
12+
func TestAccTencentCloudNeedFixClsCloudProductLogTaskV2Resource_basic(t *testing.T) {
13+
t.Parallel()
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() {
16+
tcacctest.AccPreCheck(t)
17+
},
18+
Providers: tcacctest.AccProviders,
19+
Steps: []resource.TestStep{
20+
{
21+
Config: testAccClsCloudProductLogTaskV2,
22+
Check: resource.ComposeTestCheckFunc(
23+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "id"),
24+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "instance_id"),
25+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "assumer_name"),
26+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "log_type"),
27+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "cloud_product_region"),
28+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "cls_region"),
29+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "logset_name"),
30+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "topic_name"),
31+
),
32+
},
33+
{
34+
Config: testAccClsCloudProductLogTaskV2Update,
35+
Check: resource.ComposeTestCheckFunc(
36+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "id"),
37+
resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "extend"),
38+
),
39+
},
40+
{
41+
ResourceName: "tencentcloud_cls_cloud_product_log_task_v2.example",
42+
ImportState: true,
43+
ImportStateVerify: true,
44+
},
45+
},
46+
})
47+
}
48+
49+
const testAccClsCloudProductLogTaskV2 = `
50+
resource "tencentcloud_cls_cloud_product_log_task_v2" "example" {
51+
instance_id = "postgres-mcdstv8l"
52+
assumer_name = "PostgreSQL"
53+
log_type = "PostgreSQL-SLOW"
54+
cloud_product_region = "gz"
55+
cls_region = "ap-guangzhou"
56+
logset_name = "tf-example"
57+
topic_name = "tf-example"
58+
}
59+
`
60+
61+
const testAccClsCloudProductLogTaskV2Update = `
62+
resource "tencentcloud_cls_cloud_product_log_task_v2" "example" {
63+
instance_id = "postgres-mcdstv8l"
64+
assumer_name = "PostgreSQL"
65+
log_type = "PostgreSQL-SLOW"
66+
cloud_product_region = "gz"
67+
cls_region = "ap-guangzhou"
68+
logset_name = "tf-example"
69+
topic_name = "tf-example"
70+
extend = "{\"ServiceName\":[\"HDFS\",\"KNOX\",\"YARN\",\"ZOOKEEPER\"],\"Policy\":0}"
71+
}
72+
`

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016/client.go

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)