@@ -25,26 +25,6 @@ type ResourceTencentCloudMysqlPrivilegeId struct {
2525 AccountHost string `json:"AccountHost,omitempty"`
2626}
2727
28- func resourceTencentCloudMysqlPrivilegeHash (v interface {}) int {
29- vmap := v .(map [string ]interface {})
30- hashMap := map [string ]interface {}{}
31- hashMap ["database_name" ] = vmap ["database_name" ]
32-
33- if vmap ["table_name" ] != nil {
34- hashMap ["table_name" ] = vmap ["table_name" ]
35- }
36- if hashMap ["column_name" ] != nil {
37- hashMap ["column_name" ] = vmap ["column_name" ]
38- }
39- slice := []string {}
40- for _ , v := range vmap ["privileges" ].(* schema.Set ).List () {
41- slice = append (slice , v .(string ))
42- }
43- hashMap ["privileges" ] = slice
44- b , _ := json .Marshal (hashMap )
45- return helper .HashString (string (b ))
46- }
47-
4828func ResourceTencentCloudMysqlPrivilege () * schema.Resource {
4929 return & schema.Resource {
5030 Create : resourceTencentCloudMysqlPrivilegeCreate ,
@@ -94,7 +74,6 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
9474 Type : schema .TypeSet ,
9575 Optional : true ,
9676 Description : "Database privileges list." ,
97- Set : resourceTencentCloudMysqlPrivilegeHash ,
9877 Elem : & schema.Resource {
9978 Schema : map [string ]* schema.Schema {
10079 "database_name" : {
@@ -103,12 +82,9 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
10382 Description : "Database name." ,
10483 },
10584 "privileges" : {
106- Type : schema .TypeSet ,
107- Required : true ,
108- Elem : & schema.Schema {Type : schema .TypeString },
109- Set : func (v interface {}) int {
110- return helper .HashString (v .(string ))
111- },
85+ Type : schema .TypeSet ,
86+ Required : true ,
87+ Elem : & schema.Schema {Type : schema .TypeString },
11288 Description : `Database privilege.available values for Privileges:` + strings .Join (MYSQL_DATABASE_PRIVILEGE , "," ) + "." ,
11389 },
11490 },
@@ -118,7 +94,6 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
11894 Type : schema .TypeSet ,
11995 Optional : true ,
12096 Description : "Table privileges list." ,
121- Set : resourceTencentCloudMysqlPrivilegeHash ,
12297 Elem : & schema.Resource {
12398 Schema : map [string ]* schema.Schema {
12499 "database_name" : {
@@ -132,12 +107,9 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
132107 Description : "Table name." ,
133108 },
134109 "privileges" : {
135- Type : schema .TypeSet ,
136- Required : true ,
137- Elem : & schema.Schema {Type : schema .TypeString },
138- Set : func (v interface {}) int {
139- return helper .HashString (v .(string ))
140- },
110+ Type : schema .TypeSet ,
111+ Required : true ,
112+ Elem : & schema.Schema {Type : schema .TypeString },
141113 Description : `Table privilege.available values for Privileges:` + strings .Join (MYSQL_TABLE_PRIVILEGE , "," ) + "." ,
142114 },
143115 },
@@ -147,7 +119,6 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
147119 Type : schema .TypeSet ,
148120 Optional : true ,
149121 Description : "Column privileges list." ,
150- Set : resourceTencentCloudMysqlPrivilegeHash ,
151122 Elem : & schema.Resource {
152123 Schema : map [string ]* schema.Schema {
153124 "database_name" : {
@@ -166,12 +137,9 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
166137 Description : "Column name." ,
167138 },
168139 "privileges" : {
169- Type : schema .TypeSet ,
170- Required : true ,
171- Elem : & schema.Schema {Type : schema .TypeString },
172- Set : func (v interface {}) int {
173- return helper .HashString (v .(string ))
174- },
140+ Type : schema .TypeSet ,
141+ Required : true ,
142+ Elem : & schema.Schema {Type : schema .TypeString },
175143 Description : `Column privilege.available values for Privileges:` + strings .Join (MYSQL_COLUMN_PRIVILEGE , "," ) + "." ,
176144 },
177145 },
@@ -209,93 +177,66 @@ func (me *ResourceTencentCloudMysqlPrivilegeId) update(ctx context.Context, d *s
209177 }
210178 }
211179
212- same := map [string ]bool {}
213-
214- sliceInterface = d .Get ("database" ).(* schema.Set ).List ()
215- if len (sliceInterface ) > 0 {
216- request .DatabasePrivileges = make ([]* cdb.DatabasePrivilege , 0 , len (sliceInterface ))
217- for _ , v := range sliceInterface {
218- vmap := v .(map [string ]interface {})
219-
220- trace := * sp (vmap ["database_name" ])
221- if same [trace ] {
222- return errors .New ("can not assign two permissions to a database and an account," + trace )
223- } else {
224- same [trace ] = true
180+ if v , ok := d .GetOk ("database" ); ok {
181+ for _ , item := range v .(* schema.Set ).List () {
182+ dMap := item .(map [string ]interface {})
183+ privilege := cdb.DatabasePrivilege {}
184+ if v , ok := dMap ["database_name" ]; ok {
185+ privilege .Database = helper .String (v .(string ))
225186 }
226-
227- p := & cdb.DatabasePrivilege {
228- Database : sp (vmap ["database_name" ]),
229- Privileges : []* string {},
230- }
231-
232- for _ , privilege := range vmap ["privileges" ].(* schema.Set ).List () {
233- ptr := sp (privilege )
234- if ! tccommon .IsContains (MYSQL_DATABASE_PRIVILEGE , * ptr ) {
235- return errors .New ("database privileges not support:" + * ptr )
187+ if v , ok := dMap ["privileges" ]; ok {
188+ privilegeList := []* string {}
189+ for _ , v := range v .(* schema.Set ).List () {
190+ privilegeList = append (privilegeList , helper .String (v .(string )))
236191 }
237- p .Privileges = append ( p . Privileges , ptr )
192+ privilege .Privileges = privilegeList
238193 }
239- request .DatabasePrivileges = append (request .DatabasePrivileges , p )
194+ request .DatabasePrivileges = append (request .DatabasePrivileges , & privilege )
240195 }
241196 }
242197
243- sliceInterface = d .Get ("table" ).(* schema.Set ).List ()
244- if len (sliceInterface ) > 0 {
245- request .TablePrivileges = make ([]* cdb.TablePrivilege , 0 , len (sliceInterface ))
246- for _ , v := range sliceInterface {
247- vmap := v .(map [string ]interface {})
248-
249- trace := * sp (vmap ["database_name" ]) + "." + * sp (vmap ["table_name" ])
250- if same [trace ] {
251- return errors .New ("can not assign two permissions to a table and an account," + trace )
252- } else {
253- same [trace ] = true
198+ if v , ok := d .GetOk ("table" ); ok {
199+ for _ , item := range v .(* schema.Set ).List () {
200+ dMap := item .(map [string ]interface {})
201+ privilege := cdb.TablePrivilege {}
202+ if v , ok := dMap ["database_name" ]; ok {
203+ privilege .Database = helper .String (v .(string ))
254204 }
255-
256- p := & cdb.TablePrivilege {
257- Database : sp (vmap ["database_name" ]),
258- Table : sp (vmap ["table_name" ]),
259- Privileges : []* string {},
205+ if v , ok := dMap ["table_name" ]; ok {
206+ privilege .Table = helper .String (v .(string ))
260207 }
261- for _ , privilege := range vmap ["privileges" ].( * schema. Set ). List () {
262- ptr := sp ( privilege )
263- if ! tccommon . IsContains ( MYSQL_TABLE_PRIVILEGE , * ptr ) {
264- return errors . New ( "table privileges not support:" + * ptr )
208+ if v , ok := dMap ["privileges" ]; ok {
209+ privilegeList := [] * string {}
210+ for _ , v := range v .( * schema. Set ). List ( ) {
211+ privilegeList = append ( privilegeList , helper . String ( v .( string )) )
265212 }
266- p .Privileges = append ( p . Privileges , ptr )
213+ privilege .Privileges = privilegeList
267214 }
268- request .TablePrivileges = append (request .TablePrivileges , p )
215+ request .TablePrivileges = append (request .TablePrivileges , & privilege )
269216 }
270217 }
271218
272- sliceInterface = d .Get ("column" ).(* schema.Set ).List ()
273- if len (sliceInterface ) > 0 {
274- request .ColumnPrivileges = make ([]* cdb.ColumnPrivilege , 0 , len (sliceInterface ))
275- for _ , v := range sliceInterface {
276- vmap := v .(map [string ]interface {})
277-
278- trace := * sp (vmap ["database_name" ]) + "." + * sp (vmap ["table_name" ]) + "." + * sp (vmap ["column_name" ])
279- if same [trace ] {
280- return errors .New ("can not assign two permissions to a column and an account," + trace )
281- } else {
282- same [trace ] = true
219+ if v , ok := d .GetOk ("column" ); ok {
220+ for _ , item := range v .(* schema.Set ).List () {
221+ dMap := item .(map [string ]interface {})
222+ privilege := cdb.ColumnPrivilege {}
223+ if v , ok := dMap ["database_name" ]; ok {
224+ privilege .Database = helper .String (v .(string ))
283225 }
284-
285- p := & cdb.ColumnPrivilege {
286- Database : sp (vmap ["database_name" ]),
287- Table : sp (vmap ["table_name" ]),
288- Column : sp (vmap ["column_name" ]),
289- Privileges : []* string {},
226+ if v , ok := dMap ["table_name" ]; ok {
227+ privilege .Table = helper .String (v .(string ))
228+ }
229+ if v , ok := dMap ["column_name" ]; ok {
230+ privilege .Column = helper .String (v .(string ))
290231 }
291- for _ , privilege := range vmap ["privileges" ].( * schema. Set ). List () {
292- ptr := sp ( privilege )
293- if ! tccommon . IsContains ( MYSQL_COLUMN_PRIVILEGE , * ptr ) {
294- return errors . New ( "column privileges not support:" + * ptr )
232+ if v , ok := dMap ["privileges" ]; ok {
233+ privilegeList := [] * string {}
234+ for _ , v := range v .( * schema. Set ). List ( ) {
235+ privilegeList = append ( privilegeList , helper . String ( v .( string )) )
295236 }
296- p .Privileges = append ( p . Privileges , ptr )
237+ privilege .Privileges = privilegeList
297238 }
298- request .ColumnPrivileges = append (request .ColumnPrivileges , p )
239+ request .ColumnPrivileges = append (request .ColumnPrivileges , & privilege )
299240 }
300241 }
301242 }
0 commit comments