@@ -71,8 +71,7 @@ func init() {
7171 })
7272}
7373
74- func TestAccTencentCloudMongodbInstanceResourcePostPaid (t * testing.T ) {
75- t .Parallel ()
74+ func TestAccTencentCloudMongodbInstanceResource_PostPaid (t * testing.T ) {
7675 resource .Test (t , resource.TestCase {
7776 PreCheck : func () { tcacctest .AccPreCheck (t ) },
7877 Providers : tcacctest .AccProviders ,
@@ -96,6 +95,7 @@ func TestAccTencentCloudMongodbInstanceResourcePostPaid(t *testing.T) {
9695 resource .TestCheckResourceAttr ("tencentcloud_mongodb_instance.mongodb" , "tags.test" , "test" ),
9796 resource .TestCheckResourceAttr ("tencentcloud_mongodb_instance.mongodb" , "charge_type" , svcmongodb .MONGODB_CHARGE_TYPE_POSTPAID ),
9897 resource .TestCheckNoResourceAttr ("tencentcloud_mongodb_instance.mongodb" , "prepaid_period" ),
98+ resource .TestCheckResourceAttr ("tencentcloud_mongodb_instance.mongodb" , "security_groups.0" , "sg-if748odn" ),
9999 ),
100100 },
101101 {
@@ -124,12 +124,17 @@ func TestAccTencentCloudMongodbInstanceResourcePostPaid(t *testing.T) {
124124 resource .TestCheckResourceAttr ("tencentcloud_mongodb_instance.mongodb" , "tags.abc" , "abc" ),
125125 ),
126126 },
127+ {
128+ Config : testAccMongodbInstance_updateSecurityGroup ,
129+ Check : resource .ComposeTestCheckFunc (
130+ resource .TestCheckResourceAttr ("tencentcloud_mongodb_instance.mongodb" , "security_groups.0" , "sg-05f7wnhn" ),
131+ ),
132+ },
127133 },
128134 })
129135}
130136
131- func TestAccTencentCloudMongodbInstanceResource_multiZone (t * testing.T ) {
132- t .Parallel ()
137+ func TestAccTencentCloudMongodbInstanceResource_MultiZone (t * testing.T ) {
133138 resource .Test (t , resource.TestCase {
134139 PreCheck : func () { tcacctest .AccPreCheck (t ) },
135140 Providers : tcacctest .AccProviders ,
@@ -148,7 +153,7 @@ func TestAccTencentCloudMongodbInstanceResource_multiZone(t *testing.T) {
148153 })
149154}
150155
151- func TestAccTencentCloudMongodbInstanceResourcePrepaid (t * testing.T ) {
156+ func TestAccTencentCloudMongodbInstanceResource_Prepaid (t * testing.T ) {
152157 // Avoid to set Parallel to make sure EnvVar secure
153158 resource .Test (t , resource.TestCase {
154159 PreCheck : func () { tcacctest .AccPreCheck (t ) },
@@ -239,6 +244,18 @@ func testAccCheckMongodbInstanceExists(n string) resource.TestCheckFunc {
239244}
240245
241246const testAccMongodbInstance = tcacctest .DefaultMongoDBSpec + `
247+ resource "tencentcloud_vpc" "vpc" {
248+ name = "mongodb-instance-vpc"
249+ cidr_block = "10.0.0.0/16"
250+ }
251+
252+ resource "tencentcloud_subnet" "subnet" {
253+ vpc_id = tencentcloud_vpc.vpc.id
254+ name = "mongodb-instance-subnet"
255+ cidr_block = "10.0.0.0/16"
256+ availability_zone = "ap-guangzhou-3"
257+ }
258+
242259resource "tencentcloud_mongodb_instance" "mongodb" {
243260 instance_name = "tf-mongodb-test"
244261 memory = local.memory
@@ -249,8 +266,8 @@ resource "tencentcloud_mongodb_instance" "mongodb" {
249266 available_zone = "ap-guangzhou-3"
250267 project_id = 0
251268 password = "test1234"
252- vpc_id = var.vpc_id
253- subnet_id = var.subnet_id
269+ vpc_id = tencentcloud_vpc.vpc.id
270+ subnet_id = tencentcloud_subnet.subnet.id
254271
255272 tags = {
256273 test = "test"
@@ -259,6 +276,18 @@ resource "tencentcloud_mongodb_instance" "mongodb" {
259276`
260277
261278const testAccMongodbInstance_updateConfig = tcacctest .DefaultMongoDBSpec + `
279+ resource "tencentcloud_vpc" "vpc" {
280+ name = "mongodb-instance-vpc"
281+ cidr_block = "10.0.0.0/16"
282+ }
283+
284+ resource "tencentcloud_subnet" "subnet" {
285+ vpc_id = tencentcloud_vpc.vpc.id
286+ name = "mongodb-instance-subnet"
287+ cidr_block = "10.0.0.0/16"
288+ availability_zone = "ap-guangzhou-3"
289+ }
290+
262291resource "tencentcloud_mongodb_instance" "mongodb" {
263292 instance_name = "tf-mongodb-update"
264293 memory = local.memory * 2
@@ -269,15 +298,27 @@ resource "tencentcloud_mongodb_instance" "mongodb" {
269298 available_zone = "ap-guangzhou-3"
270299 project_id = 0
271300 password = "test1234update"
272- vpc_id = var.vpc_id
273- subnet_id = var.subnet_id
301+ vpc_id = tencentcloud_vpc.vpc.id
302+ subnet_id = tencentcloud_subnet.subnet.id
274303 tags = {
275304 abc = "abc"
276305 }
277306}
278307`
279308
280309const testAccMongodbInstance_updateNode = tcacctest .DefaultMongoDBSpec + `
310+ resource "tencentcloud_vpc" "vpc" {
311+ name = "mongodb-instance-vpc"
312+ cidr_block = "10.0.0.0/16"
313+ }
314+
315+ resource "tencentcloud_subnet" "subnet" {
316+ vpc_id = tencentcloud_vpc.vpc.id
317+ name = "mongodb-instance-subnet"
318+ cidr_block = "10.0.0.0/16"
319+ availability_zone = "ap-guangzhou-3"
320+ }
321+
281322resource "tencentcloud_mongodb_instance" "mongodb" {
282323 instance_name = "tf-mongodb-update"
283324 memory = local.memory * 2
@@ -288,8 +329,49 @@ resource "tencentcloud_mongodb_instance" "mongodb" {
288329 available_zone = "ap-guangzhou-3"
289330 project_id = 0
290331 password = "test1234update"
291- vpc_id = var.vpc_id
292- subnet_id = var.subnet_id
332+ vpc_id = tencentcloud_vpc.vpc.id
333+ subnet_id = tencentcloud_subnet.subnet.id
334+
335+ node_num = 5
336+ add_node_list {
337+ role = "SECONDARY"
338+ zone = "ap-guangzhou-3"
339+ }
340+ add_node_list {
341+ role = "SECONDARY"
342+ zone = "ap-guangzhou-3"
343+ }
344+ tags = {
345+ abc = "abc"
346+ }
347+ }
348+ `
349+
350+ const testAccMongodbInstance_updateSecurityGroup = tcacctest .DefaultMongoDBSpec + `
351+ resource "tencentcloud_vpc" "vpc" {
352+ name = "mongodb-instance-vpc"
353+ cidr_block = "10.0.0.0/16"
354+ }
355+
356+ resource "tencentcloud_subnet" "subnet" {
357+ vpc_id = tencentcloud_vpc.vpc.id
358+ name = "mongodb-instance-subnet"
359+ cidr_block = "10.0.0.0/16"
360+ availability_zone = "ap-guangzhou-3"
361+ }
362+
363+ resource "tencentcloud_mongodb_instance" "mongodb" {
364+ instance_name = "tf-mongodb-update"
365+ memory = local.memory * 2
366+ volume = local.volume * 2
367+ engine_version = local.engine_version
368+ machine_type = local.machine_type
369+ security_groups = ["sg-05f7wnhn"]
370+ available_zone = "ap-guangzhou-3"
371+ project_id = 0
372+ password = "test1234update"
373+ vpc_id = tencentcloud_vpc.vpc.id
374+ subnet_id = tencentcloud_subnet.subnet.id
293375
294376 node_num = 5
295377 add_node_list {
@@ -307,6 +389,18 @@ resource "tencentcloud_mongodb_instance" "mongodb" {
307389`
308390
309391const testAccMongodbInstancePrepaid = tcacctest .DefaultMongoDBSpec + `
392+ resource "tencentcloud_vpc" "vpc" {
393+ name = "mongodb-instance-prepaid-vpc"
394+ cidr_block = "10.0.0.0/16"
395+ }
396+
397+ resource "tencentcloud_subnet" "subnet" {
398+ vpc_id = tencentcloud_vpc.vpc.id
399+ name = "mongodb-instance-prepaid-subnet"
400+ cidr_block = "10.0.0.0/16"
401+ availability_zone = "ap-guangzhou-3"
402+ }
403+
310404resource "tencentcloud_mongodb_instance" "mongodb_prepaid" {
311405 instance_name = "tf-mongodb-test-prepaid"
312406 memory = local.memory
@@ -320,8 +414,8 @@ resource "tencentcloud_mongodb_instance" "mongodb_prepaid" {
320414 charge_type = "PREPAID"
321415 prepaid_period = 1
322416 auto_renew_flag = 1
323- vpc_id = var.vpc_id
324- subnet_id = var.subnet_id
417+ vpc_id = tencentcloud_vpc.vpc.id
418+ subnet_id = tencentcloud_subnet.subnet.id
325419
326420 tags = {
327421 test = "test-prepaid"
@@ -330,6 +424,18 @@ resource "tencentcloud_mongodb_instance" "mongodb_prepaid" {
330424`
331425
332426const testAccMongodbInstancePrepaid_update = tcacctest .DefaultMongoDBSpec + `
427+ resource "tencentcloud_vpc" "vpc" {
428+ name = "mongodb-instance-prepaid-vpc"
429+ cidr_block = "10.0.0.0/16"
430+ }
431+
432+ resource "tencentcloud_subnet" "subnet" {
433+ vpc_id = tencentcloud_vpc.vpc.id
434+ name = "mongodb-instance-prepaid-subnet"
435+ cidr_block = "10.0.0.0/16"
436+ availability_zone = "ap-guangzhou-3"
437+ }
438+
333439resource "tencentcloud_mongodb_instance" "mongodb_prepaid" {
334440 instance_name = "tf-mongodb-test-prepaid-update"
335441 memory = local.memory
@@ -343,8 +449,8 @@ resource "tencentcloud_mongodb_instance" "mongodb_prepaid" {
343449 charge_type = "PREPAID"
344450 prepaid_period = 1
345451 auto_renew_flag = 1
346- vpc_id = var.vpc_id
347- subnet_id = var.subnet_id
452+ vpc_id = tencentcloud_vpc.vpc.id
453+ subnet_id = tencentcloud_subnet.subnet.id
348454
349455 tags = {
350456 prepaid = "prepaid"
@@ -353,6 +459,18 @@ resource "tencentcloud_mongodb_instance" "mongodb_prepaid" {
353459`
354460
355461const testAccMongodbInstance_multiZone = tcacctest .DefaultMongoDBSpec + `
462+ resource "tencentcloud_vpc" "vpc" {
463+ name = "mongodb-multi-zone-vpc"
464+ cidr_block = "10.0.0.0/16"
465+ }
466+
467+ resource "tencentcloud_subnet" "subnet" {
468+ vpc_id = tencentcloud_vpc.vpc.id
469+ name = "mongodb-multi-zone-subnet"
470+ cidr_block = "10.0.0.0/16"
471+ availability_zone = "ap-guangzhou-3"
472+ }
473+
356474resource "tencentcloud_mongodb_instance" "mongodb_mutil_zone" {
357475 instance_name = "mongodb-mutil-zone-test"
358476 memory = local.memory
@@ -362,8 +480,8 @@ resource "tencentcloud_mongodb_instance" "mongodb_mutil_zone" {
362480 available_zone = "ap-guangzhou-3"
363481 project_id = 0
364482 password = "test1234"
365- vpc_id = var.vpc_id
366- subnet_id = var.subnet_id
483+ vpc_id = tencentcloud_vpc.vpc.id
484+ subnet_id = tencentcloud_subnet.subnet.id
367485 node_num = 5
368486 availability_zone_list = ["ap-guangzhou-3", "ap-guangzhou-3", "ap-guangzhou-4", "ap-guangzhou-4", "ap-guangzhou-6"]
369487 hidden_zone = "ap-guangzhou-6"
0 commit comments