Skip to content

Commit 0ae4cb6

Browse files
authored
fix: adjust security_group_ids to TypeSet (#1321)
* adjust security_group_ids to TypeSet * adjust doc * adjust security_group_ids to TypeSet * adjust doc * adjust security_group_ids to TypeSet * adjust doc * adjust security_group_ids to TypeSet * adjust doc * add changelog Co-authored-by: nickyinluo <nickyinluo@tencent.com>
1 parent 91237f3 commit 0ae4cb6

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

.changelog/1321.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/tencentcloud_kubernetes_node_pool: adjust `security_group_ids` type to unordered
3+
```

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
326326
Description: "ID list of keys.",
327327
},
328328
"security_group_ids": {
329-
Type: schema.TypeList,
329+
Type: schema.TypeSet,
330330
Optional: true,
331331
Elem: &schema.Schema{Type: schema.TypeString},
332332
Description: "Security groups to which a CVM instance belongs.",
@@ -748,12 +748,7 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me
748748
}
749749

750750
if v, ok := dMap["security_group_ids"]; ok {
751-
securityGroups := v.([]interface{})
752-
request.SecurityGroupIds = make([]*string, 0, len(securityGroups))
753-
for i := range securityGroups {
754-
securityGroup := securityGroups[i].(string)
755-
request.SecurityGroupIds = append(request.SecurityGroupIds, &securityGroup)
756-
}
751+
request.SecurityGroupIds = helper.InterfacesStringsPoint(v.(*schema.Set).List())
757752
}
758753

759754
request.EnhancedService = &as.EnhancedService{}
@@ -886,12 +881,7 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
886881
}
887882

888883
if v, ok := dMap["security_group_ids"]; ok {
889-
securityGroups := v.([]interface{})
890-
request.SecurityGroupIds = make([]*string, 0, len(securityGroups))
891-
for i := range securityGroups {
892-
securityGroup := securityGroups[i].(string)
893-
request.SecurityGroupIds = append(request.SecurityGroupIds, &securityGroup)
894-
}
884+
request.SecurityGroupIds = helper.InterfacesStringsPoint(v.(*schema.Set).List())
895885
}
896886

897887
chargeType, ok := dMap["instance_charge_type"].(string)

tencentcloud/resource_tc_kubernetes_node_pool_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func TestAccTencentCloudTkeNodePoolResourceBasic(t *testing.T) {
101101
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "node_count", "1"),
102102
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "autoscaling_added_total", "1"),
103103
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "manually_added_total", "0"),
104+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.security_group_ids.#", "1"),
104105
),
105106
},
106107
{
@@ -130,6 +131,7 @@ func TestAccTencentCloudTkeNodePoolResourceBasic(t *testing.T) {
130131
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "default_cooldown", "350"),
131132
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "termination_policies.#", "1"),
132133
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "termination_policies.0", "NEWEST_INSTANCE"),
134+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.security_group_ids.#", "2"),
133135
),
134136
},
135137
},
@@ -241,6 +243,10 @@ data "tencentcloud_vpc_subnets" "vpc" {
241243
data "tencentcloud_security_groups" "sg" {
242244
name = "default"
243245
}
246+
247+
data "tencentcloud_security_groups" "sg_as" {
248+
name = "keep-for-as"
249+
}
244250
`
245251

246252
const testAccTkeNodePoolCluster string = testAccTkeNodePoolClusterBasic + `
@@ -323,7 +329,7 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
323329
instance_type = var.ins_type
324330
system_disk_type = "CLOUD_PREMIUM"
325331
system_disk_size = "100"
326-
security_group_ids = [data.tencentcloud_security_groups.sg.security_groups[0].security_group_id]
332+
security_group_ids = [data.tencentcloud_security_groups.sg.security_groups[0].security_group_id, data.tencentcloud_security_groups.sg_as.security_groups[0].security_group_id]
327333
instance_charge_type = "SPOTPAID"
328334
spot_instance_type = "one-time"
329335
spot_max_price = "1000"

website/docs/r/kubernetes_node_pool.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ The `auto_scaling_config` object supports the following:
196196
* `key_ids` - (Optional, List, ForceNew) ID list of keys.
197197
* `password` - (Optional, String, ForceNew) Password to access.
198198
* `public_ip_assigned` - (Optional, Bool) Specify whether to assign an Internet IP address.
199-
* `security_group_ids` - (Optional, List) Security groups to which a CVM instance belongs.
199+
* `security_group_ids` - (Optional, Set) Security groups to which a CVM instance belongs.
200200
* `spot_instance_type` - (Optional, String) Type of spot instance, only support `one-time` now. Note: it only works when instance_charge_type is set to `SPOTPAID`.
201201
* `spot_max_price` - (Optional, String) Max price of a spot instance, is the format of decimal string, for example "0.50". Note: it only works when instance_charge_type is set to `SPOTPAID`.
202202
* `system_disk_size` - (Optional, Int) Volume of system disk in GB. Default is `50`.

0 commit comments

Comments
 (0)