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

azurerm_kubernetes_clusterazurerm_kubernetes_cluster_node_pool - support for the node_public_ip_tags property #19731

Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,21 @@ func TestAccKubernetesCluster_kubeProxy(t *testing.T) {
})
}

func TestAccKubernetesCluster_clusterPoolNodePublicIPTags(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.clusterPoolNodePublicIPTags(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (KubernetesClusterResource) apiServerInBYOSubnet(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -3412,69 +3427,103 @@ resource "azurerm_kubernetes_cluster" "test" {

func (KubernetesClusterResource) kubeProxy(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_D2s_v3"
}
identity {
type = "SystemAssigned"
}

network_profile {
network_plugin = "none"
kube_proxy {
mode = "IPVS"
ipvs {
scheduler = "LeastConnection"
tcp_fin_timeout_in_seconds = 1000
tcp_timeout_in_seconds = 1000
udp_timeout_in_seconds = 1000
}
}
}
}
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_D2s_v3"
}
identity {
type = "SystemAssigned"
}

network_profile {
network_plugin = "none"
kube_proxy {
mode = "IPVS"
ipvs {
scheduler = "LeastConnection"
tcp_fin_timeout_in_seconds = 1000
tcp_timeout_in_seconds = 1000
udp_timeout_in_seconds = 1000
}
}
}
}
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) kubeProxyDisabled(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_D2s_v3"
}
identity {
type = "SystemAssigned"
}

network_profile {
network_plugin = "none"
}
}
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_D2s_v3"
}
identity {
type = "SystemAssigned"
}

network_profile {
network_plugin = "none"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

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

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%[2]d"
location = "%[1]s"
}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%[2]d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
enable_node_public_ip = true
node_network_profile {
node_public_ip_tags = {
RoutingPreference = "Internet"
stephybun marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
identity {
type = "SystemAssigned"
}
}
`, data.Locations.Primary, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource {
ValidateFunc: validation.IntBetween(0, 1000),
},

"node_network_profile": schemaNodePoolNetworkProfile(),

"node_labels": {
Type: pluginsdk.TypeMap,
Optional: true,
Expand Down Expand Up @@ -575,6 +577,10 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int
profile.LinuxOSConfig = linuxOSConfig
}

if networkProfile := d.Get("node_network_profile").([]interface{}); len(networkProfile) > 0 {
profile.NetworkProfile = expandAgentPoolNetworkProfile(networkProfile)
}

parameters := agentpools.AgentPool{
Name: utils.String(id.AgentPoolName),
Properties: &profile,
Expand Down Expand Up @@ -710,6 +716,10 @@ func resourceKubernetesClusterNodePoolUpdate(d *pluginsdk.ResourceData, meta int
props.NodeLabels = expandNodeLabels(d.Get("node_labels").(map[string]interface{}))
}

if d.HasChange("node_network_profile") {
props.NetworkProfile = expandAgentPoolNetworkProfile(d.Get("node_network_profile").([]interface{}))
}
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

// validate the auto-scale fields are both set/unset to prevent a continual diff
maxCount := 0
if props.MaxCount != nil {
Expand Down Expand Up @@ -933,9 +943,14 @@ func resourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta inter
if err := d.Set("upgrade_settings", flattenAgentPoolUpgradeSettings(props.UpgradeSettings)); err != nil {
return fmt.Errorf("setting `upgrade_settings`: %+v", err)
}

if err := d.Set("windows_profile", flattenAgentPoolWindowsProfile(props.WindowsProfile)); err != nil {
return fmt.Errorf("setting `windows_profile`: %+v", err)
}

if err := d.Set("node_network_profile", flattenAgentPoolNetworkProfile(props.NetworkProfile)); err != nil {
return fmt.Errorf("setting `node_network_profile`: %+v", err)
}
}

return tags.FlattenAndSet(d, resp.Model.Properties.Tags)
Expand Down Expand Up @@ -1424,3 +1439,56 @@ func flattenAgentPoolWindowsProfile(input *agentpools.AgentPoolWindowsProfile) [
},
}
}

func expandAgentPoolNetworkProfile(input []interface{}) *agentpools.AgentPoolNetworkProfile {
if len(input) == 0 || input[0] == nil {
return nil
}
v := input[0].(map[string]interface{})
return &agentpools.AgentPoolNetworkProfile{
NodePublicIPTags: expandAgentPoolNetworkProfileNodePublicIPTags(v["node_public_ip_tags"].(map[string]interface{})),
}
}

func expandAgentPoolNetworkProfileNodePublicIPTags(input map[string]interface{}) *[]agentpools.IPTag {
if len(input) == 0 {
return nil
}
out := make([]agentpools.IPTag, 0)

for key, val := range input {
ipTag := agentpools.IPTag{
IPTagType: utils.String(key),
Tag: utils.String(val.(string)),
}
out = append(out, ipTag)
}
return &out
}

func flattenAgentPoolNetworkProfile(input *agentpools.AgentPoolNetworkProfile) []interface{} {
if input == nil || input.NodePublicIPTags == nil || len(*input.NodePublicIPTags) != 0 {
return []interface{}{}
}

return []interface{}{
map[string]interface{}{
"node_public_ip_tags": flattenAgentPoolNetworkProfileNodePublicIPTags(input.NodePublicIPTags),
},
}
}

func flattenAgentPoolNetworkProfileNodePublicIPTags(input *[]agentpools.IPTag) map[string]interface{} {
if input == nil {
return map[string]interface{}{}
}
out := make(map[string]interface{})

for _, tag := range *input {
if tag.IPTagType != nil {
out[*tag.IPTagType] = tag.Tag
}
}

return out
}
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,21 @@ func TestAccKubernetesClusterNodePool_windowsProfileOutboundNatEnabled(t *testin
})
}

func TestAccKubernetesClusterNodePool_nodeIPTags(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test")
r := KubernetesClusterNodePoolResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.nodeIPTags(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t KubernetesClusterNodePoolResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := agentpools.ParseAgentPoolID(state.ID)
if err != nil {
Expand Down Expand Up @@ -2442,3 +2457,43 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" {
}
`, data.Locations.Primary, data.RandomInteger)
}

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

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%[2]d"
location = "%[1]s"
}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%[2]d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2s_v3"
}
identity {
type = "SystemAssigned"
}
}

resource "azurerm_kubernetes_cluster_node_pool" "test" {
name = "internal"
kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id
vm_size = "Standard_D2s_v3"
enable_node_public_ip = true
node_network_profile {
node_public_ip_tags = {
RoutingPreference = "Internet"
stephybun marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
`, data.Locations.Primary, data.RandomInteger)
}
Loading