Skip to content

Commit 041d67f

Browse files
WeiMengXSWeiMengXS
andauthored
feat: support security_groups (#2281)
* feat: support `security_groups` * feat: support `security_groups` * feat: support `security_groups` * feat: support `security_groups` * feat: support `security_groups` * feat: support `security_groups` * feat: support `security_groups` --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent 0711f1c commit 041d67f

11 files changed

+29
-25
lines changed

.changelog/2281.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_mongodb_instance: Support `security_groups` (which `engine_version` is `MONGO_40_WT`)
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_mongodb_sharding_instance: Support `security_groups` (which `engine_version` is `MONGO_40_WT`)
7+
```
8+
9+
```release-note:enhancement
10+
resource/tencentcloud_mongodb_standby_instance: Support `security_groups` (which `engine_version` is `MONGO_40_WT`)
11+
```

tencentcloud/basic_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,16 @@ data "tencentcloud_mongodb_zone_config" "zone_config" {
776776
available_zone = "ap-guangzhou-6"
777777
}
778778
779+
data "tencentcloud_security_group" "foo" {
780+
name = "default"
781+
}
782+
779783
variable "engine_versions" {
780784
default = {
781785
"3.6": "MONGO_36_WT",
782786
"4.0": "MONGO_40_WT",
783787
"4.2": "MONGO_42_WT"
788+
"4.4": "MONGO_44_WT"
784789
}
785790
}
786791
variable "sg_id" {
@@ -801,6 +806,7 @@ locals {
801806
memory = local.spec.0.memory / 1024
802807
volume = local.spec.0.min_storage / 1024
803808
engine_version = lookup(var.engine_versions, local.spec.0.engine_version)
809+
security_group_id = data.tencentcloud_security_group.foo.id
804810
}
805811
806812
locals {

tencentcloud/extension_mongodb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func TencentMongodbBasicInfo() map[string]*schema.Schema {
142142
Set: func(v interface{}) int {
143143
return helper.HashString(v.(string))
144144
},
145-
Description: "ID of the security group. NOTE: for instance which `engine_version` is `MONGO_40_WT`, `security_groups` is not supported.",
145+
Description: "ID of the security group.",
146146
},
147147
"password": {
148148
Type: schema.TypeString,

tencentcloud/resource_tc_mongodb_instance.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,6 @@ func resourceTencentCloudMongodbInstanceCreate(d *schema.ResourceData, meta inte
273273
tagService := TagService{client: client}
274274
region := client.Region
275275

276-
// check security group info
277-
if d.Get("engine_version").(string) == MONGODB_ENGINE_VERSION_4_WT {
278-
if _, ok := d.GetOk("security_groups"); ok {
279-
return fmt.Errorf("[CRITAL] for instance which `engine_version` is `MONGO_40_WT`, `security_groups` is not supported")
280-
}
281-
}
282-
283276
chargeType := d.Get("charge_type")
284277
if chargeType == MONGODB_CHARGE_TYPE_POSTPAID {
285278
_, ok := d.GetOk("prepaid_period")

tencentcloud/resource_tc_mongodb_instance_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ resource "tencentcloud_mongodb_instance" "mongodb" {
245245
volume = local.volume
246246
engine_version = local.engine_version
247247
machine_type = local.machine_type
248+
security_groups = [local.security_group_id]
248249
available_zone = "ap-guangzhou-3"
249250
project_id = 0
250251
password = "test1234"
@@ -264,6 +265,7 @@ resource "tencentcloud_mongodb_instance" "mongodb" {
264265
volume = local.volume * 2
265266
engine_version = local.engine_version
266267
machine_type = local.machine_type
268+
security_groups = [local.security_group_id]
267269
available_zone = "ap-guangzhou-3"
268270
project_id = 0
269271
password = "test1234update"
@@ -283,6 +285,7 @@ resource "tencentcloud_mongodb_instance" "mongodb_prepaid" {
283285
volume = local.volume
284286
engine_version = local.engine_version
285287
machine_type = local.machine_type
288+
security_groups = [local.security_group_id]
286289
available_zone = "ap-guangzhou-3"
287290
project_id = 0
288291
password = "test1234"
@@ -305,6 +308,7 @@ resource "tencentcloud_mongodb_instance" "mongodb_prepaid" {
305308
volume = local.volume
306309
engine_version = local.engine_version
307310
machine_type = local.machine_type
311+
security_groups = [local.security_group_id]
308312
available_zone = "ap-guangzhou-3"
309313
project_id = 0
310314
password = "test1234update"

tencentcloud/resource_tc_mongodb_sharding_instance.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,6 @@ func resourceMongodbShardingInstanceCreate(d *schema.ResourceData, meta interfac
270270
tagService := TagService{client: client}
271271
region := client.Region
272272

273-
// check security group info
274-
if d.Get("engine_version").(string) == MONGODB_ENGINE_VERSION_4_WT {
275-
if _, ok := d.GetOk("security_groups"); ok {
276-
return fmt.Errorf("[CRITAL] for instance which `engine_version` is `MONGO_40_WT`, `security_groups` is not supported")
277-
}
278-
}
279-
280273
chargeType := d.Get("charge_type")
281274
if chargeType == MONGODB_CHARGE_TYPE_POSTPAID {
282275
_, ok := d.GetOk("prepaid_period")

tencentcloud/resource_tc_mongodb_sharding_instance_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ resource "tencentcloud_mongodb_sharding_instance" "mongodb" {
138138
volume = local.sharding_volume
139139
engine_version = local.sharding_engine_version
140140
machine_type = local.sharding_machine_type
141+
security_groups = [local.security_group_id]
141142
available_zone = "ap-guangzhou-3"
142143
project_id = 0
143144
password = "test1234"
@@ -164,6 +165,7 @@ resource "tencentcloud_mongodb_sharding_instance" "mongodb" {
164165
volume = local.sharding_volume
165166
engine_version = local.sharding_engine_version
166167
machine_type = local.sharding_machine_type
168+
security_groups = [local.security_group_id]
167169
available_zone = "ap-guangzhou-3"
168170
project_id = 0
169171
password = "test1234update"
@@ -191,6 +193,7 @@ resource "tencentcloud_mongodb_sharding_instance" "mongodb_prepaid" {
191193
volume = local.sharding_volume
192194
engine_version = local.sharding_engine_version
193195
machine_type = local.sharding_machine_type
196+
security_groups = [local.security_group_id]
194197
available_zone = "ap-guangzhou-3"
195198
project_id = 0
196199
password = "test1234"
@@ -220,6 +223,7 @@ resource "tencentcloud_mongodb_sharding_instance" "mongodb_prepaid" {
220223
volume = local.sharding_volume
221224
engine_version = local.sharding_engine_version
222225
machine_type = local.sharding_machine_type
226+
security_groups = [local.security_group_id]
223227
available_zone = "ap-guangzhou-3"
224228
project_id = 0
225229
password = "test1234update"

tencentcloud/resource_tc_mongodb_standby_instance.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,6 @@ func resourceTencentCloudMongodbStandbyInstanceCreate(d *schema.ResourceData, me
290290
return fmt.Errorf("[CRITAL] standBy instance zoneId must not same with father instance's")
291291
}
292292

293-
// check security group info
294-
if *masterInfo.MongoVersion == MONGODB_ENGINE_VERSION_4_WT {
295-
if _, ok := d.GetOk("security_groups"); ok {
296-
return fmt.Errorf("[CRITAL] for instance which `engine_version` is `MONGO_40_WT`, `security_groups` is not supported")
297-
}
298-
}
299-
300293
chargeType := d.Get("charge_type").(string)
301294

302295
if chargeType == MONGODB_CHARGE_TYPE_POSTPAID {

website/docs/r/mongodb_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The following arguments are supported:
5050
* `password` - (Optional, String) Password of this Mongodb account.
5151
* `prepaid_period` - (Optional, Int) The tenancy (time unit is month) of the prepaid instance. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. NOTE: it only works when charge_type is set to `PREPAID`.
5252
* `project_id` - (Optional, Int) ID of the project which the instance belongs.
53-
* `security_groups` - (Optional, Set: [`String`], ForceNew) ID of the security group. NOTE: for instance which `engine_version` is `MONGO_40_WT`, `security_groups` is not supported.
53+
* `security_groups` - (Optional, Set: [`String`], ForceNew) ID of the security group.
5454
* `subnet_id` - (Optional, String, ForceNew) ID of the subnet within this VPC. The value is required if `vpc_id` is set.
5555
* `tags` - (Optional, Map) The tags of the Mongodb. Key name `project` is system reserved and can't be used.
5656
* `vpc_id` - (Optional, String, ForceNew) ID of the VPC.

website/docs/r/mongodb_sharding_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The following arguments are supported:
5959
* `password` - (Optional, String) Password of this Mongodb account.
6060
* `prepaid_period` - (Optional, Int) The tenancy (time unit is month) of the prepaid instance. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. NOTE: it only works when charge_type is set to `PREPAID`.
6161
* `project_id` - (Optional, Int) ID of the project which the instance belongs.
62-
* `security_groups` - (Optional, Set: [`String`], ForceNew) ID of the security group. NOTE: for instance which `engine_version` is `MONGO_40_WT`, `security_groups` is not supported.
62+
* `security_groups` - (Optional, Set: [`String`], ForceNew) ID of the security group.
6363
* `subnet_id` - (Optional, String, ForceNew) ID of the subnet within this VPC. The value is required if `vpc_id` is set.
6464
* `tags` - (Optional, Map) The tags of the Mongodb. Key name `project` is system reserved and can't be used.
6565
* `vpc_id` - (Optional, String, ForceNew) ID of the VPC.

0 commit comments

Comments
 (0)