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_cluster: support for enable_node_public_ip in agent_pool_profile #4613

Merged
merged 2 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions azurerm/data_source_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ func dataSourceArmKubernetesCluster() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"enable_node_public_ip": {
Type: schema.TypeBool,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -719,6 +724,10 @@ func flattenKubernetesClusterDataSourceAgentPoolProfiles(input *[]containerservi
agentPoolProfile["node_taints"] = *profile.NodeTaints
}

if profile.EnableNodePublicIP != nil {
agentPoolProfile["enable_node_public_ip"] = *profile.EnableNodePublicIP
}

agentPoolProfiles = append(agentPoolProfiles, agentPoolProfile)
}

Expand Down
36 changes: 36 additions & 0 deletions azurerm/data_source_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,30 @@ func TestAccDataSourceAzureRMKubernetesCluster_nodeTaints(t *testing.T) {
})
}

func TestAccDataSourceAzureRMKubernetesCluster_enableNodePublicIP(t *testing.T) {
dataSourceName := "data.azurerm_kubernetes_cluster.test"
ri := tf.AccRandTimeInt()
clientId := os.Getenv("ARM_CLIENT_ID")
clientSecret := os.Getenv("ARM_CLIENT_SECRET")

config := testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIP(ri, clientId, clientSecret, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKubernetesClusterDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(dataSourceName),
resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.enable_node_public_ip", "true"),
),
},
},
})
}

func testAccDataSourceAzureRMKubernetesCluster_basic(rInt int, clientId string, clientSecret string, location string) string {
r := testAccAzureRMKubernetesCluster_basic(rInt, clientId, clientSecret, location)
return fmt.Sprintf(`
Expand Down Expand Up @@ -776,3 +800,15 @@ data "azurerm_kubernetes_cluster" "test" {
}
`, r)
}

func testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIP(rInt int, clientId string, clientSecret string, location string) string {
r := testAccAzureRMKubernetesCluster_enableNodePublicIP(rInt, clientId, clientSecret, location)
return fmt.Sprintf(`
%s

data "azurerm_kubernetes_cluster" "test" {
name = "${azurerm_kubernetes_cluster.test.name}"
resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}"
}
`, r)
}
41 changes: 28 additions & 13 deletions azurerm/resource_arm_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ func resourceArmKubernetesCluster() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"enable_node_public_ip": {
Type: schema.TypeBool,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -1240,6 +1245,10 @@ func expandKubernetesClusterAgentPoolProfiles(d *schema.ResourceData) ([]contain
profile.NodeTaints = nodeTaints
}

if enableNodePublicIP := config["enable_node_public_ip"]; enableNodePublicIP != nil {
profile.EnableNodePublicIP = utils.Bool(enableNodePublicIP.(bool))
}

profiles = append(profiles, profile)
}

Expand Down Expand Up @@ -1300,20 +1309,26 @@ func flattenKubernetesClusterAgentPoolProfiles(profiles *[]containerservice.Mana
subnetId = *profile.VnetSubnetID
}

enableNodePublicIP := false
if profile.EnableNodePublicIP != nil {
enableNodePublicIP = *profile.EnableNodePublicIP
}

agentPoolProfile := map[string]interface{}{
"availability_zones": utils.FlattenStringSlice(profile.AvailabilityZones),
"count": count,
"enable_auto_scaling": enableAutoScaling,
"max_count": maxCount,
"max_pods": maxPods,
"min_count": minCount,
"name": name,
"node_taints": utils.FlattenStringSlice(profile.NodeTaints),
"os_disk_size_gb": osDiskSizeGB,
"os_type": string(profile.OsType),
"type": string(profile.Type),
"vm_size": string(profile.VMSize),
"vnet_subnet_id": subnetId,
"availability_zones": utils.FlattenStringSlice(profile.AvailabilityZones),
"count": count,
"enable_auto_scaling": enableAutoScaling,
"enable_node_public_ip": enableNodePublicIP,
"max_count": maxCount,
"max_pods": maxPods,
"min_count": minCount,
"name": name,
"node_taints": utils.FlattenStringSlice(profile.NodeTaints),
"os_disk_size_gb": osDiskSizeGB,
"os_type": string(profile.OsType),
"type": string(profile.Type),
"vm_size": string(profile.VMSize),
"vnet_subnet_id": subnetId,

// TODO: remove in 2.0
"fqdn": fqdnVal,
Expand Down
52 changes: 52 additions & 0 deletions azurerm/resource_arm_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,29 @@ func testCheckAzureRMKubernetesClusterDestroy(s *terraform.State) error {
return nil
}

func TestAccAzureRMKubernetesCluster_enableNodePublicIP(t *testing.T) {
resourceName := "azurerm_kubernetes_cluster.test"
ri := tf.AccRandTimeInt()
clientId := os.Getenv("ARM_CLIENT_ID")
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
config := testAccAzureRMKubernetesCluster_enableNodePublicIP(ri, clientId, clientSecret, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKubernetesClusterDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "agent_pool_profile.0.enable_node_public_ip", "true"),
),
},
},
})
}

func testAccAzureRMKubernetesCluster_basic(rInt int, clientId string, clientSecret string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down Expand Up @@ -2538,3 +2561,32 @@ resource "azurerm_kubernetes_cluster" "test" {
}
`, rInt, location, rInt, rInt, clientId, clientSecret)
}

func testAccAzureRMKubernetesCluster_enableNodePublicIP(rInt int, clientId string, clientSecret string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%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"

agent_pool_profile {
name = "default"
count = "1"
type = "VirtualMachineScaleSets"
vm_size = "Standard_DS2_v2"
enable_node_public_ip = true
}

service_principal {
client_id = "%s"
client_secret = "%s"
}
}
`, rInt, location, rInt, rInt, clientId, clientSecret)
}