Skip to content

Commit 7c861de

Browse files
committed
feat(k8s): support for pod_cidr, service_cidr and service_dns_ip
1 parent e5302f6 commit 7c861de

File tree

6 files changed

+214
-1184
lines changed

6 files changed

+214
-1184
lines changed

docs/resources/k8s_cluster.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,17 @@ you can still set it now. In this case it will not destroy and recreate your clu
303303

304304
- `required_claim` - (Optional) Multiple key=value pairs that describes a required claim in the ID Token
305305

306-
- `default_pool` - (Deprecated) See below.
306+
- `pod_cidr` - (Optional) The subnet used for the Pod CIDR.
307+
308+
~> **Important:** Changes to this field will recreate a new resource.
309+
310+
- `service_cidr` - (Optional) The subnet used for the Service CIDR.
311+
312+
~> **Important:** Changes to this field will recreate a new resource.
313+
314+
- `service_dns_ip` - (Optional) The IP used for the DNS Service. If unset, defaults to Service CIDR's network + 10.
315+
316+
~> **Important:** Changes to this field will recreate a new resource.
307317

308318
- `region` - (Defaults to [provider](../index.md#arguments-reference) `region`) The [region](../guides/regions_and_zones.md#regions) in which the cluster should be created.
309319

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/nats-io/jwt/v2 v2.8.0
3030
github.com/nats-io/nats.go v1.45.0
3131
github.com/robfig/cron/v3 v3.0.1
32-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250721082157-a9b7a7bd9686
32+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250728144921-0b5c3c564bb6
3333
github.com/stretchr/testify v1.11.1
3434
golang.org/x/crypto v0.42.0
3535
gopkg.in/dnaeon/go-vcr.v3 v3.2.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
456456
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
457457
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
458458
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
459-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250721082157-a9b7a7bd9686 h1:rSbtkU5fMMXbv0qwIH5dBq+TvAYnbClahwPP1KtN9bs=
460-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250721082157-a9b7a7bd9686/go.mod h1:fw6BmcfYRs2BEHYW0c3/rR0JgZHvdx6uMYqpeUJx3Bc=
459+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250728144921-0b5c3c564bb6 h1:77MmFGSxomMgJVpOMlmv7pGoAoreELviEHqCZGQwn2w=
460+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250728144921-0b5c3c564bb6/go.mod h1:fw6BmcfYRs2BEHYW0c3/rR0JgZHvdx6uMYqpeUJx3Bc=
461461
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
462462
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
463463
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=

internal/services/k8s/cluster.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"net"
78
"strings"
89
"time"
910

@@ -158,6 +159,30 @@ func ResourceCluster() *schema.Resource {
158159
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
159160
DiffSuppressFunc: dsf.Locality,
160161
},
162+
"pod_cidr": {
163+
Type: schema.TypeString,
164+
Optional: true,
165+
ForceNew: true,
166+
Computed: true,
167+
Description: "The subnet used for the Pod CIDR.",
168+
ValidateFunc: validation.IsCIDR,
169+
},
170+
"service_cidr": {
171+
Type: schema.TypeString,
172+
Optional: true,
173+
ForceNew: true,
174+
Computed: true,
175+
Description: "The subnet used for the Service CIDR.",
176+
ValidateFunc: validation.IsCIDR,
177+
},
178+
"service_dns_ip": {
179+
Type: schema.TypeString,
180+
Optional: true,
181+
ForceNew: true,
182+
Computed: true,
183+
Description: "The IP used for the DNS Service.",
184+
ValidateFunc: validation.IsIPAddress,
185+
},
161186
"region": regional.Schema(),
162187
"organization_id": account.OrganizationIDSchema(),
163188
"project_id": account.ProjectIDSchema(),
@@ -497,6 +522,23 @@ func ResourceK8SClusterCreate(ctx context.Context, d *schema.ResourceData, m any
497522
req.PrivateNetworkID = scw.StringPtr(regional.ExpandID(pnID.(string)).ID)
498523
}
499524

525+
// Networking configuration
526+
527+
if podCIDR, ok := d.GetOk("pod_cidr"); ok {
528+
podCIDRIPNet, _ := types.ExpandIPNet(podCIDR.(string))
529+
req.PodCidr = &podCIDRIPNet
530+
}
531+
532+
if serviceCIDR, ok := d.GetOk("service_cidr"); ok {
533+
serviceCIDRIPNet, _ := types.ExpandIPNet(serviceCIDR.(string))
534+
req.ServiceCidr = &serviceCIDRIPNet
535+
}
536+
537+
if serviceDNSIP, ok := d.GetOk("service_dns_ip"); ok {
538+
serviceDNSIPNetIP := net.ParseIP(serviceDNSIP.(string))
539+
req.ServiceDNSIP = &serviceDNSIPNetIP
540+
}
541+
500542
// Cluster creation
501543

502544
res, err := k8sAPI.CreateCluster(req, scw.WithContext(ctx))
@@ -578,6 +620,11 @@ func ResourceK8SClusterRead(ctx context.Context, d *schema.ResourceData, m any)
578620
// private_network
579621
_ = d.Set("private_network_id", types.FlattenStringPtr(cluster.PrivateNetworkID))
580622

623+
// networking
624+
_ = d.Set("pod_cidr", cluster.PodCidr.String())
625+
_ = d.Set("service_cidr", cluster.ServiceCidr.String())
626+
_ = d.Set("service_dns_ip", cluster.ServiceDNSIP.String())
627+
581628
////
582629
// Read kubeconfig
583630
////

internal/services/k8s/cluster_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ resource "scaleway_k8s_cluster" "minimal" {
136136
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "tags.1", "scaleway_k8s_cluster"),
137137
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "tags.2", "minimal"),
138138
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "description", "terraform basic test cluster"),
139+
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "pod_cidr", ""),
140+
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "service_cidr", ""),
141+
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "service_dns_ip", ""),
139142
),
140143
},
141144
{
@@ -166,6 +169,9 @@ resource "scaleway_k8s_cluster" "minimal" {
166169
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "tags.1", "scaleway_k8s_cluster"),
167170
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "tags.2", "minimal"),
168171
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "description", ""),
172+
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "pod_cidr", ""),
173+
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "service_cidr", ""),
174+
resource.TestCheckResourceAttr("scaleway_k8s_cluster.minimal", "service_dns_ip", ""),
169175
),
170176
},
171177
},

0 commit comments

Comments
 (0)