Skip to content

Commit

Permalink
PLT-729:Added static placement support to azure cluster.
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Oct 25, 2023
1 parent 7b3d7d5 commit 828de4b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
17 changes: 17 additions & 0 deletions examples/resources/spectrocloud_cluster_azure/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ resource "spectrocloud_cluster_azure" "cluster" {
resource_group = var.azure_resource_group
region = var.azure_region
ssh_key = var.cluster_ssh_public_key

// Static placement config
# static_placement {
# network_resource_group = "test-resource-group"
# virtual_network_name = "test-network-name"
# virtual_network_cidr_block = "10.0.0.9/10"
# control_plane_subnet {
# name="cp_subnet_name"
# cidr_block="10.0.0.9/16"
# security_group_name="cp_subnet_security_name"
# }
# worker_node_subnet {
# name="worker_subnet_name"
# cidr_block="10.0.0.9/16"
# security_group_name="worker_subnet_security_name"
# }
# }
}

machine_pool {
Expand Down
50 changes: 49 additions & 1 deletion spectrocloud/resource_cluster_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,32 @@ func resourceClusterAzure() *schema.Resource {
Required: true,
Description: "SSH key to be used for the cluster nodes.",
},
"static_placement": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network_resource_group": {
Type: schema.TypeString,
Required: true,
Description: "Azure network resource group in which the cluster is to be provisioned..",
},
"virtual_network_name": {
Type: schema.TypeString,
Required: true,
Description: "Azure virtual network in which the cluster is to be provisioned.",
},
"virtual_network_cidr_block": {
Type: schema.TypeString,
Required: true,
Description: "Azure virtual network cidr block in which the cluster is to be provisioned.",
},
"control_plane_subnet": schemas.SubnetSchema(),
"worker_node_subnet": schemas.SubnetSchema(),
},
},
},
},
},
},
Expand Down Expand Up @@ -522,7 +548,8 @@ func toAzureCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spect
},
},
}

// setting static placements
toStaticPlacement(cluster, cloudConfig)
//for _, machinePool := range d.Get("machine_pool").([]interface{}) {
machinePoolConfigs := make([]*models.V1AzureMachinePoolConfigEntity, 0)
for _, machinePool := range d.Get("machine_pool").(*schema.Set).List() {
Expand All @@ -538,6 +565,27 @@ func toAzureCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spect

return cluster, nil
}
func toStaticPlacement(c *models.V1SpectroAzureClusterEntity, cloudConfig map[string]interface{}) {
placement := cloudConfig["static_placement"]
if len(placement.([]interface{})) > 0 {
staticPlacement := placement.([]interface{})[0].(map[string]interface{})
c.Spec.CloudConfig.VnetResourceGroup = staticPlacement["network_resource_group"].(string)
c.Spec.CloudConfig.VnetName = staticPlacement["virtual_network_name"].(string)
c.Spec.CloudConfig.VnetCidrBlock = staticPlacement["virtual_network_cidr_block"].(string)
cpSubnet := staticPlacement["control_plane_subnet"].([]interface{})[0].(map[string]interface{})
c.Spec.CloudConfig.ControlPlaneSubnet = &models.V1Subnet{
CidrBlock: cpSubnet["cidr_block"].(string),
Name: cpSubnet["name"].(string),
SecurityGroupName: cpSubnet["security_group_name"].(string),
}
workerSubnet := staticPlacement["worker_node_subnet"].([]interface{})[0].(map[string]interface{})
c.Spec.CloudConfig.WorkerSubnet = &models.V1Subnet{
CidrBlock: workerSubnet["cidr_block"].(string),
Name: workerSubnet["name"].(string),
SecurityGroupName: workerSubnet["security_group_name"].(string),
}
}
}

func toMachinePoolAzure(machinePool interface{}) (*models.V1AzureMachinePoolConfigEntity, error) {
m := machinePool.(map[string]interface{})
Expand Down
32 changes: 32 additions & 0 deletions spectrocloud/schemas/subnet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package schemas

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func SubnetSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the subnet.",
},
"cidr_block": {
Type: schema.TypeString,
Required: true,
Description: "CidrBlock is the CIDR block to be used when the provider creates a managed virtual network.",
},
"security_group_name": {
Type: schema.TypeString,
Optional: true,
Description: "Network Security Group(NSG) to be attached to subnet.",
},
},
},
}
}

0 comments on commit 828de4b

Please sign in to comment.