@@ -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 {
0 commit comments