Skip to content

Commit b6a9ef7

Browse files
committed
PLT-1780: Added support for Private api server lb support for azure i… (#621)
* PLT-1780: Added support for Private api server lb support for azure iaas cluster * Added documentation * updated example * fix unit test fix * updated sdk Signed-off-by: Sivaanand Murugesan <[email protected]> * fix with re --------- Signed-off-by: Sivaanand Murugesan <[email protected]>
1 parent 5328c3e commit b6a9ef7

File tree

7 files changed

+143
-3
lines changed

7 files changed

+143
-3
lines changed

docs/resources/cluster_azure.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ resource "spectrocloud_cluster_azure" "cluster" {
3232
resource_group = var.azure_resource_group
3333
region = var.azure_region
3434
ssh_key = var.cluster_ssh_public_key
35+
36+
//Static placement config
37+
# network_resource_group = "test-resource-group"
38+
# virtual_network_name = "test-network-name"
39+
# virtual_network_cidr_block = "10.0.0.9/10"
40+
# control_plane_subnet {
41+
# name="cp_subnet_name"
42+
# cidr_block="10.0.0.9/16"
43+
# security_group_name="cp_subnet_security_name"
44+
# }
45+
# worker_node_subnet {
46+
# name="worker_subnet_name"
47+
# cidr_block="10.0.0.9/16"
48+
# security_group_name="worker_subnet_security_name"
49+
# }
50+
# private_api_server {
51+
# resource_group = "test-resource-group"
52+
# private_dns_zone = "test-private-dns-zone"
53+
# static_ip = "10.11.12.51"
54+
# }
3555
}
3656
3757
cluster_profile {
@@ -157,6 +177,7 @@ Optional:
157177
- `container_name` (String) Container name within your azure storage account.
158178
- `control_plane_subnet` (Block List, Max: 1) (see [below for nested schema](#nestedblock--cloud_config--control_plane_subnet))
159179
- `network_resource_group` (String) Azure network resource group in which the cluster is to be provisioned.
180+
- `private_api_server` (Block List, Max: 1) Custom private DNS zone for your cluster's API server. For more details, refer to the https://docs.spectrocloud.com/clusters/public-cloud/azure/create-azure-cluster/#private-api-server-lb-settings (see [below for nested schema](#nestedblock--cloud_config--private_api_server))
160181
- `storage_account_name` (String) Azure storage account name.
161182
- `virtual_network_cidr_block` (String) Azure virtual network cidr block in which the cluster is to be provisioned.
162183
- `virtual_network_name` (String) Azure virtual network in which the cluster is to be provisioned.
@@ -175,6 +196,19 @@ Optional:
175196
- `security_group_name` (String) Network Security Group(NSG) to be attached to subnet.
176197

177198

199+
<a id="nestedblock--cloud_config--private_api_server"></a>
200+
### Nested Schema for `cloud_config.private_api_server`
201+
202+
Required:
203+
204+
- `resource_group` (String) The resource group of the private DNS zone.
205+
206+
Optional:
207+
208+
- `private_dns_zone` (String) The private DNS zone for the cluster. This is optional. If not provided, a new private DNS zone will be created.
209+
- `static_ip` (String) Static IP address for the private API server load balancer. This is optional. If not provided, Dynamic IP allocation will be used.
210+
211+
178212
<a id="nestedblock--cloud_config--worker_node_subnet"></a>
179213
### Nested Schema for `cloud_config.worker_node_subnet`
180214

examples/resources/spectrocloud_cluster_azure/resource.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ resource "spectrocloud_cluster_azure" "cluster" {
3333
# cidr_block="10.0.0.9/16"
3434
# security_group_name="worker_subnet_security_name"
3535
# }
36+
# private_api_server {
37+
# resource_group = "test-resource-group"
38+
# private_dns_zone = "test-private-dns-zone"
39+
# static_ip = "10.11.12.51"
40+
# }
3641

3742
}
3843

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/hashicorp/terraform-plugin-docs v0.16.0
1212
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
1313
github.com/robfig/cron v1.2.0
14-
github.com/spectrocloud/palette-sdk-go v0.0.0-20250509161739-f7416a832d78
14+
github.com/spectrocloud/palette-sdk-go v0.0.0-20250521182614-2b9b65c1d0e4
1515
github.com/stretchr/testify v1.10.0
1616
gotest.tools v2.2.0+incompatible
1717
k8s.io/api v0.23.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
597597
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
598598
github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
599599
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
600-
github.com/spectrocloud/palette-sdk-go v0.0.0-20250509161739-f7416a832d78 h1:QGVhNlDPNZcEffk7cPLEK+LU2P7f1ScCCFq0g3FO+V4=
601-
github.com/spectrocloud/palette-sdk-go v0.0.0-20250509161739-f7416a832d78/go.mod h1:3/NvYC0TKTbjvnyfaNj+A5r3nVhwDJ26B3PF86RZ/cc=
600+
github.com/spectrocloud/palette-sdk-go v0.0.0-20250521182614-2b9b65c1d0e4 h1:MU8Rdye5fwDgfwP9qy+N3JatknTxyJOL61wfSr+R5OU=
601+
github.com/spectrocloud/palette-sdk-go v0.0.0-20250521182614-2b9b65c1d0e4/go.mod h1:3/NvYC0TKTbjvnyfaNj+A5r3nVhwDJ26B3PF86RZ/cc=
602602
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
603603
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
604604
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=

spectrocloud/resource_cluster_azure.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,32 @@ func resourceClusterAzure() *schema.Resource {
193193
},
194194
"control_plane_subnet": schemas.SubnetSchema(),
195195
"worker_node_subnet": schemas.SubnetSchema(),
196+
"private_api_server": {
197+
Type: schema.TypeList,
198+
Optional: true,
199+
MaxItems: 1,
200+
RequiredWith: []string{"cloud_config.0.network_resource_group", "cloud_config.0.virtual_network_name", "cloud_config.0.virtual_network_cidr_block"},
201+
Description: "Custom private DNS zone for your cluster's API server. For more details, refer to the https://docs.spectrocloud.com/clusters/public-cloud/azure/create-azure-cluster/#private-api-server-lb-settings",
202+
Elem: &schema.Resource{
203+
Schema: map[string]*schema.Schema{
204+
"resource_group": {
205+
Type: schema.TypeString,
206+
Required: true,
207+
Description: "The resource group of the private DNS zone.",
208+
},
209+
"private_dns_zone": {
210+
Type: schema.TypeString,
211+
Optional: true,
212+
Description: "The private DNS zone for the cluster. This is optional. If not provided, a new private DNS zone will be created.",
213+
},
214+
"static_ip": {
215+
Type: schema.TypeString,
216+
Optional: true,
217+
Description: "Static IP address for the private API server load balancer. This is optional. If not provided, Dynamic IP allocation will be used.",
218+
},
219+
},
220+
},
221+
},
196222
},
197223
},
198224
},
@@ -452,6 +478,15 @@ func flattenClusterConfigsAzure(config *models.V1AzureCloudConfig) []interface{}
452478
}
453479
m["worker_node_subnet"] = []interface{}{workerSubnet}
454480
}
481+
if config.Spec.ClusterConfig.InfraLBConfig != nil {
482+
if config.Spec.ClusterConfig.InfraLBConfig.APIServerLB != nil {
483+
m["private_api_server"] = []interface{}{map[string]interface{}{
484+
"resource_group": config.Spec.ClusterConfig.InfraLBConfig.APIServerLB.PrivateDNSZoneResourceGroup,
485+
"private_dns_zone": config.Spec.ClusterConfig.InfraLBConfig.APIServerLB.PrivateDNSName,
486+
"static_ip": config.Spec.ClusterConfig.InfraLBConfig.APIServerLB.APIServerLBStaticIP,
487+
}}
488+
}
489+
}
455490
}
456491

