Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proximity_placement_group_id to AKS node pools #9195

Merged
merged 13 commits into from
Nov 12, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ func dataSourceKubernetesClusterNodePool() *schema.Resource {
Computed: true,
},

"proximity_placement_group_id": {
Type: schema.TypeString,
Computed: true,
},

"spot_max_price": {
Type: schema.TypeFloat,
Computed: true,
Expand Down Expand Up @@ -248,6 +253,12 @@ func dataSourceKubernetesClusterNodePoolRead(d *schema.ResourceData, meta interf
}
d.Set("priority", priority)

proximityPlacementGroupId := ""
if props.ProximityPlacementGroupID != nil {
proximityPlacementGroupId = *props.ProximityPlacementGroupID
}
d.Set("proximity_placement_group_id", proximityPlacementGroupId)

spotMaxPrice := -1.0
if props.SpotMaxPrice != nil {
spotMaxPrice = *props.SpotMaxPrice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ func resourceArmKubernetesClusterNodePool() *schema.Resource {
}, false),
},

"proximity_placement_group_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: computeValidate.ProximityPlacementGroupID,
},

"spot_max_price": {
Type: schema.TypeFloat,
Optional: true,
Expand Down Expand Up @@ -326,6 +333,11 @@ func resourceArmKubernetesClusterNodePoolCreate(d *schema.ResourceData, meta int
profile.OsDiskSizeGB = utils.Int32(int32(osDiskSizeGB))
}

proximityPlacementGroupId := d.Get("proximity_placement_group_id").(string)
if proximityPlacementGroupId != "" {
profile.ProximityPlacementGroupID = &proximityPlacementGroupId
}

if vnetSubnetID := d.Get("vnet_subnet_id").(string); vnetSubnetID != "" {
profile.VnetSubnetID = utils.String(vnetSubnetID)
}
Expand Down Expand Up @@ -625,6 +637,8 @@ func resourceArmKubernetesClusterNodePoolRead(d *schema.ResourceData, meta inter
}
d.Set("priority", priority)

d.Set("proximity_placement_group_id", props.ProximityPlacementGroupID)

spotMaxPrice := -1.0
if props.SpotMaxPrice != nil {
spotMaxPrice = *props.SpotMaxPrice
Expand Down
91 changes: 55 additions & 36 deletions azurerm/internal/services/containers/kubernetes_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package containers
import (
"fmt"

computeValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/validate"

"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-09-01/containerservice"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -133,6 +135,12 @@ func SchemaDefaultNodePool() *schema.Schema {
Computed: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"proximity_placement_group_id": {
Type: schema.TypeString,
Optional: true,
favoretti marked this conversation as resolved.
Show resolved Hide resolved
ForceNew: true,
ValidateFunc: computeValidate.ProximityPlacementGroupID,
},
},
},
}
Expand All @@ -143,26 +151,27 @@ func ConvertDefaultNodePoolToAgentPool(input *[]containerservice.ManagedClusterA
return containerservice.AgentPool{
Name: defaultCluster.Name,
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
Count: defaultCluster.Count,
VMSize: defaultCluster.VMSize,
OsDiskSizeGB: defaultCluster.OsDiskSizeGB,
VnetSubnetID: defaultCluster.VnetSubnetID,
MaxPods: defaultCluster.MaxPods,
OsType: defaultCluster.OsType,
MaxCount: defaultCluster.MaxCount,
MinCount: defaultCluster.MinCount,
EnableAutoScaling: defaultCluster.EnableAutoScaling,
Type: defaultCluster.Type,
OrchestratorVersion: defaultCluster.OrchestratorVersion,
AvailabilityZones: defaultCluster.AvailabilityZones,
EnableNodePublicIP: defaultCluster.EnableNodePublicIP,
ScaleSetPriority: defaultCluster.ScaleSetPriority,
ScaleSetEvictionPolicy: defaultCluster.ScaleSetEvictionPolicy,
SpotMaxPrice: defaultCluster.SpotMaxPrice,
Mode: defaultCluster.Mode,
NodeLabels: defaultCluster.NodeLabels,
NodeTaints: defaultCluster.NodeTaints,
Tags: defaultCluster.Tags,
Count: defaultCluster.Count,
VMSize: defaultCluster.VMSize,
OsDiskSizeGB: defaultCluster.OsDiskSizeGB,
VnetSubnetID: defaultCluster.VnetSubnetID,
MaxPods: defaultCluster.MaxPods,
OsType: defaultCluster.OsType,
MaxCount: defaultCluster.MaxCount,
MinCount: defaultCluster.MinCount,
EnableAutoScaling: defaultCluster.EnableAutoScaling,
Type: defaultCluster.Type,
OrchestratorVersion: defaultCluster.OrchestratorVersion,
ProximityPlacementGroupID: defaultCluster.ProximityPlacementGroupID,
AvailabilityZones: defaultCluster.AvailabilityZones,
EnableNodePublicIP: defaultCluster.EnableNodePublicIP,
ScaleSetPriority: defaultCluster.ScaleSetPriority,
ScaleSetEvictionPolicy: defaultCluster.ScaleSetEvictionPolicy,
SpotMaxPrice: defaultCluster.SpotMaxPrice,
Mode: defaultCluster.Mode,
NodeLabels: defaultCluster.NodeLabels,
NodeTaints: defaultCluster.NodeTaints,
Tags: defaultCluster.Tags,
},
}
}
Expand Down Expand Up @@ -231,6 +240,10 @@ func ExpandDefaultNodePool(d *schema.ResourceData) (*[]containerservice.ManagedC
profile.OrchestratorVersion = utils.String(orchestratorVersion)
}

