Skip to content

Commit fbda8b7

Browse files
authored
add cdb param list (#1777)
* add cdb param list * add changelog
1 parent bf66a2a commit fbda8b7

File tree

4 files changed

+142
-37
lines changed

4 files changed

+142
-37
lines changed

.changelog/1777.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_mysql_param_template: support set `param_list`
3+
```

tencentcloud/resource_tc_mysql_param_template.go

Lines changed: 102 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,20 @@ resource "tencentcloud_mysql_param_template" "param_template" {
88
name = "terraform-test"
99
description = "terraform-test"
1010
engine_version = "8.0"
11-
template_type = "HIGH_STABILITY"
12-
engine_type = "InnoDB"
11+
param_list {
12+
current_value = "1"
13+
name = "auto_increment_increment"
14+
}
15+
param_list {
16+
current_value = "1"
17+
name = "auto_increment_offset"
18+
}
19+
param_list {
20+
current_value = "ON"
21+
name = "automatic_sp_privileges"
22+
}
23+
template_type = "HIGH_STABILITY"
24+
engine_type = "InnoDB"
1325
}
1426
```
1527
@@ -62,43 +74,47 @@ func resourceTencentCloudMysqlParamTemplate() *schema.Resource {
6274
Description: "The version of MySQL.",
6375
},
6476

65-
"template_type": {
66-
Optional: true,
67-
Type: schema.TypeString,
68-
Description: "The default type of parameter template, supported value is HIGH_STABILITY or HIGH_PERFORMANCE.",
69-
},
70-
71-
"engine_type": {
72-
Optional: true,
73-
Type: schema.TypeString,
74-
Description: "The engine type of instance, optional value is InnoDB or RocksDB, default to InnoDB.",
75-
},
76-
7777
"template_id": {
78+
Optional: true,
7879
Computed: true,
7980
Type: schema.TypeInt,
8081
Description: "The ID of source parameter template.",
8182
},
8283

8384
"param_list": {
85+
Optional: true,
8486
Computed: true,
8587
Type: schema.TypeList,
8688
Description: "parameter list.",
8789
Elem: &schema.Resource{
8890
Schema: map[string]*schema.Schema{
8991
"name": {
9092
Type: schema.TypeString,
93+
Optional: true,
9194
Computed: true,
9295
Description: "The name of parameter.",
9396
},
9497
"current_value": {
9598
Type: schema.TypeString,
99+
Optional: true,
96100
Computed: true,
97101
Description: "The value of parameter.",
98102
},
99103
},
100104
},
101105
},
106+
107+
"template_type": {
108+
Optional: true,
109+
Type: schema.TypeString,
110+
Description: "The default type of parameter template, supported value is HIGH_STABILITY or HIGH_PERFORMANCE.",
111+
},
112+
113+
"engine_type": {
114+
Optional: true,
115+
Type: schema.TypeString,
116+
Description: "The engine type of instance, optional value is InnoDB or RocksDB, default to InnoDB.",
117+
},
102118
},
103119
}
104120
}
@@ -126,6 +142,24 @@ func resourceTencentCloudMysqlParamTemplateCreate(d *schema.ResourceData, meta i
126142
request.EngineVersion = helper.String(v.(string))
127143
}
128144

145+
if v, ok := d.GetOkExists("template_id"); ok {
146+
request.TemplateId = helper.IntInt64(v.(int))
147+
}
148+
149+
if v, ok := d.GetOk("param_list"); ok {
150+
for _, item := range v.([]interface{}) {
151+
dMap := item.(map[string]interface{})
152+
parameter := mysql.Parameter{}
153+
if v, ok := dMap["name"]; ok {
154+
parameter.Name = helper.String(v.(string))
155+
}
156+
if v, ok := dMap["current_value"]; ok {
157+
parameter.CurrentValue = helper.String(v.(string))
158+
}
159+
request.ParamList = append(request.ParamList, &parameter)
160+
}
161+
}
162+
129163
if v, ok := d.GetOk("template_type"); ok {
130164
request.TemplateType = helper.String(v.(string))
131165
}
@@ -189,27 +223,50 @@ func resourceTencentCloudMysqlParamTemplateRead(d *schema.ResourceData, meta int
189223
_ = d.Set("engine_version", paramTemplate.EngineVersion)
190224
}
191225

