Skip to content

Commit

Permalink
Update Terraform integration for Azure with new fields (#2081)
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
  • Loading branch information
xmudrii authored Jun 1, 2022
1 parent d7e1d68 commit fcad936
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 42 deletions.
35 changes: 20 additions & 15 deletions examples/terraform/azure/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,32 @@ output "kubeone_workers" {
# provider specific fields:
# see example under `cloudProviderSpec` section at:
# https://github.com/kubermatic/machine-controller/blob/master/examples/azure-machinedeployment.yaml
assignPublicIP = true
availabilitySet = azurerm_availability_set.avset_workers.name
location = var.location
resourceGroup = azurerm_resource_group.rg.name
routeTableName = azurerm_route_table.rt.name
securityGroupName = azurerm_network_security_group.sg.name
subnetName = azurerm_subnet.subnet.name
vmSize = var.worker_vm_size
vnetName = azurerm_virtual_network.vpc.name
# Custom Image ID (optional)
# imageID = ""
# Size of the operating system disk (optional)
# osDiskSize = 100
# Size of the data disk (optional)
# dataDiskSize = 100
location = var.location
resourceGroup = azurerm_resource_group.rg.name
# vnetResourceGroup = ""
vmSize = var.worker_vm_size
vnetName = azurerm_virtual_network.vpc.name
subnetName = azurerm_subnet.subnet.name
# loadBalancerSku = ""
routeTableName = azurerm_route_table.rt.name
availabilitySet = azurerm_availability_set.avset_workers.name
# assignAvailabilitySet = true/false
securityGroupName = azurerm_network_security_group.sg.name
assignPublicIP = true
# Zones (optional)
# Represents Availability Zones is a high-availability offering
# that protects your applications and data from datacenter failures.
# zones = {
# "1"
# }
# Custom Image ID (optional)
# imageID = ""
# Size of the operating system disk (optional)
# osDiskSize = 100
# osDiskSKU = 100
# Size of the data disk (optional)
# dataDiskSize = 100
# dataDiskSKU = 100
tags = {
"${var.cluster_name}-workers" = "pool1"
}
Expand Down
44 changes: 29 additions & 15 deletions pkg/templates/machinecontroller/cloudprovider_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,39 @@ type VSphereSpec struct {

// AzureSpec holds cloudprovider spec for Azure
type AzureSpec struct {
AssignPublicIP bool `json:"assignPublicIP"`
AvailabilitySet string `json:"availabilitySet"`
Location string `json:"location"`
ResourceGroup string `json:"resourceGroup"`
RouteTableName string `json:"routeTableName"`
SecurityGroupName string `json:"securityGroupName"`
Zones []string `json:"zones"`
ImagePlan *AzureImagePlan `json:"imagePlan"`
SubnetName string `json:"subnetName"`
Tags map[string]string `json:"tags"`
VMSize string `json:"vmSize"`
VNetName string `json:"vnetName"`
ImageID string `json:"imageID"`
OSDiskSize int `json:"osDiskSize"`
DataDiskSize int `json:"dataDiskSize"`
Location string `json:"location"`
ResourceGroup string `json:"resourceGroup"`
VNetResourceGroup string `json:"vnetResourceGroup"`
VMSize string `json:"vmSize"`
VNetName string `json:"vnetName"`
SubnetName string `json:"subnetName"`
LoadBalancerSku string `json:"loadBalancerSku"`
RouteTableName string `json:"routeTableName"`
AvailabilitySet string `json:"availabilitySet"`
AssignAvailabilitySet *bool `json:"assignAvailabilitySet,omitempty"`
SecurityGroupName string `json:"securityGroupName"`
Zones []string `json:"zones"`
ImagePlan *AzureImagePlan `json:"imagePlan"`
ImageReference *AzureImageReference `json:"imageReference,omitempty"`

ImageID string `json:"imageID"`
OSDiskSize int `json:"osDiskSize"`
OSDiskSKU *string `json:"osDiskSKU,omitempty"`
DataDiskSize int `json:"dataDiskSize"`
DataDiskSKU *string `json:"dataDiskSKU,omitempty"`
AssignPublicIP bool `json:"assignPublicIP"`
Tags map[string]string `json:"tags"`
}

type AzureImagePlan struct {
Name string `json:"name,omitempty"`
Publisher string `json:"publisher,omitempty"`
Product string `json:"product,omitempty"`
}

type AzureImageReference struct {
Publisher string `json:"publisher,omitempty"`
Offer string `json:"offer,omitempty"`
Sku string `json:"sku,omitempty"`
Version string `json:"version,omitempty"`
}
18 changes: 12 additions & 6 deletions pkg/terraform/v1beta1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,27 @@ func (c *Config) updateAzureWorkerset(existingWorkerSet *kubeonev1beta1.DynamicW
}

flags := []cloudProviderFlags{
{key: "assignPublicIP", value: azureCloudConfig.AssignPublicIP},
{key: "availabilitySet", value: azureCloudConfig.AvailabilitySet},
{key: "location", value: azureCloudConfig.Location},
{key: "resourceGroup", value: azureCloudConfig.ResourceGroup},
{key: "vnetResourceGroup", value: azureCloudConfig.VNetResourceGroup},
{key: "vmSize", value: azureCloudConfig.VMSize},
{key: "vnetName", value: azureCloudConfig.VNetName},
{key: "subnetName", value: azureCloudConfig.SubnetName},
{key: "loadBalancerSku", value: azureCloudConfig.LoadBalancerSku},
{key: "routeTableName", value: azureCloudConfig.RouteTableName},
{key: "availabilitySet", value: azureCloudConfig.AvailabilitySet},
{key: "assignAvailabilitySet", value: azureCloudConfig.AssignAvailabilitySet},
{key: "securityGroupName", value: azureCloudConfig.SecurityGroupName},
{key: "zones", value: azureCloudConfig.Zones},
{key: "imagePlan", value: azureCloudConfig.ImagePlan},
{key: "subnetName", value: azureCloudConfig.SubnetName},
{key: "tags", value: azureCloudConfig.Tags},
{key: "vmSize", value: azureCloudConfig.VMSize},
{key: "vnetName", value: azureCloudConfig.VNetName},
{key: "imageReference", value: azureCloudConfig.ImageReference},
{key: "imageID", value: azureCloudConfig.ImageID},
{key: "osDiskSize", value: azureCloudConfig.OSDiskSize},
{key: "osDiskSKU", value: azureCloudConfig.OSDiskSKU},
{key: "dataDiskSize", value: azureCloudConfig.DataDiskSize},
{key: "dataDiskSKU", value: azureCloudConfig.DataDiskSKU},
{key: "assignPublicIP", value: azureCloudConfig.AssignPublicIP},
{key: "tags", value: azureCloudConfig.Tags},
}

for _, flag := range flags {
Expand Down
18 changes: 12 additions & 6 deletions pkg/terraform/v1beta2/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,27 @@ func updateAzureWorkerset(existingWorkerSet *kubeonev1beta2.DynamicWorkerConfig,
}

flags := []cloudProviderFlags{
{key: "assignPublicIP", value: azureCloudConfig.AssignPublicIP},
{key: "availabilitySet", value: azureCloudConfig.AvailabilitySet},
{key: "location", value: azureCloudConfig.Location},
{key: "resourceGroup", value: azureCloudConfig.ResourceGroup},
{key: "vnetResourceGroup", value: azureCloudConfig.VNetResourceGroup},
{key: "vmSize", value: azureCloudConfig.VMSize},
{key: "vnetName", value: azureCloudConfig.VNetName},
{key: "subnetName", value: azureCloudConfig.SubnetName},
{key: "loadBalancerSku", value: azureCloudConfig.LoadBalancerSku},
{key: "routeTableName", value: azureCloudConfig.RouteTableName},
{key: "availabilitySet", value: azureCloudConfig.AvailabilitySet},
{key: "assignAvailabilitySet", value: azureCloudConfig.AssignAvailabilitySet},
{key: "securityGroupName", value: azureCloudConfig.SecurityGroupName},
{key: "zones", value: azureCloudConfig.Zones},
{key: "imagePlan", value: azureCloudConfig.ImagePlan},
{key: "subnetName", value: azureCloudConfig.SubnetName},
{key: "tags", value: azureCloudConfig.Tags},
{key: "vmSize", value: azureCloudConfig.VMSize},
{key: "vnetName", value: azureCloudConfig.VNetName},
{key: "imageReference", value: azureCloudConfig.ImageReference},
{key: "imageID", value: azureCloudConfig.ImageID},
{key: "osDiskSize", value: azureCloudConfig.OSDiskSize},
{key: "osDiskSKU", value: azureCloudConfig.OSDiskSKU},
{key: "dataDiskSize", value: azureCloudConfig.DataDiskSize},
{key: "dataDiskSKU", value: azureCloudConfig.DataDiskSKU},
{key: "assignPublicIP", value: azureCloudConfig.AssignPublicIP},
{key: "tags", value: azureCloudConfig.Tags},
}

for _, flag := range flags {
Expand Down

0 comments on commit fcad936

Please sign in to comment.