457492
return []interface{}{m}
@@ -683,7 +718,44 @@ func toStaticPlacement(c *models.V1SpectroAzureClusterEntity, cloudConfig map[st
683718
Name: workerSubnet["name"].(string),
684719
SecurityGroupName: workerSubnet["security_group_name"].(string),
685720
}
721+
722+
if v, ok := cloudConfig["private_api_server"]; ok {
723+
privateApiServer := v.([]interface{})
724+
if len(privateApiServer) > 0 {
725+
privateApiServerConfig := privateApiServer[0].(map[string]interface{})
726+
apiServerLB := &models.V1LoadBalancerSpec{
727+
PrivateDNSZoneResourceGroup: privateApiServerConfig["resource_group"].(string),
728+
PrivateDNSName: privateApiServerConfig["private_dns_zone"].(string),
729+
APIServerLBStaticIP: privateApiServerConfig["static_ip"].(string),
730+
IPAllocationMethod: chooseIPMethod(privateApiServerConfig["static_ip"].(string)),
731+
Type: StringPtr("Internal"),
732+
}
733+
c.Spec.CloudConfig.InfraLBConfig = &models.V1InfraLBConfig{
734+
APIServerLB: apiServerLB,
735+
}
736+
}
737+
} else {
738+
apiServerLB := &models.V1LoadBalancerSpec{
739+
IPAllocationMethod: chooseIPMethod(""),
740+
Type: StringPtr("Public"),
741+
PrivateDNSZoneResourceGroup: "",
742+
PrivateDNSName: "",
743+
APIServerLBStaticIP: "",
744+
}
745+
c.Spec.CloudConfig.InfraLBConfig = &models.V1InfraLBConfig{
746+
APIServerLB: apiServerLB,
747+
}
748+
749+
}
750+
751+
}
752+
}
753+
754+
func chooseIPMethod(ip string) *string {
755+
if ip == "" {
756+
return StringPtr("Dynamic")
686757
}
758+
return StringPtr("Static")
687759
}
688760

