@@ -57,6 +57,7 @@ package tencentcloud
57
57
import (
58
58
"context"
59
59
"fmt"
60
+ "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
60
61
"strings"
61
62
62
63
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -109,6 +110,16 @@ func resourceTencentCloudPostgresqlInstance() *schema.Resource {
109
110
Optional : true ,
110
111
Description : "ID of subnet." ,
111
112
},
113
+ "security_groups" : {
114
+ Type : schema .TypeSet ,
115
+ Optional : true ,
116
+ ForceNew : true ,
117
+ Elem : & schema.Schema {Type : schema .TypeString },
118
+ Set : func (v interface {}) int {
119
+ return hashcode .String (v .(string ))
120
+ },
121
+ Description : "ID of security group. If both vpc_id and subnet_id are not set, this argument should not be set either." ,
122
+ },
112
123
"storage" : {
113
124
Type : schema .TypeInt ,
114
125
Required : true ,
@@ -210,6 +221,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
210
221
projectId = d .Get ("project_id" ).(int )
211
222
subnetId = d .Get ("subnet_id" ).(string )
212
223
vpcId = d .Get ("vpc_id" ).(string )
224
+ securityGroups = d .Get ("security_groups" ).(* schema.Set ).List ()
213
225
zone = d .Get ("availability_zone" ).(string )
214
226
storage = d .Get ("storage" ).(int )
215
227
memory = d .Get ("memory" ).(int )
@@ -225,6 +237,12 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
225
237
var outErr , inErr error
226
238
var allowVersion , allowMemory []string
227
239
240
+ requestSecurityGroup := make ([]string , 0 , len (securityGroups ))
241
+
242
+ for _ , v := range securityGroups {
243
+ requestSecurityGroup = append (requestSecurityGroup , v .(string ))
244
+ }
245
+
228
246
// get speccode with engine_version and memory
229
247
outErr = resource .Retry (readRetryTimeout , func () * resource.RetryError {
230
248
speccodes , inErr := postgresqlService .DescribeSpecinfos (ctx , zone )
@@ -262,7 +280,21 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
262
280
}
263
281
264
282
outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
265
- instanceId , inErr = postgresqlService .CreatePostgresqlInstance (ctx , name , dbVersion , payType , specCode , 0 , projectId , period , subnetId , vpcId , zone , storage , username , password , charset )
283
+ instanceId , inErr = postgresqlService .CreatePostgresqlInstance (ctx ,
284
+ name ,
285
+ dbVersion ,
286
+ payType , specCode ,
287
+ 0 ,
288
+ projectId ,
289
+ period ,
290
+ subnetId ,
291
+ vpcId ,
292
+ zone ,
293
+ requestSecurityGroup ,
294
+ storage ,
295
+ username ,
296
+ password ,
297
+ charset )
266
298
if inErr != nil {
267
299
return retryError (inErr )
268
300
}
0 commit comments