Skip to content

Commit 4b157cf

Browse files
committed
add
1 parent 9c51acc commit 4b157cf

4 files changed

+77
-83
lines changed

tencentcloud/services/cdb/resource_tc_mysql_cls_log_attachment.go

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ func ResourceTencentCloudMysqlClsLogAttachment() *schema.Resource {
2020
Create: resourceTencentCloudMysqlClsLogAttachmentCreate,
2121
Read: resourceTencentCloudMysqlClsLogAttachmentRead,
2222
Delete: resourceTencentCloudMysqlClsLogAttachmentDelete,
23-
Importer: &schema.ResourceImporter{
24-
State: schema.ImportStatePassthrough,
25-
},
23+
2624
Schema: map[string]*schema.Schema{
2725
"instance_id": {
2826
Required: true,
@@ -37,17 +35,29 @@ func ResourceTencentCloudMysqlClsLogAttachment() *schema.Resource {
3735
ValidateFunc: tccommon.ValidateAllowedStringValue(MYSQL_LOG_TO_CLS_TYPE),
3836
Description: "Log type. Support `error` or `slowlog`.",
3937
},
40-
"log_set_id": {
38+
"create_log_set": {
39+
Optional: true,
40+
ForceNew: true,
41+
Type: schema.TypeBool,
42+
Description: "Whether to create log set.",
43+
},
44+
"create_log_topic": {
45+
Optional: true,
46+
ForceNew: true,
47+
Type: schema.TypeBool,
48+
Description: "Whether to create log topic.",
49+
},
50+
"log_set": {
4151
Required: true,
4252
ForceNew: true,
4353
Type: schema.TypeString,
44-
Description: "Log set Id.",
54+
Description: "If `create_log_set` is `true`, use log set name, Else use log set Id.",
4555
},
46-
"log_topic_id": {
56+
"log_topic": {
4757
Required: true,
4858
ForceNew: true,
4959
Type: schema.TypeString,
50-
Description: "Log topic Id.",
60+
Description: "If `create_log_topic` is `true`, use log topic name, Else use log topic Id.",
5161
},
5262
"period": {
5363
Optional: true,
@@ -67,6 +77,16 @@ func ResourceTencentCloudMysqlClsLogAttachment() *schema.Resource {
6777
Type: schema.TypeString,
6878
Description: "Cls region.",
6979
},
80+
"log_set_id": {
81+
Computed: true,
82+
Type: schema.TypeString,
83+
Description: "Log set Id.",
84+
},
85+
"log_topic_id": {
86+
Computed: true,
87+
Type: schema.TypeString,
88+
Description: "Log topic Id.",
89+
},
7090
"status": {
7191
Computed: true,
7292
Type: schema.TypeString,
@@ -97,11 +117,19 @@ func resourceTencentCloudMysqlClsLogAttachmentCreate(d *schema.ResourceData, met
97117
request.LogType = helper.String(v.(string))
98118
}
99119

100-
if v, ok := d.GetOk("log_set_id"); ok {
120+
if v, ok := d.GetOkExists("create_log_set"); ok {
121+
request.CreateLogset = helper.Bool(v.(bool))
122+
}
123+
124+
if v, ok := d.GetOkExists("create_log_topic"); ok {
125+
request.CreateLogTopic = helper.Bool(v.(bool))
126+
}
127+
128+
if v, ok := d.GetOk("log_set"); ok {
101129
request.Logset = helper.String(v.(string))
102130
}
103131

104-
if v, ok := d.GetOk("log_topic_id"); ok {
132+
if v, ok := d.GetOk("log_topic"); ok {
105133
request.LogTopic = helper.String(v.(string))
106134
}
107135

@@ -118,8 +146,6 @@ func resourceTencentCloudMysqlClsLogAttachmentCreate(d *schema.ResourceData, met
118146
}
119147

120148
request.Status = helper.String("ON")
121-
request.CreateLogset = helper.Bool(false)
122-
request.CreateLogTopic = helper.Bool(false)
123149
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
124150
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMysqlClient().ModifyDBInstanceLogToCLS(request)
125151
if e != nil {

tencentcloud/services/cdb/resource_tc_mysql_cls_log_attachment.md

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to create a mysql log to cls
22

3+
~> **NOTE:** The CLS resource bound to resource `tencentcloud_mysql_cls_log_attachment` needs to be manually deleted.
4+
35
Example Usage
46

57
Create Error Log to ClS
@@ -53,48 +55,28 @@ resource "tencentcloud_mysql_instance" "example" {
5355
}
5456
}
5557
56-
# create cls logset
57-
resource "tencentcloud_cls_logset" "example" {
58-
logset_name = "tf_example"
59-
tags = {
60-
tagKey = "tagValue"
61-
}
62-
}
63-
64-
# create cls topic
65-
resource "tencentcloud_cls_topic" "example" {
66-
topic_name = "tf_example"
67-
logset_id = tencentcloud_cls_logset.example.id
68-
auto_split = false
69-
max_split_partitions = 20
70-
partition_count = 1
71-
period = 30
72-
storage_type = "hot"
73-
tags = {
74-
tagKey = "tagValue"
75-
}
76-
}
77-
7858
# attachment cls log
7959
resource "tencentcloud_mysql_cls_log_attachment" "example" {
80-
instance_id = tencentcloud_mysql_instance.example.id
81-
log_type = "error"
82-
log_set_id = tencentcloud_cls_logset.example.id
83-
log_topic_id = tencentcloud_cls_topic.example.id
84-
period = 30
85-
create_index = true
86-
cls_region = "ap-guangzhou"
60+
instance_id = tencentcloud_mysql_instance.example.id
61+
log_type = "error"
62+
create_log_set = true
63+
create_log_topic = true
64+
log_set = "tf_log_set"
65+
log_topic = "tf_log_topic"
66+
period = 30
67+
create_index = true
68+
cls_region = "ap-guangzhou"
8769
}
8870
```
8971

9072
Create Slow Log to ClS
9173

9274
```hcl
9375
resource "tencentcloud_mysql_cls_log_attachment" "example" {
94-
instance_id = tencentcloud_mysql_instance.example.id
95-
log_type = "slowlog"
96-
log_set_id = tencentcloud_cls_logset.example.id
97-
log_topic_id = tencentcloud_cls_topic.example.id
76+
instance_id = tencentcloud_mysql_instance.example.id
77+
log_type = "slowlog"
78+
log_set = "50d499a8-c4c0-4442-aa04-e8aa8a02437d"
79+
log_topic = "140d4d39-4307-45a8-9655-290f679b063d"
9880
}
9981
```
10082

tencentcloud/services/cdb/resource_tc_mysql_cls_log_attachment_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func TestAccTencentCloudNeedFixMysqlClsLogAttachmentResource(t *testing.T) {
2222
resource.TestCheckResourceAttrSet("tencentcloud_mysql_cls_log_attachment.example", "id"),
2323
resource.TestCheckResourceAttr("tencentcloud_mysql_cls_log_attachment.example", "instance_id", "cdb-8fk7id2l"),
2424
resource.TestCheckResourceAttr("tencentcloud_mysql_cls_log_attachment.example", "log_type", "slowlog"),
25-
resource.TestCheckResourceAttr("tencentcloud_mysql_cls_log_attachment.example", "log_set_id", "cb4ca863-13b4-489a-b3ef-aae3b0f1b172"),
26-
resource.TestCheckResourceAttr("tencentcloud_mysql_cls_log_attachment.example", "log_topic_id", "286cb422-c09d-4d9c-96ab-107b6bba1561"),
25+
resource.TestCheckResourceAttr("tencentcloud_mysql_cls_log_attachment.example", "log_set", "cb4ca863-13b4-489a-b3ef-aae3b0f1b172"),
26+
resource.TestCheckResourceAttr("tencentcloud_mysql_cls_log_attachment.example", "log_topic", "286cb422-c09d-4d9c-96ab-107b6bba1561"),
2727
resource.TestCheckResourceAttr("tencentcloud_mysql_cls_log_attachment.example", "period", "30"),
2828
resource.TestCheckResourceAttr("tencentcloud_mysql_cls_log_attachment.example", "create_index", "true"),
2929
resource.TestCheckResourceAttr("tencentcloud_mysql_cls_log_attachment.example", "cls_region", "ap-guangzhou"),
@@ -43,8 +43,8 @@ const testAccClsLogAttachment = `
4343
resource "tencentcloud_mysql_cls_log_attachment" "example" {
4444
instance_id = "cdb-8fk7id2l"
4545
log_type = "slowlog"
46-
log_set_id = "cb4ca863-13b4-489a-b3ef-aae3b0f1b172"
47-
log_topic_id = "286cb422-c09d-4d9c-96ab-107b6bba1561"
46+
log_set = "cb4ca863-13b4-489a-b3ef-aae3b0f1b172"
47+
log_topic = "286cb422-c09d-4d9c-96ab-107b6bba1561"
4848
period = 30
4949
create_index = true
5050
cls_region = "ap-guangzhou"

website/docs/r/mysql_cls_log_attachment.html.markdown

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ description: |-
1111

1212
Provides a resource to create a mysql log to cls
1313

14+
~> **NOTE:** The CLS resource bound to resource `tencentcloud_mysql_cls_log_attachment` needs to be manually deleted.
15+
1416
## Example Usage
1517

1618
### Create Error Log to ClS
@@ -64,48 +66,28 @@ resource "tencentcloud_mysql_instance" "example" {
6466
}
6567
}
6668
67-
# create cls logset
68-
resource "tencentcloud_cls_logset" "example" {
69-
logset_name = "tf_example"
70-
tags = {
71-
tagKey = "tagValue"
72-
}
73-
}
74-
75-
# create cls topic
76-
resource "tencentcloud_cls_topic" "example" {
77-
topic_name = "tf_example"
78-
logset_id = tencentcloud_cls_logset.example.id
79-
auto_split = false
80-
max_split_partitions = 20
81-
partition_count = 1
82-
period = 30
83-
storage_type = "hot"
84-
tags = {
85-
tagKey = "tagValue"
86-
}
87-
}
88-
8969
# attachment cls log
9070
resource "tencentcloud_mysql_cls_log_attachment" "example" {
91-
instance_id = tencentcloud_mysql_instance.example.id
92-
log_type = "error"
93-
log_set_id = tencentcloud_cls_logset.example.id
94-
log_topic_id = tencentcloud_cls_topic.example.id
95-
period = 30
96-
create_index = true
97-
cls_region = "ap-guangzhou"
71+
instance_id = tencentcloud_mysql_instance.example.id
72+
log_type = "error"
73+
create_log_set = true
74+
create_log_topic = true
75+
log_set = "tf_log_set"
76+
log_topic = "tf_log_topic"
77+
period = 30
78+
create_index = true
79+
cls_region = "ap-guangzhou"
9880
}
9981
```
10082

10183
### Create Slow Log to ClS
10284

10385
```hcl
10486
resource "tencentcloud_mysql_cls_log_attachment" "example" {
105-
instance_id = tencentcloud_mysql_instance.example.id
106-
log_type = "slowlog"
107-
log_set_id = tencentcloud_cls_logset.example.id
108-
log_topic_id = tencentcloud_cls_topic.example.id
87+
instance_id = tencentcloud_mysql_instance.example.id
88+
log_type = "slowlog"
89+
log_set = "50d499a8-c4c0-4442-aa04-e8aa8a02437d"
90+
log_topic = "140d4d39-4307-45a8-9655-290f679b063d"
10991
}
11092
```
11193

@@ -114,18 +96,22 @@ resource "tencentcloud_mysql_cls_log_attachment" "example" {
11496
The following arguments are supported:
11597

11698
* `instance_id` - (Required, String, ForceNew) The id of instance.
117-
* `log_set_id` - (Required, String, ForceNew) Log set Id.
118-
* `log_topic_id` - (Required, String, ForceNew) Log topic Id.
99+
* `log_set` - (Required, String, ForceNew) If `create_log_set` is `true`, use log set name, Else use log set Id.
100+
* `log_topic` - (Required, String, ForceNew) If `create_log_topic` is `true`, use log topic name, Else use log topic Id.
119101
* `log_type` - (Required, String, ForceNew) Log type. Support `error` or `slowlog`.
120102
* `cls_region` - (Optional, String) Cls region.
121103
* `create_index` - (Optional, Bool, ForceNew) Whether to create index.
104+
* `create_log_set` - (Optional, Bool, ForceNew) Whether to create log set.
105+
* `create_log_topic` - (Optional, Bool, ForceNew) Whether to create log topic.
122106
* `period` - (Optional, Int, ForceNew) The validity period of the log theme is 30 days by default when not filled in.
123107

124108
## Attributes Reference
125109

126110
In addition to all arguments above, the following attributes are exported:
127111

128112
* `id` - ID of the resource.
113+
* `log_set_id` - Log set Id.
114+
* `log_topic_id` - Log topic Id.
129115
* `status` - Log Status.
130116

131117

0 commit comments

Comments
 (0)