689761
func toMachinePoolAzure(machinePool interface{}) (*models.V1AzureMachinePoolConfigEntity, error) {

spectrocloud/resource_cluster_azure_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ func TestToStaticPlacement(t *testing.T) {
123123
Name: "worker_subnet",
124124
SecurityGroupName: "worker_sg",
125125
},
126+
InfraLBConfig: &models.V1InfraLBConfig{
127+
APIServerLB: &models.V1LoadBalancerSpec{
128+
IPAllocationMethod: types.Ptr("Dynamic"),
129+
PrivateDNSName: "",
130+
PrivateDNSZoneResourceGroup: "",
131+
APIServerLBStaticIP: "",
132+
Type: types.Ptr("Public"),
133+
},
134+
},
126135
},
127136
},
128137
}

templates/resources/cluster_azure.md.tmpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ resource "spectrocloud_cluster_azure" "cluster" {
3232
resource_group = var.azure_resource_group
3333
region = var.azure_region
3434
ssh_key = var.cluster_ssh_public_key
35+
36+
//Static placement config
37+
# network_resource_group = "test-resource-group"
38+
# virtual_network_name = "test-network-name"
39+
# virtual_network_cidr_block = "10.0.0.9/10"
40+
# control_plane_subnet {
41+
# name="cp_subnet_name"
42+
# cidr_block="10.0.0.9/16"
43+
# security_group_name="cp_subnet_security_name"
44+
# }
45+
# worker_node_subnet {
46+
# name="worker_subnet_name"
47+
# cidr_block="10.0.0.9/16"
48+
# security_group_name="worker_subnet_security_name"
49+
# }
50+
# private_api_server {
51+
# resource_group = "test-resource-group"
52+
# private_dns_zone = "test-private-dns-zone"
53+
# static_ip = "10.11.12.51"
54+
# }
3555
}
3656
3757
cluster_profile {

0 commit comments

Comments
 (0)