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

Support AKS Virtual Nodes #2641

Merged
merged 3 commits into from
Jan 11, 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
54 changes: 54 additions & 0 deletions azurerm/resource_arm_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ func resourceArmKubernetesCluster() *schema.Resource {
},
},
},

"aci_connector_linux": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
"subnet_name": {
Type: schema.TypeString,
Required: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -725,6 +743,22 @@ func expandKubernetesClusterAddonProfiles(d *schema.ResourceData) map[string]*co
}
}

aciConnector := profile["aci_connector_linux"].([]interface{})
if len(aciConnector) > 0 {
value := aciConnector[0].(map[string]interface{})
config := make(map[string]*string)
enabled := value["enabled"].(bool)

if subnetName, ok := value["subnet_name"]; ok {
config["subnetName"] = utils.String(subnetName.(string))
}

addonProfiles["aciConnectorLinux"] = &containerservice.ManagedClusterAddonProfile{
patst marked this conversation as resolved.
Show resolved Hide resolved
Enabled: utils.Bool(enabled),
Config: config,
}
}

return addonProfiles
}

Expand Down Expand Up @@ -771,6 +805,26 @@ func flattenKubernetesClusterAddonProfiles(profile map[string]*containerservice.
}
values["oms_agent"] = agents

aciConnectors := make([]interface{}, 0)
if aciConnector := profile["aciConnectorLinux"]; aciConnector != nil {
enabled := false
if enabledVal := aciConnector.Enabled; enabledVal != nil {
enabled = *enabledVal
}

subnetName := ""
if v := aciConnector.Config["subnetName"]; v != nil {
subnetName = *v
}

output := map[string]interface{}{
"enabled": enabled,
"subnet_name": subnetName,
}
aciConnectors = append(aciConnectors, output)
}
values["aci_connector_linux"] = aciConnectors

return []interface{}{values}
}

Expand Down
106 changes: 106 additions & 0 deletions azurerm/resource_arm_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,32 @@ func TestAccAzureRMKubernetesCluster_internalNetwork(t *testing.T) {
})
}

func TestAccAzureRMKubernetesCluster_addonProfileAciConnectorLinux(t *testing.T) {
resourceName := "azurerm_kubernetes_cluster.test"
ri := acctest.RandInt()
clientId := os.Getenv("ARM_CLIENT_ID")
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
config := testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinux(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, "addon_profile.0.http_application_routing.#", "0"),
resource.TestCheckResourceAttr(resourceName, "addon_profile.0.aci_connector_linux.#", "1"),
resource.TestCheckResourceAttr(resourceName, "addon_profile.0.aci_connector_linux.0.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "addon_profile.0.aci_connector_linux.0.subnet_name", fmt.Sprintf("acctestsubnet-aci%d", ri)),
),
},
},
})
}

func TestAccAzureRMKubernetesCluster_addonProfileOMS(t *testing.T) {
resourceName := "azurerm_kubernetes_cluster.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -742,6 +768,86 @@ resource "azurerm_kubernetes_cluster" "test" {
`, rInt, location, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret)
}

func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinux(rInt int, clientId string, clientSecret string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestvirtnet%d"
address_space = ["172.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

tags {
environment = "Testing"
}
}

resource "azurerm_subnet" "test" {
name = "acctestsubnet%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "172.0.2.0/24"
}

resource "azurerm_subnet" "test-aci" {
name = "acctestsubnet-aci%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "172.0.3.0/24"

delegation {
name = "aciDelegation"
service_delegation {
name = "Microsoft.ContainerInstance/containerGroups"
actions = [ "Microsoft.Network/virtualNetworks/subnets/action" ]
}
}
}
patst marked this conversation as resolved.
Show resolved Hide resolved

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"

linux_profile {
admin_username = "acctestuser%d"

ssh_key {
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld"
}
}

agent_pool_profile {
name = "default"
count = "1"
vm_size = "Standard_DS2_v2"
vnet_subnet_id = "${azurerm_subnet.test.id}"
}

service_principal {
client_id = "%s"
client_secret = "%s"
}

addon_profile {
aci_connector_linux {
enabled = true
subnet_name = "${azurerm_subnet.test-aci.name}"
}
}

network_profile {
network_plugin = "azure"
}
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret)
}

func testAccAzureRMKubernetesCluster_addonProfileOMS(rInt int, clientId string, clientSecret string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ The following arguments are supported:

A `addon_profile` block supports the following:

* `aci_connector_linux` - (Optional) A `aci_connector_linux` block. For more details, please visit [Create and configure an AKS cluster to use virtual nodes](https://docs.microsoft.com/en-us/azure/aks/virtual-nodes-portal).
* `http_application_routing` - (Optional) A `http_application_routing` block.
* `oms_agent` - (Optional) A `oms_agent` block. For more details, please visit [How to onboard Azure Monitor for containers](https://docs.microsoft.com/en-us/azure/monitoring/monitoring-container-insights-onboard).

Expand Down Expand Up @@ -167,6 +168,14 @@ A `oms_agent` block supports the following:

---

A `aci_connector_linux` block supports the following:

* `enabled` - (Required) Is the virtual node addon enabled?

* `subnet_name` - (Required) The subnet name for the virtual nodes to run.

---

A `role_based_access_control` block supports the following:

* `azure_active_directory` - (Optional) An `azure_active_directory` block. Changing this forces a new resource to be created.
Expand Down