|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
| 7 | + "net" |
7 | 8 | "strings" |
8 | 9 | "time" |
9 | 10 |
|
@@ -158,6 +159,30 @@ func ResourceCluster() *schema.Resource { |
158 | 159 | ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(), |
159 | 160 | DiffSuppressFunc: dsf.Locality, |
160 | 161 | }, |
| 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 | + }, |
161 | 186 | "region": regional.Schema(), |
162 | 187 | "organization_id": account.OrganizationIDSchema(), |
163 | 188 | "project_id": account.ProjectIDSchema(), |
@@ -497,6 +522,23 @@ func ResourceK8SClusterCreate(ctx context.Context, d *schema.ResourceData, m any |
497 | 522 | req.PrivateNetworkID = scw.StringPtr(regional.ExpandID(pnID.(string)).ID) |
498 | 523 | } |
499 | 524 |
|
| 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 | + |
500 | 542 | // Cluster creation |
501 | 543 |
|
502 | 544 | res, err := k8sAPI.CreateCluster(req, scw.WithContext(ctx)) |
@@ -578,6 +620,11 @@ func ResourceK8SClusterRead(ctx context.Context, d *schema.ResourceData, m any) |
578 | 620 | // private_network |
579 | 621 | _ = d.Set("private_network_id", types.FlattenStringPtr(cluster.PrivateNetworkID)) |
580 | 622 |
|
| 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 | + |
581 | 628 | //// |
582 | 629 | // Read kubeconfig |
583 | 630 | //// |
|
0 commit comments