diff --git a/azurerm/internal/services/containers/client/client.go b/azurerm/internal/services/containers/client/client.go index 2268c0463b92f..2e785d72ee5ce 100644 --- a/azurerm/internal/services/containers/client/client.go +++ b/azurerm/internal/services/containers/client/client.go @@ -3,7 +3,7 @@ package client import ( "github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance" "github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2018-09-01/containerregistry" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-10-01/containerservice" + "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" ) diff --git a/azurerm/internal/services/containers/data_source_kubernetes_cluster.go b/azurerm/internal/services/containers/data_source_kubernetes_cluster.go index f7d4902455875..44f8f0515c996 100644 --- a/azurerm/internal/services/containers/data_source_kubernetes_cluster.go +++ b/azurerm/internal/services/containers/data_source_kubernetes_cluster.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-10-01/containerservice" + "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/kubernetes" @@ -176,6 +176,14 @@ func dataSourceArmKubernetesCluster() *schema.Resource { Computed: true, }, + "node_labels": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "node_taints": { Type: schema.TypeList, Optional: true, @@ -750,6 +758,10 @@ func flattenKubernetesClusterDataSourceAgentPoolProfiles(input *[]containerservi agentPoolProfile["max_pods"] = int(*profile.MaxPods) } + if profile.NodeLabels != nil { + agentPoolProfile["node_labels"] = profile.NodeLabels + } + if profile.NodeTaints != nil { agentPoolProfile["node_taints"] = *profile.NodeTaints } diff --git a/azurerm/internal/services/containers/kubernetes_addons.go b/azurerm/internal/services/containers/kubernetes_addons.go index 7ca7aaf8acfea..c6bc490e5c4b6 100644 --- a/azurerm/internal/services/containers/kubernetes_addons.go +++ b/azurerm/internal/services/containers/kubernetes_addons.go @@ -3,7 +3,7 @@ package containers import ( "strings" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-10-01/containerservice" + "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" diff --git a/azurerm/internal/services/containers/kubernetes_nodepool.go b/azurerm/internal/services/containers/kubernetes_nodepool.go index 43d5ac611ee49..5e4d501148f1a 100644 --- a/azurerm/internal/services/containers/kubernetes_nodepool.go +++ b/azurerm/internal/services/containers/kubernetes_nodepool.go @@ -3,7 +3,7 @@ package containers import ( "fmt" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-10-01/containerservice" + "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" @@ -90,6 +90,14 @@ func SchemaDefaultNodePool() *schema.Schema { ValidateFunc: validation.IntBetween(1, 100), }, + "node_labels": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "node_taints": { Type: schema.TypeList, Optional: true, @@ -135,6 +143,7 @@ func ConvertDefaultNodePoolToAgentPool(input *[]containerservice.ManagedClusterA EnableNodePublicIP: defaultCluster.EnableNodePublicIP, ScaleSetPriority: defaultCluster.ScaleSetPriority, ScaleSetEvictionPolicy: defaultCluster.ScaleSetEvictionPolicy, + NodeLabels: defaultCluster.NodeLabels, NodeTaints: defaultCluster.NodeTaints, }, } @@ -150,6 +159,8 @@ func ExpandDefaultNodePool(d *schema.ResourceData) (*[]containerservice.ManagedC raw := input[0].(map[string]interface{}) enableAutoScaling := raw["enable_auto_scaling"].(bool) + nodeLabelsRaw := raw["node_labels"].(map[string]interface{}) + nodeLabels := utils.ExpandMapStringPtrString(nodeLabelsRaw) nodeTaintsRaw := raw["node_taints"].([]interface{}) nodeTaints := utils.ExpandStringSlice(nodeTaintsRaw) @@ -157,6 +168,7 @@ func ExpandDefaultNodePool(d *schema.ResourceData) (*[]containerservice.ManagedC EnableAutoScaling: utils.Bool(enableAutoScaling), EnableNodePublicIP: utils.Bool(raw["enable_node_public_ip"].(bool)), Name: utils.String(raw["name"].(string)), + NodeLabels: nodeLabels, NodeTaints: nodeTaints, Type: containerservice.AgentPoolType(raw["type"].(string)), VMSize: containerservice.VMSizeTypes(raw["vm_size"].(string)), @@ -286,6 +298,14 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro name = *agentPool.Name } + var nodeLabels map[string]string + if agentPool.NodeLabels != nil { + nodeLabels = make(map[string]string) + for k, v := range agentPool.NodeLabels { + nodeLabels[k] = *v + } + } + var nodeTaints []string if agentPool.NodeTaints != nil { nodeTaints = *agentPool.NodeTaints @@ -311,6 +331,7 @@ func FlattenDefaultNodePool(input *[]containerservice.ManagedClusterAgentPoolPro "min_count": minCount, "name": name, "node_count": count, + "node_labels": nodeLabels, "node_taints": nodeTaints, "os_disk_size_gb": osDiskSizeGB, "type": string(agentPool.Type), diff --git a/azurerm/internal/services/containers/resource_arm_container_service.go b/azurerm/internal/services/containers/resource_arm_container_service.go index 90132090948e9..12a99747ac71b 100644 --- a/azurerm/internal/services/containers/resource_arm_container_service.go +++ b/azurerm/internal/services/containers/resource_arm_container_service.go @@ -7,7 +7,7 @@ import ( "log" "time" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-10-01/containerservice" + "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go index e0ca72a6cd5f5..ff229932ca0b4 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-10-01/containerservice" + "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" @@ -223,6 +223,14 @@ func resourceArmKubernetesCluster() *schema.Resource { ForceNew: true, }, + "node_labels": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "node_taints": { Type: schema.TypeList, Optional: true, @@ -1230,6 +1238,10 @@ func expandKubernetesClusterAgentPoolProfiles(input []interface{}, isNewResource return nil, fmt.Errorf("Can't create an AKS cluster with autoscaling enabled but not setting min_count or max_count") } + if nodeLabels := utils.ExpandMapStringPtrString(config["node_labels"].(map[string]interface{})); len(nodeLabels) > 0 { + profile.NodeLabels = nodeLabels + } + if nodeTaints := utils.ExpandStringSlice(config["node_taints"].([]interface{})); len(*nodeTaints) > 0 { profile.NodeTaints = nodeTaints } @@ -1312,6 +1324,7 @@ func flattenKubernetesClusterAgentPoolProfiles(profiles *[]containerservice.Mana "max_pods": maxPods, "min_count": minCount, "name": name, + "node_labels": utils.FlattenMapStringPtrString(profile.NodeLabels), "node_taints": utils.FlattenStringSlice(profile.NodeTaints), "os_disk_size_gb": osDiskSizeGB, "os_type": string(profile.OsType), diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go index 320d91304ef8e..6f860fe2a6404 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-10-01/containerservice" + "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" @@ -99,6 +99,14 @@ func resourceArmKubernetesClusterNodePool() *schema.Resource { ValidateFunc: validation.IntBetween(1, 100), }, + "node_labels": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "node_taints": { Type: schema.TypeList, Optional: true, @@ -213,6 +221,11 @@ func resourceArmKubernetesClusterNodePoolCreate(d *schema.ResourceData, meta int profile.MaxPods = utils.Int32(maxPods) } + nodeLabelsRaw := d.Get("node_labels").(map[string]interface{}) + if nodeLabels := utils.ExpandMapStringPtrString(nodeLabelsRaw); len(nodeLabels) > 0 { + profile.NodeLabels = nodeLabels + } + nodeTaintsRaw := d.Get("node_taints").([]interface{}) if nodeTaints := utils.ExpandStringSlice(nodeTaintsRaw); len(*nodeTaints) > 0 { profile.NodeTaints = nodeTaints @@ -348,6 +361,12 @@ func resourceArmKubernetesClusterNodePoolUpdate(d *schema.ResourceData, meta int props.Count = utils.Int32(int32(d.Get("node_count").(int))) } + if d.HasChange("node_labels") { + nodeLabelsRaw := d.Get("node_labels").(map[string]interface{}) + nodeLabels := utils.ExpandMapStringPtrString(nodeLabelsRaw) + props.NodeLabels = nodeLabels + } + if d.HasChange("node_taints") { nodeTaintsRaw := d.Get("node_taints").([]interface{}) nodeTaints := utils.ExpandStringSlice(nodeTaintsRaw) @@ -466,6 +485,10 @@ func resourceArmKubernetesClusterNodePoolRead(d *schema.ResourceData, meta inter } d.Set("node_count", count) + if err := d.Set("node_labels", props.NodeLabels); err != nil { + return fmt.Errorf("Error setting `node_labels`: %+v", err) + } + if err := d.Set("node_taints", utils.FlattenStringSlice(props.NodeTaints)); err != nil { return fmt.Errorf("Error setting `node_taints`: %+v", err) } diff --git a/azurerm/utils/common_marshal.go b/azurerm/utils/common_marshal.go index 33bdc24c4fbf2..758c78238aa1e 100644 --- a/azurerm/utils/common_marshal.go +++ b/azurerm/utils/common_marshal.go @@ -12,6 +12,15 @@ func ExpandStringSlice(input []interface{}) *[]string { return &result } +func ExpandMapStringPtrString(input map[string]interface{}) map[string]*string { + result := make(map[string]*string) + for k, v := range input { + s := v.(string) + result[k] = &s + } + return result +} + func FlattenStringSlice(input *[]string) []interface{} { result := make([]interface{}, 0) if input != nil { @@ -21,3 +30,13 @@ func FlattenStringSlice(input *[]string) []interface{} { } return result } + +func FlattenMapStringPtrString(input map[string]*string) map[string]interface{} { + result := make(map[string]interface{}) + if input != nil { + for k, v := range input { + result[k] = *v + } + } + return result +} diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index 917a936e53e03..f66ae65f99811 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -184,6 +184,8 @@ A `agent_pool_profile` block supports the following: * `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created. +* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the agent pool (e.g `{"name": "value"}`). + * `node_taints` - (Optional) A list of Kubernetes taints which should be applied to nodes in the agent pool (e.g `key=value:NoSchedule`) * `os_disk_size_gb` - (Optional) The Agent Operating System disk size in GB. Changing this forces a new resource to be created. @@ -239,6 +241,8 @@ A `default_node_pool` block supports the following: * `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created. +* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the agent pool (e.g `{"name": "value"}`). + * `node_taints` - (Optional) A list of Kubernetes taints which should be applied to nodes in the agent pool (e.g `key=value:NoSchedule`). * `os_disk_size_gb` - (Optional) The size of the OS Disk which should be used for each agent in the Node Pool. Changing this forces a new resource to be created. diff --git a/website/docs/r/kubernetes_cluster_node_pool.html.markdown b/website/docs/r/kubernetes_cluster_node_pool.html.markdown index 235182e11ac5a..246b9f48768ba 100644 --- a/website/docs/r/kubernetes_cluster_node_pool.html.markdown +++ b/website/docs/r/kubernetes_cluster_node_pool.html.markdown @@ -70,6 +70,8 @@ The following arguments are supported: * `max_pods` - (Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created. +* `node_labels` - (Optional) A map of Kubernetes labels which should be applied to nodes in the agent pool (e.g `{"name": "value"}`). + * `node_taints` - (Optional) A list of Kubernetes taints which should be applied to nodes in the agent pool (e.g `key=value:NoSchedule`). * `os_disk_size_gb` - (Optional) The Agent Operating System disk size in GB. Changing this forces a new resource to be created.