Skip to content

Commit

Permalink
Merge pull request #904 from terraform-providers/b-kubernetes_cluster…
Browse files Browse the repository at this point in the history
…-admin

Changed admin_username and key_data to require a new resource.
  • Loading branch information
katbyte authored Feb 28, 2018
2 parents 3a05739 + 6168ed0 commit d329df7
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
10 changes: 7 additions & 3 deletions azurerm/resource_arm_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/aci-linux-multi/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions examples/kubernetes-cluster/main.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
}
4 changes: 4 additions & 0 deletions examples/kubernetes-cluster/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

output "id" {
value = "${azurerm_kubernetes_cluster.aks_container.id}"
}
37 changes: 37 additions & 0 deletions examples/kubernetes-cluster/variables.tf
Original file line number Diff line number Diff line change
@@ -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'"
}
6 changes: 3 additions & 3 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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

Expand Down

0 comments on commit d329df7

Please sign in to comment.