@@ -57,6 +57,7 @@ package tencentcloud
5757import (
5858 "context"
5959 "fmt"
60+ "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
6061 "strings"
6162
6263 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -109,6 +110,16 @@ func resourceTencentCloudPostgresqlInstance() *schema.Resource {
109110 Optional : true ,
110111 Description : "ID of subnet." ,
111112 },
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+ },
112123 "storage" : {
113124 Type : schema .TypeInt ,
114125 Required : true ,
@@ -210,6 +221,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
210221 projectId = d .Get ("project_id" ).(int )
211222 subnetId = d .Get ("subnet_id" ).(string )
212223 vpcId = d .Get ("vpc_id" ).(string )
224+ securityGroups = d .Get ("security_groups" ).(* schema.Set ).List ()
213225 zone = d .Get ("availability_zone" ).(string )
214226 storage = d .Get ("storage" ).(int )
215227 memory = d .Get ("memory" ).(int )
@@ -225,6 +237,12 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
225237 var outErr , inErr error
226238 var allowVersion , allowMemory []string
227239
240+ requestSecurityGroup := make ([]string , 0 , len (securityGroups ))
241+
242+ for _ , v := range securityGroups {
243+ requestSecurityGroup = append (requestSecurityGroup , v .(string ))
244+ }
245+
228246 // get speccode with engine_version and memory
229247 outErr = resource .Retry (readRetryTimeout , func () * resource.RetryError {
230248 speccodes , inErr := postgresqlService .DescribeSpecinfos (ctx , zone )
@@ -262,7 +280,21 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
262280 }
263281
264282 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 )
266298 if inErr != nil {
267299 return retryError (inErr )
268300 }
0 commit comments