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 test and sample for AKS with route table. #2286

Closed
wants to merge 3 commits into from
Closed
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
122 changes: 120 additions & 2 deletions azurerm/resource_arm_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,31 @@ func TestAccAzureRMKubernetesCluster_internalNetwork(t *testing.T) {
})
}

func TestAccAzureRMKubernetesCluster_internalNetworkRouteTable(t *testing.T) {
metacpp marked this conversation as resolved.
Show resolved Hide resolved
resourceName := "azurerm_kubernetes_cluster.test"
ri := acctest.RandInt()
clientId := os.Getenv("ARM_CLIENT_ID")
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
config := testAccAzureRMKubernetesCluster_internalNetworkRouteTable(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.max_pods", "60"),
resource.TestCheckResourceAttrSet("azurerm_subnet_route_table_association.test", "route_table_id"),
resource.TestCheckResourceAttrSet("azurerm_subnet_route_table_association.test", "subnet_id"),
),
},
},
})
}

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

func testAccAzureRMKubernetesCluster_internalNetworkRouteTable(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"
route_table_id = "${azurerm_route_table.test.id}"
}

resource "azurerm_route_table" "test" {
name = "akc-routetable-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

route {
name = "akc-route-%d"
address_prefix = "10.100.0.0/14"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "10.10.1.1"
}
}

resource "azurerm_subnet_route_table_association" "test" {
subnet_id = "${azurerm_subnet.test.id}"
route_table_id = "${azurerm_route_table.test.id}"
}

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 = "2"
vm_size = "Standard_DS2_v2"
vnet_subnet_id = "${azurerm_subnet.test.id}"
max_pods = 60
}

service_principal {
client_id = "%s"
client_secret = "%s"
}
}
`, rInt, location, rInt, 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 Expand Up @@ -729,7 +828,26 @@ 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 = "10.1.0.0/24"
address_prefix = "172.0.2.0/24"
route_table_id = "${azurerm_route_table.test.id}"
}

resource "azurerm_route_table" "test" {
name = "akc-routetable-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

route {
name = "akc-route-%d"
address_prefix = "10.100.0.0/14"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "10.10.1.1"
}
}

resource "azurerm_subnet_route_table_association" "test" {
subnet_id = "${azurerm_subnet.test.id}"
route_table_id = "${azurerm_route_table.test.id}"
}

resource "azurerm_kubernetes_cluster" "test" {
Expand Down Expand Up @@ -765,7 +883,7 @@ resource "azurerm_kubernetes_cluster" "test" {
service_cidr = "10.10.0.0/16"
}
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret, networkPlugin)
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret, networkPlugin)
}

func testCheckAzureRMKubernetesClusterExists(name string) resource.TestCheckFunc {
Expand Down
17 changes: 17 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ resource "azurerm_subnet" "test_subnet" {
virtual_network_name = "${azurerm_virtual_network.test_advanced_network.name}"
}

resource "azurerm_route_table" "test" {
metacpp marked this conversation as resolved.
Show resolved Hide resolved
name = "akc-routetable-1"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

route {
name = "akc-routetable"
address_prefix = "10.100.0.0/14"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "10.10.1.1"
}
}

resource "azurerm_subnet_route_table_association" "test" {
subnet_id = "${azurerm_subnet.test.id}"
route_table_id = "${azurerm_route_table.test.id}"
}
metacpp marked this conversation as resolved.
Show resolved Hide resolved

resource "azurerm_log_analytics_workspace" "test" {
name = "acctest-01"
Expand Down