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

azurerm_kubernetes_cluster - making linux_profile optional #1821

Merged
merged 10 commits into from
Aug 30, 2018
Merged
50 changes: 33 additions & 17 deletions azurerm/resource_arm_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func resourceArmKubernetesCluster() *schema.Resource {

"linux_profile": {
Type: schema.TypeList,
Required: true,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -403,7 +403,7 @@ func resourceArmKubernetesClusterCreate(d *schema.ResourceData, meta interface{}
AgentPoolProfiles: &agentProfiles,
DNSPrefix: &dnsPrefix,
KubernetesVersion: &kubernetesVersion,
LinuxProfile: &linuxProfile,
LinuxProfile: linuxProfile,
ServicePrincipalProfile: servicePrincipalProfile,
NetworkProfile: networkProfile,
},
Expand Down Expand Up @@ -532,33 +532,40 @@ func resourceArmKubernetesClusterDelete(d *schema.ResourceData, meta interface{}
return future.WaitForCompletionRef(ctx, kubernetesClustersClient.Client)
}

func flattenAzureRmKubernetesClusterLinuxProfile(input *containerservice.LinuxProfile) []interface{} {
func flattenAzureRmKubernetesClusterLinuxProfile(profile *containerservice.LinuxProfile) []interface{} {
if profile == nil {
return []interface{}{}
}

values := make(map[string]interface{})
sshKeys := make([]interface{}, 0)

if profile := input; profile != nil {
if username := profile.AdminUsername; username != nil {
values["admin_username"] = *username
}
if username := profile.AdminUsername; username != nil {
values["admin_username"] = *username
}

if ssh := profile.SSH; ssh != nil {
if keys := ssh.PublicKeys; keys != nil {
for _, sshKey := range *keys {
outputs := make(map[string]interface{}, 0)
if keyData := sshKey.KeyData; keyData != nil {
outputs["key_data"] = *keyData
}
sshKeys = append(sshKeys, outputs)
if ssh := profile.SSH; ssh != nil {
if keys := ssh.PublicKeys; keys != nil {
for _, sshKey := range *keys {
outputs := make(map[string]interface{}, 0)
if keyData := sshKey.KeyData; keyData != nil {
outputs["key_data"] = *keyData
}
sshKeys = append(sshKeys, outputs)
}
}
}

values["ssh_key"] = sshKeys

return []interface{}{values}
}

func flattenAzureRmKubernetesClusterAgentPoolProfiles(profiles *[]containerservice.ManagedClusterAgentPoolProfile, fqdn *string) []interface{} {
if profiles == nil {
return []interface{}{}
}

agentPoolProfiles := make([]interface{}, 0)

for _, profile := range *profiles {
Expand Down Expand Up @@ -650,6 +657,10 @@ func flattenAzureRmKubernetesClusterAccessProfile(profile *containerservice.Mana
}

func flattenAzureRmKubernetesClusterNetworkProfile(profile *containerservice.NetworkProfile) []interface{} {
if profile == nil {
return []interface{}{}
}

values := make(map[string]interface{})

values["network_plugin"] = profile.NetworkPlugin
Expand Down Expand Up @@ -690,8 +701,13 @@ func flattenKubernetesClusterKubeConfig(config kubernetes.KubeConfig) []interfac
return []interface{}{values}
}

func expandAzureRmKubernetesClusterLinuxProfile(d *schema.ResourceData) containerservice.LinuxProfile {
func expandAzureRmKubernetesClusterLinuxProfile(d *schema.ResourceData) *containerservice.LinuxProfile {
profiles := d.Get("linux_profile").([]interface{})

if len(profiles) == 0 {
return nil
}

config := profiles[0].(map[string]interface{})

adminUsername := config["admin_username"].(string)
Expand All @@ -714,7 +730,7 @@ func expandAzureRmKubernetesClusterLinuxProfile(d *schema.ResourceData) containe
},
}

return profile
return &profile
}

func expandAzureRmKubernetesClusterServicePrincipal(d *schema.ResourceData) *containerservice.ServicePrincipalProfile {
Expand Down
12 changes: 2 additions & 10 deletions azurerm/resource_arm_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,6 @@ resource "azurerm_kubernetes_cluster" "test" {
dns_prefix = "acctestaks%d"
kubernetes_version = "1.7.7"

linux_profile {
admin_username = "acctestuser%d"

ssh_key {
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt [email protected]"
}
}

agent_pool_profile {
name = "default"
count = "1"
Expand All @@ -357,7 +349,7 @@ resource "azurerm_kubernetes_cluster" "test" {
client_secret = "%s"
}
}
`, rInt, location, rInt, rInt, rInt, clientId, clientSecret)
`, rInt, location, rInt, rInt, clientId, clientSecret)
metacpp marked this conversation as resolved.
Show resolved Hide resolved
}

func testAccAzureRMKubernetesCluster_addAgent(rInt int, clientId string, clientSecret string, location string) string {
Expand Down Expand Up @@ -489,7 +481,7 @@ resource "azurerm_kubernetes_cluster" "test" {
client_id = "%s"
client_secret = "%s"
}

addon_profile {
oms_agent {
enabled = true
Expand Down
10 changes: 1 addition & 9 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ resource "azurerm_kubernetes_cluster" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
dns_prefix   = "acctestagent1"

linux_profile {
admin_username = "acctestuser1"

ssh_key {
key_data = "ssh-rsa ..."
}
}

agent_pool_profile {
name = "default"
count = 1
Expand Down Expand Up @@ -180,7 +172,7 @@ The following arguments are supported:

* `dns_prefix` - (Required) DNS prefix specified when creating the managed cluster.

* `linux_profile` - (Required) A Linux Profile block as documented below.
* `linux_profile` - (Optional) A Linux Profile block as documented below.

* `agent_pool_profile` - (Required) One or more Agent Pool Profile's block as documented below.

Expand Down