From 6168ed082554cb8b3697352ddf9e0bb4086711f6 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 28 Feb 2018 00:00:22 -0800 Subject: [PATCH] Changed admin_username and key_data to require a new resource. Fixed cash when key_data was empty. Added Kubernetes cluster example. --- azurerm/resource_arm_kubernetes_cluster.go | 10 +++-- examples/aci-linux-multi/main.tf | 2 +- examples/kubernetes-cluster/main.tf | 39 +++++++++++++++++++ examples/kubernetes-cluster/outputs.tf | 4 ++ examples/kubernetes-cluster/variables.tf | 37 ++++++++++++++++++ .../docs/r/kubernetes_cluster.html.markdown | 6 +-- 6 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 examples/kubernetes-cluster/main.tf create mode 100644 examples/kubernetes-cluster/outputs.tf create mode 100644 examples/kubernetes-cluster/variables.tf diff --git a/azurerm/resource_arm_kubernetes_cluster.go b/azurerm/resource_arm_kubernetes_cluster.go index dea24930099c..fbbe848b8aec 100644 --- a/azurerm/resource_arm_kubernetes_cluster.go +++ b/azurerm/resource_arm_kubernetes_cluster.go @@ -54,10 +54,13 @@ func resourceArmKubernetesCluster() *schema.Resource { "admin_username": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "ssh_key": { Type: schema.TypeList, Required: true, + ForceNew: true, + Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "key_data": { @@ -376,9 +379,10 @@ func expandAzureRmKubernetesClusterLinuxProfile(d *schema.ResourceData) containe adminUsername := config["admin_username"].(string) linuxKeys := config["ssh_key"].([]interface{}) - key := linuxKeys[0].(map[string]interface{}) - keyData := key["key_data"].(string) - + keyData := "" + if key, ok := linuxKeys[0].(map[string]interface{}); ok { + keyData = key["key_data"].(string) + } sshPublicKey := containerservice.SSHPublicKey{ KeyData: &keyData, } diff --git a/examples/aci-linux-multi/main.tf b/examples/aci-linux-multi/main.tf index ae735c2bb023..6d525b1a4e22 100644 --- a/examples/aci-linux-multi/main.tf +++ b/examples/aci-linux-multi/main.tf @@ -3,7 +3,7 @@ resource "azurerm_resource_group" "aci-rg" { location = "${var.resource_group_location}" } -#an attempt to keep the aci container group name (an dns label) somewhat omunique +#an attempt to keep the aci container group name (and dns label) somewhat unique resource "random_integer" "random_int" { min = 100 max = 999 diff --git a/examples/kubernetes-cluster/main.tf b/examples/kubernetes-cluster/main.tf new file mode 100644 index 000000000000..898312caa5fb --- /dev/null +++ b/examples/kubernetes-cluster/main.tf @@ -0,0 +1,39 @@ +resource "azurerm_resource_group" "akc-rg" { + name = "${var.resource_group_name}" + location = "${var.resource_group_location}" +} + +#an attempt to keep the aci container group name (and dns label) somewhat unique +resource "random_integer" "random_int" { + min = 100 + max = 999 +} + +resource "azurerm_kubernetes_cluster" "aks_container" { + name = "akc-${random_integer.random_int.result}" + location = "${var.resource_group_location}" + dns_prefix = "akc-${random_integer.random_int.result}" + + resource_group_name = "${azurerm_resource_group.akc-rg.name}" + kubernetes_version = "1.8.7" + + + linux_profile { + admin_username = "${var.linux_admin_username}" + ssh_key { + key_data = "${var.linux_admin_ssh_publickey}" + } + } + + agent_pool_profile { + name = "agentpool" + count = "2" + vm_size = "Standard_DS2_v2" + os_type = "Linux" + } + + service_principal { + client_id = "${var.client_id}" + client_secret = "${var.client_secret}" + } +} \ No newline at end of file diff --git a/examples/kubernetes-cluster/outputs.tf b/examples/kubernetes-cluster/outputs.tf new file mode 100644 index 000000000000..eb206a8c2ba2 --- /dev/null +++ b/examples/kubernetes-cluster/outputs.tf @@ -0,0 +1,4 @@ + +output "id" { + value = "${azurerm_kubernetes_cluster.aks_container.id}" +} diff --git a/examples/kubernetes-cluster/variables.tf b/examples/kubernetes-cluster/variables.tf new file mode 100644 index 000000000000..eb2648c13c3c --- /dev/null +++ b/examples/kubernetes-cluster/variables.tf @@ -0,0 +1,37 @@ +variable "name" { + type = "string" + description = "Name of this cluster." + default = "akc-example" +} + +variable "client_id" { + type = "string" + description = "Client ID" +} + +variable "client_secret" { + type = "string" + description = "Client secret." +} + +variable "resource_group_name" { + type = "string" + description = "Name of the azure resource group." + default = "akc-rg" +} + +variable "resource_group_location" { + type = "string" + description = "Location of the azure resource group." + default = "eastus" +} + +variable "linux_admin_username" { + type = "string" + description = "User name for authentication to the Kubernetes linux agent virtual machines in the cluster." +} + +variable "linux_admin_ssh_publickey" { + type = "string" + description = "Configure all the linux virtual machines in the cluster with the SSH RSA public key string. The key should include three parts, for example 'ssh-rsa AAAAB...snip...UcyupgH azureuser@linuxvm'" +} \ No newline at end of file diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index 8651df097afe..4ea4aaaf1a53 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -79,12 +79,12 @@ The following arguments are supported: `linux_profile` supports the following: -* `admin_username` - (Required) The Admin Username for the Cluster. +* `admin_username` - (Required) The Admin Username for the Cluster. Changing this forces a new resource to be created. * `ssh_key` - (Required) An SSH Key block as documented below. `ssh_key` supports the following: -* `key_data` - (Required) The Public SSH Key used to access the cluster. +* `key_data` - (Required) The Public SSH Key used to access the cluster. Changing this forces a new resource to be created. `agent_pool_profile` supports the following: @@ -105,7 +105,7 @@ The following attributes are exported: * `id` - The Kubernetes Managed Cluster ID. -* `fqdn` - The FQDN of the Azure Kubernetes Managed Cluster. +* `agent_pool_profile.#.fqdn` - The FQDN of the Azure Kubernetes Managed Cluster. ## Import