if proximityPlacementGroupId := raw["proximity_placement_group_id"].(string); proximityPlacementGroupId != "" {
profile.ProximityPlacementGroupID = utils.String(proximityPlacementGroupId)
}

count := raw["node_count"].(int)
maxCount := raw["max_count"].(int)
minCount := raw["min_count"].(int)
Expand Down Expand Up @@ -356,24 +369,30 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro
orchestratorVersion = *agentPool.OrchestratorVersion
}

proximityPlacementGroupId := ""
if agentPool.ProximityPlacementGroupID != nil {
proximityPlacementGroupId = *agentPool.ProximityPlacementGroupID
}

return &[]interface{}{
map[string]interface{}{
"availability_zones": availabilityZones,
"enable_auto_scaling": enableAutoScaling,
"enable_node_public_ip": enableNodePublicIP,
"max_count": maxCount,
"max_pods": maxPods,
"min_count": minCount,
"name": name,
"node_count": count,
"node_labels": nodeLabels,
"node_taints": []string{},
"os_disk_size_gb": osDiskSizeGB,
"tags": tags.Flatten(agentPool.Tags),
"type": string(agentPool.Type),
"vm_size": string(agentPool.VMSize),
"orchestrator_version": orchestratorVersion,
"vnet_subnet_id": vnetSubnetId,
"availability_zones": availabilityZones,
"enable_auto_scaling": enableAutoScaling,
"enable_node_public_ip": enableNodePublicIP,
"max_count": maxCount,
"max_pods": maxPods,
"min_count": minCount,
"name": name,
"node_count": count,
"node_labels": nodeLabels,
"node_taints": []string{},
"os_disk_size_gb": osDiskSizeGB,
"tags": tags.Flatten(agentPool.Tags),
"type": string(agentPool.Type),
"vm_size": string(agentPool.VMSize),
"orchestrator_version": orchestratorVersion,
"proximity_placement_group_id": proximityPlacementGroupId,
"vnet_subnet_id": vnetSubnetId,
},
}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var kubernetesNodePoolTests = map[string]func(t *testing.T){
"requiresImport": testAccAzureRMKubernetesClusterNodePool_requiresImport,
"spot": testAccAzureRMKubernetesClusterNodePool_spot,
"osDiskSizeGB": testAccAzureRMKubernetesClusterNodePool_osDiskSizeGB,
"proximityPlacementGroupId": testAccAzureRMKubernetesClusterNodePool_proximityPlacementGroupId,
"modeSystem": testAccAzureRMKubernetesClusterNodePool_modeSystem,
"modeUpdate": testAccAzureRMKubernetesClusterNodePool_modeUpdate,
"virtualNetworkAutomatic": testAccAzureRMKubernetesClusterNodePool_virtualNetworkAutomatic,
Expand Down Expand Up @@ -572,6 +573,30 @@ func testAccAzureRMKubernetesClusterNodePool_osDiskSizeGB(t *testing.T) {
})
}

func TestAccAzureRMKubernetesClusterNodePool_proximityPlacementGroupId(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccAzureRMKubernetesClusterNodePool_proximityPlacementGroupId(t)
}

func testAccAzureRMKubernetesClusterNodePool_proximityPlacementGroupId(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMKubernetesClusterNodePool_proximityPlacementGroupIdConfig(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesNodePoolExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMKubernetesClusterNodePool_requiresImport(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccAzureRMKubernetesClusterNodePool_requiresImport(t)
Expand Down Expand Up @@ -1386,6 +1411,55 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" {
`, template)
}

func testAccAzureRMKubernetesClusterNodePool_proximityPlacementGroupIdConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"

default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}

identity {
type = "SystemAssigned"
}
}

resource "azurerm_proximity_placement_group" "test" {
name = "acctestPPG-aks-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

tags = {
environment = "Production"
}
}

resource "azurerm_kubernetes_cluster_node_pool" "test" {
name = "internal"
kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id
vm_size = "Standard_DS2_v2"
node_count = 1
proximity_placement_group_id = azurerm_proximity_placement_group.test.id
}

`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMKubernetesClusterNodePool_spotConfig(data acceptance.TestData) string {
template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data)
return fmt.Sprintf(`
Expand Down
Loading