@@ -25,26 +25,6 @@ type ResourceTencentCloudMysqlPrivilegeId struct {
25
25
AccountHost string `json:"AccountHost,omitempty"`
26
26
}
27
27
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
-
48
28
func ResourceTencentCloudMysqlPrivilege () * schema.Resource {
49
29
return & schema.Resource {
50
30
Create : resourceTencentCloudMysqlPrivilegeCreate ,
@@ -94,7 +74,6 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
94
74
Type : schema .TypeSet ,
95
75
Optional : true ,
96
76
Description : "Database privileges list." ,
97
- Set : resourceTencentCloudMysqlPrivilegeHash ,
98
77
Elem : & schema.Resource {
99
78
Schema : map [string ]* schema.Schema {
100
79
"database_name" : {
@@ -103,12 +82,9 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
103
82
Description : "Database name." ,
104
83
},
105
84
"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 },
112
88
Description : `Database privilege.available values for Privileges:` + strings .Join (MYSQL_DATABASE_PRIVILEGE , "," ) + "." ,
113
89
},
114
90
},
@@ -118,7 +94,6 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
118
94
Type : schema .TypeSet ,
119
95
Optional : true ,
120
96
Description : "Table privileges list." ,
121
- Set : resourceTencentCloudMysqlPrivilegeHash ,
122
97
Elem : & schema.Resource {
123
98
Schema : map [string ]* schema.Schema {
124
99
"database_name" : {
@@ -132,12 +107,9 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
132
107
Description : "Table name." ,
133
108
},
134
109
"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 },
141
113
Description : `Table privilege.available values for Privileges:` + strings .Join (MYSQL_TABLE_PRIVILEGE , "," ) + "." ,
142
114
},
143
115
},
@@ -147,7 +119,6 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
147
119
Type : schema .TypeSet ,
148
120
Optional : true ,
149
121
Description : "Column privileges list." ,
150
- Set : resourceTencentCloudMysqlPrivilegeHash ,
151
122
Elem : & schema.Resource {
152
123
Schema : map [string ]* schema.Schema {
153
124
"database_name" : {
@@ -166,12 +137,9 @@ func ResourceTencentCloudMysqlPrivilege() *schema.Resource {
166
137
Description : "Column name." ,
167
138
},
168
139
"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 },
175
143
Description : `Column privilege.available values for Privileges:` + strings .Join (MYSQL_COLUMN_PRIVILEGE , "," ) + "." ,
176
144
},
177
145
},
@@ -209,93 +177,66 @@ func (me *ResourceTencentCloudMysqlPrivilegeId) update(ctx context.Context, d *s
209
177
}
210
178
}
211
179
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 ))
225
186
}
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 )))
236
191
}
237
- p .Privileges = append ( p . Privileges , ptr )
192
+ privilege .Privileges = privilegeList
238
193
}
239
- request .DatabasePrivileges = append (request .DatabasePrivileges , p )
194
+ request .DatabasePrivileges = append (request .DatabasePrivileges , & privilege )
240
195
}
241
196
}
242
197
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 ))
254
204
}
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 ))
260
207
}
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 )) )
265
212
}
266
- p .Privileges = append ( p . Privileges , ptr )
213
+ privilege .Privileges = privilegeList
267
214
}
268
- request .TablePrivileges = append (request .TablePrivileges , p )
215
+ request .TablePrivileges = append (request .TablePrivileges , & privilege )
269
216
}
270
217
}
271
218
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 ))
283
225
}
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 ))
290
231
}
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 )) )
295
236
}
296
- p .Privileges = append ( p . Privileges , ptr )
237
+ privilege .Privileges = privilegeList
297
238
}
298
- request .ColumnPrivileges = append (request .ColumnPrivileges , p )
239
+ request .ColumnPrivileges = append (request .ColumnPrivileges , & privilege )
299
240
}
300
241
}
301
242
}
0 commit comments