Skip to content

Commit

Permalink
azurerm_kubernetes_cluster: Add support for virtual machine scale set…
Browse files Browse the repository at this point in the history
… node pool (#3422)
  • Loading branch information
dominik-lekse authored and katbyte committed May 12, 2019
1 parent fa53685 commit 77d8dd0
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
9 changes: 9 additions & 0 deletions azurerm/data_source_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func dataSourceArmKubernetesCluster() *schema.Resource {
Computed: true,
},

"type": {
Type: schema.TypeString,
Computed: true,
},

"count": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -551,6 +556,10 @@ func flattenKubernetesClusterDataSourceAgentPoolProfiles(input *[]containerservi
for _, profile := range *input {
agentPoolProfile := make(map[string]interface{})

if profile.Type != "" {
agentPoolProfile["type"] = string(profile.Type)
}

if profile.Count != nil {
agentPoolProfile["count"] = int(*profile.Count)
}
Expand Down
16 changes: 16 additions & 0 deletions azurerm/resource_arm_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ func resourceArmKubernetesCluster() *schema.Resource {
ValidateFunc: validate.KubernetesAgentPoolName,
},

"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(containerservice.AvailabilitySet),
string(containerservice.VirtualMachineScaleSets),
}, false),
},

"count": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -897,13 +907,15 @@ func expandKubernetesClusterAgentPoolProfiles(d *schema.ResourceData) []containe
config := configs[0].(map[string]interface{})

name := config["name"].(string)
poolType := config["type"].(string)
count := int32(config["count"].(int))
vmSize := config["vm_size"].(string)
osDiskSizeGB := int32(config["os_disk_size_gb"].(int))
osType := config["os_type"].(string)

profile := containerservice.ManagedClusterAgentPoolProfile{
Name: utils.String(name),
Type: containerservice.AgentPoolType(poolType),
Count: utils.Int32(count),
VMSize: containerservice.VMSizeTypes(vmSize),
OsDiskSizeGB: utils.Int32(osDiskSizeGB),
Expand Down Expand Up @@ -932,6 +944,10 @@ func flattenKubernetesClusterAgentPoolProfiles(profiles *[]containerservice.Mana
for _, profile := range *profiles {
agentPoolProfile := make(map[string]interface{})

if profile.Type != "" {
agentPoolProfile["type"] = string(profile.Type)
}

if profile.Count != nil {
agentPoolProfile["count"] = int(*profile.Count)
}
Expand Down
68 changes: 68 additions & 0 deletions azurerm/resource_arm_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,46 @@ func TestAccAzureRMKubernetesCluster_apiServerAuthorizedIPRanges(t *testing.T) {
})
}

func TestAccAzureRMKubernetesCluster_virtualMachineScaleSets(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_virtualMachineScaleSets(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, "role_based_access_control.#", "1"),
resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.azure_active_directory.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_key"),
resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_certificate"),
resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.cluster_ca_certificate"),
resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.host"),
resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.username"),
resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.password"),
resource.TestCheckResourceAttr(resourceName, "kube_admin_config.#", "0"),
resource.TestCheckResourceAttr(resourceName, "kube_admin_config_raw", ""),
resource.TestCheckResourceAttrSet(resourceName, "agent_pool_profile.0.max_pods"),
resource.TestCheckResourceAttr(resourceName, "agent_pool_profile.0.type", "VirtualMachineScaleSets"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckAzureRMKubernetesClusterExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -1431,3 +1471,31 @@ resource "azurerm_kubernetes_cluster" "test" {
}
`, rInt, location, rInt, rInt, clientId, clientSecret)
}

func testAccAzureRMKubernetesCluster_virtualMachineScaleSets(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"
type = "VirtualMachineScaleSets"
count = "1"
vm_size = "Standard_DS2_v2"
}
service_principal {
client_id = "%s"
client_secret = "%s"
}
}
`, rInt, location, rInt, rInt, clientId, clientSecret)
}
2 changes: 2 additions & 0 deletions website/docs/d/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ A `addon_profile` block exports the following:

A `agent_pool_profile` block exports the following:

* `type` - The type of the Agent Pool.

* `count` - The number of Agents (VM's) in the Pool.

* `max_pods` - The maximum number of pods that can run on each agent.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ A `agent_pool_profile` block supports the following:
* `count` - (Required) Number of Agents (VMs) in the Pool. Possible values must be in the range of 1 to 100 (inclusive). Defaults to `1`.
* `vm_size` - (Required) The size of each VM in the Agent Pool (e.g. `Standard_F1`). Changing this forces a new resource to be created.

* `type` - (Optional) Type of the Agent Pool. Possible values are `AvailabilitySet` and `VirtualMachineScaleSets`. Changing this forces a new resource to be created. Defaults to `AvailabilitySet`.
* `max_pods` - (Optional) The maximum number of pods that can run on each agent.
* `os_disk_size_gb` - (Optional) The Agent Operating System disk size in GB. Changing this forces a new resource to be created.
* `os_type` - (Optional) The Operating System used for the Agents. Possible values are `Linux` and `Windows`. Changing this forces a new resource to be created. Defaults to `Linux`.
Expand Down

0 comments on commit 77d8dd0

Please sign in to comment.