@@ -5,10 +5,11 @@ Example Usage
55
66```hcl
77resource "tencentcloud_mysql_account" "default" {
8- mysql_id = "terraform-test-local-database"
9- name = "tf_account"
10- password = "********"
11- description = "My test account"
8+ mysql_id = "terraform-test-local-database"
9+ name = "tf_test"
10+ password = "********"
11+ description = "My test account"
12+ max_user_connections = 10
1213}
1314```
1415
@@ -76,6 +77,12 @@ func resourceTencentCloudMysqlAccount() *schema.Resource {
7677 ValidateFunc : validateStringLengthInRange (1 , 200 ),
7778 Description : "Database description." ,
7879 },
80+ "max_user_connections" : {
81+ Optional : true ,
82+ Computed : true ,
83+ Type : schema .TypeInt ,
84+ Description : "The maximum number of available connections for a new account, the default value is 10240, and the maximum value that can be set is 10240." ,
85+ },
7986 },
8087 }
8188}
@@ -94,9 +101,10 @@ func resourceTencentCloudMysqlAccountCreate(d *schema.ResourceData, meta interfa
94101 accountHost = d .Get ("host" ).(string )
95102 accountPassword = d .Get ("password" ).(string )
96103 accountDescription = d .Get ("description" ).(string )
104+ maxUserConnections = int64 (d .Get ("max_user_connections" ).(int ))
97105 )
98106
99- asyncRequestId , err := mysqlService .CreateAccount (ctx , mysqlId , accountName , accountHost , accountPassword , accountDescription )
107+ asyncRequestId , err := mysqlService .CreateAccount (ctx , mysqlId , accountName , accountHost , accountPassword , accountDescription , maxUserConnections )
100108 if err != nil {
101109 return err
102110 }
@@ -191,6 +199,8 @@ func resourceTencentCloudMysqlAccountRead(d *schema.ResourceData, meta interface
191199 _ = d .Set ("mysql_id" , mysqlId )
192200 _ = d .Set ("host" , * accountInfo .Host )
193201 _ = d .Set ("name" , * accountInfo .User )
202+ _ = d .Set ("max_user_connections" , * accountInfo .MaxUserConnections )
203+
194204 return nil
195205}
196206func resourceTencentCloudMysqlAccountUpdate (d * schema.ResourceData , meta interface {}) error {
@@ -274,6 +284,38 @@ func resourceTencentCloudMysqlAccountUpdate(d *schema.ResourceData, meta interfa
274284
275285 }
276286
287+ if d .HasChange ("max_user_connections" ) {
288+ var maxUserConnections int64
289+ if v , ok := d .GetOkExists ("max_user_connections" ); ok {
290+ maxUserConnections = int64 (v .(int ))
291+ }
292+ asyncRequestId , err := mysqlService .ModifyAccountMaxUserConnections (ctx , mysqlId , accountName , accountHost , maxUserConnections )
293+ if err != nil {
294+ return err
295+ }
296+
297+ err = resource .Retry (readRetryTimeout , func () * resource.RetryError {
298+ taskStatus , message , err := mysqlService .DescribeAsyncRequestInfo (ctx , asyncRequestId )
299+ if err != nil {
300+ return resource .NonRetryableError (err )
301+ }
302+ if taskStatus == MYSQL_TASK_STATUS_SUCCESS {
303+ return nil
304+ }
305+ if taskStatus == MYSQL_TASK_STATUS_INITIAL || taskStatus == MYSQL_TASK_STATUS_RUNNING {
306+ return resource .RetryableError (fmt .Errorf ("%s modify mysql account maxUserConnections %s task status is %s" , mysqlId , accountName , taskStatus ))
307+ }
308+ err = fmt .Errorf ("modify mysql account maxUserConnections task status is %s,we won't wait for it finish ,it show message:%s" , taskStatus , message )
309+ return resource .NonRetryableError (err )
310+ })
311+
312+ if err != nil {
313+ log .Printf ("[CRITAL]%s modify mysql account maxUserConnections fail, reason:%s\n " , logId , err .Error ())
314+ return err
315+ }
316+
317+ }
318+
277319 d .Partial (false )
278320
279321 return nil
0 commit comments