Skip to content

Commit 33090e3

Browse files
authored
feat(k8s): add support for security_group_id in pool resource (#3196)
1 parent 16eb0eb commit 33090e3

File tree

4 files changed

+9093
-793
lines changed

4 files changed

+9093
-793
lines changed

docs/resources/k8s_pool.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ The following arguments are supported:
9696

9797
~> **Important:** Updates to this field will recreate a new resource.
9898

99+
- `security_group_id` - The ID of the security group
100+
101+
~> **Important:** Updates to this field will recreate a new resource.
102+
99103
## Attributes Reference
100104

101105
In addition to all arguments above, the following attributes are exported:

internal/services/k8s/pool.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ func ResourcePool() *schema.Resource {
249249
Computed: true,
250250
Description: "The status of the pool",
251251
},
252+
"security_group_id": {
253+
Type: schema.TypeString,
254+
Computed: true,
255+
Optional: true,
256+
ForceNew: true,
257+
Description: "The ID of the security group",
258+
},
252259
},
253260
}
254261
}
@@ -324,6 +331,10 @@ func ResourceK8SPoolCreate(ctx context.Context, d *schema.ResourceData, m any) d
324331
req.RootVolumeSize = &volumeSizeInBytes
325332
}
326333

334+
if securityGroupID, ok := d.GetOk("security_group_id"); ok {
335+
req.SecurityGroupID = types.ExpandStringPtr(locality.ExpandID(securityGroupID.(string)))
336+
}
337+
327338
// check if the cluster is waiting for a pool
328339
cluster, err := k8sAPI.GetCluster(&k8s.GetClusterRequest{
329340
ClusterID: locality.ExpandID(d.Get("cluster_id")),
@@ -422,6 +433,7 @@ func ResourceK8SPoolRead(ctx context.Context, d *schema.ResourceData, m any) dia
422433
_ = d.Set("zone", pool.Zone)
423434
_ = d.Set("upgrade_policy", poolUpgradePolicyFlatten(pool))
424435
_ = d.Set("public_ip_disabled", pool.PublicIPDisabled)
436+
_ = d.Set("security_group_id", pool.SecurityGroupID)
425437

426438
if pool.PlacementGroupID != nil {
427439
_ = d.Set("placement_group_id", zonal.NewID(pool.Zone, *pool.PlacementGroupID).String())

internal/services/k8s/pool_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestAccPool_Basic(t *testing.T) {
5252
testAccCheckK8SPoolServersAreInPrivateNetwork(tt, "scaleway_k8s_cluster.minimal", "scaleway_k8s_pool.default", "scaleway_vpc_private_network.minimal"),
5353
resource.TestCheckResourceAttrSet("scaleway_k8s_pool.default", "nodes.0.private_ips.0.id"),
5454
resource.TestCheckResourceAttrSet("scaleway_k8s_pool.default", "nodes.0.private_ips.0.address"),
55+
resource.TestCheckResourceAttrSet("scaleway_k8s_pool.default", "security_group_id"),
5556
),
5657
},
5758
{
@@ -65,6 +66,7 @@ func TestAccPool_Basic(t *testing.T) {
6566
resource.TestCheckResourceAttr("scaleway_k8s_pool.minimal", "autoscaling", "true"),
6667
resource.TestCheckResourceAttr("scaleway_k8s_pool.minimal", "version", latestK8SVersion),
6768
resource.TestCheckResourceAttrSet("scaleway_k8s_pool.minimal", "id"),
69+
resource.TestCheckResourceAttrSet("scaleway_k8s_pool.minimal", "security_group_id"),
6870
resource.TestCheckResourceAttr("scaleway_k8s_pool.minimal", "tags.0", "terraform-test"),
6971
resource.TestCheckResourceAttr("scaleway_k8s_pool.minimal", "tags.1", "scaleway_k8s_cluster"),
7072
resource.TestCheckResourceAttr("scaleway_k8s_pool.minimal", "tags.2", "minimal"),
@@ -75,6 +77,7 @@ func TestAccPool_Basic(t *testing.T) {
7577
resource.TestCheckResourceAttrSet("scaleway_k8s_pool.default", "nodes.0.private_ips.0.address"),
7678
resource.TestCheckResourceAttrSet("scaleway_k8s_pool.default", "nodes.0.private_ips.1.id"),
7779
resource.TestCheckResourceAttrSet("scaleway_k8s_pool.default", "nodes.0.private_ips.1.address"),
80+
resource.TestCheckResourceAttrSet("scaleway_k8s_pool.default", "security_group_id"),
7881
),
7982
},
8083
{

0 commit comments

Comments
 (0)