192-
if paramTemplate.TemplateId != nil {
193-
_ = d.Set("template_id", paramTemplate.TemplateId)
226+
params := make([]string, 0)
227+
if v, ok := d.GetOk("param_list"); ok {
228+
for _, item := range v.([]interface{}) {
229+
if item != nil {
230+
dMap := item.(map[string]interface{})
231+
if v, ok := dMap["name"]; ok {
232+
params = append(params, v.(string))
233+
}
234+
}
235+
}
194236
}
195237

196238
if paramTemplate.Items != nil {
197-
paramListList := []interface{}{}
198-
for _, paramList := range paramTemplate.Items {
199-
paramListMap := map[string]interface{}{}
200-
201-
if paramList.Name != nil {
202-
paramListMap["name"] = paramList.Name
239+
paramItemsList := []interface{}{}
240+
if len(params) > 0 {
241+
// if set params list
242+
for _, param := range params {
243+
for _, paramList := range paramTemplate.Items {
244+
if *paramList.Name == param {
245+
paramListMap := map[string]interface{}{}
246+
if paramList.Name != nil {
247+
paramListMap["name"] = paramList.Name
248+
}
249+
if paramList.CurrentValue != nil {
250+
paramListMap["current_value"] = paramList.CurrentValue
251+
}
252+
paramItemsList = append(paramItemsList, paramListMap)
253+
}
254+
}
203255
}
204-
205-
if paramList.CurrentValue != nil {
206-
paramListMap["current_value"] = paramList.CurrentValue
256+
} else {
257+
// if not set params list
258+
for _, paramList := range paramTemplate.Items {
259+
paramListMap := map[string]interface{}{}
260+
if paramList.Name != nil {
261+
paramListMap["name"] = paramList.Name
262+
}
263+
if paramList.CurrentValue != nil {
264+
paramListMap["current_value"] = paramList.CurrentValue
265+
}
266+
paramItemsList = append(paramItemsList, paramListMap)
207267
}
208-
209-
paramListList = append(paramListList, paramListMap)
210268
}
211-
212-
_ = d.Set("param_list", paramListList)
269+
_ = d.Set("param_list", paramItemsList)
213270

214271
}
215272

@@ -252,6 +309,22 @@ func resourceTencentCloudMysqlParamTemplateUpdate(d *schema.ResourceData, meta i
252309
}
253310
}
254311

312+
if d.HasChange("param_list") {
313+
if v, ok := d.GetOk("param_list"); ok {
314+
for _, item := range v.([]interface{}) {
315+
dMap := item.(map[string]interface{})
316+
parameter := mysql.Parameter{}
317+
if v, ok := dMap["name"]; ok {
318+
parameter.Name = helper.String(v.(string))
319+
}
320+
if v, ok := dMap["current_value"]; ok {
321+
parameter.CurrentValue = helper.String(v.(string))
322+
}
323+
request.ParamList = append(request.ParamList, &parameter)
324+
}
325+
}
326+
}
327+
255328
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
256329
result, e := meta.(*TencentCloudClient).apiV3Conn.UseMysqlClient().ModifyParamTemplate(request)
257330
if e != nil {

tencentcloud/resource_tc_mysql_param_template_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestAccTencentCloudMysqlParamTemplateResource_basic(t *testing.T) {
2424
ImportStateVerify: true,
2525
ImportStateVerifyIgnore: []string{
2626
"engine_type",
27+
"param_list",
2728
},
2829
},
2930
},
@@ -36,8 +37,20 @@ resource "tencentcloud_mysql_param_template" "param_template" {
3637
name = "terraform-test"
3738
description = "terraform-test"
3839
engine_version = "8.0"
39-
template_type = "HIGH_STABILITY"
40-
engine_type = "InnoDB"
40+
param_list {
41+
current_value = "1"
42+
name = "auto_increment_increment"
43+
}
44+
param_list {
45+
current_value = "1"
46+
name = "auto_increment_offset"
47+
}
48+
param_list {
49+
current_value = "ON"
50+
name = "automatic_sp_privileges"
51+
}
52+
template_type = "HIGH_STABILITY"
53+
engine_type = "InnoDB"
4154
}
4255
4356
`

website/docs/r/mysql_param_template.html.markdown

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,20 @@ resource "tencentcloud_mysql_param_template" "param_template" {
1818
name = "terraform-test"
1919
description = "terraform-test"
2020
engine_version = "8.0"
21-
template_type = "HIGH_STABILITY"
22-
engine_type = "InnoDB"
21+
param_list {
22+
current_value = "1"
23+
name = "auto_increment_increment"
24+
}
25+
param_list {
26+
current_value = "1"
27+
name = "auto_increment_offset"
28+
}
29+
param_list {
30+
current_value = "ON"
31+
name = "automatic_sp_privileges"
32+
}
33+
template_type = "HIGH_STABILITY"
34+
engine_type = "InnoDB"
2335
}
2436
```
2537

@@ -31,17 +43,21 @@ The following arguments are supported:
3143
* `description` - (Optional, String) The description of parameter template.
3244
* `engine_type` - (Optional, String) The engine type of instance, optional value is InnoDB or RocksDB, default to InnoDB.
3345
* `engine_version` - (Optional, String) The version of MySQL.
46+
* `param_list` - (Optional, List) parameter list.
47+
* `template_id` - (Optional, Int) The ID of source parameter template.
3448
* `template_type` - (Optional, String) The default type of parameter template, supported value is HIGH_STABILITY or HIGH_PERFORMANCE.
3549

50+
The `param_list` object supports the following:
51+
52+
* `current_value` - (Optional, String) The value of parameter.
53+
* `name` - (Optional, String) The name of parameter.
54+
3655
## Attributes Reference
3756

3857
In addition to all arguments above, the following attributes are exported:
3958

4059
* `id` - ID of the resource.
41-
* `param_list` - parameter list.
42-
* `current_value` - The value of parameter.
43-
* `name` - The name of parameter.
44-
* `template_id` - The ID of source parameter template.
60+
4561

4662

4763
## Import

0 commit comments

Comments
 (0)