From aa8b1f56bfb8c1494a46764279aab061d0acfa61 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 12 Dec 2018 13:26:09 +0000 Subject: [PATCH] r/kubernetes_cluster: fixing a null-ref --- azurerm/resource_arm_kubernetes_cluster.go | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/azurerm/resource_arm_kubernetes_cluster.go b/azurerm/resource_arm_kubernetes_cluster.go index 4df32ca590f7..0e413785df41 100644 --- a/azurerm/resource_arm_kubernetes_cluster.go +++ b/azurerm/resource_arm_kubernetes_cluster.go @@ -986,25 +986,30 @@ func expandKubernetesClusterRoleBasedAccessControl(input []interface{}, provider val := input[0].(map[string]interface{}) rbacEnabled := val["enabled"].(bool) - azureADsRaw := val["azure_active_directory"].([]interface{}) - azureAdRaw := azureADsRaw[0].(map[string]interface{}) - clientAppId := azureAdRaw["client_app_id"].(string) - serverAppId := azureAdRaw["server_app_id"].(string) - serverAppSecret := azureAdRaw["server_app_secret"].(string) - tenantId := azureAdRaw["tenant_id"].(string) + var aad *containerservice.ManagedClusterAADProfile + if len(azureADsRaw) > 0 { + azureAdRaw := azureADsRaw[0].(map[string]interface{}) - if tenantId == "" { - tenantId = providerTenantId - } + clientAppId := azureAdRaw["client_app_id"].(string) + serverAppId := azureAdRaw["server_app_id"].(string) + serverAppSecret := azureAdRaw["server_app_secret"].(string) + tenantId := azureAdRaw["tenant_id"].(string) + + if tenantId == "" { + tenantId = providerTenantId + } - return rbacEnabled, &containerservice.ManagedClusterAADProfile{ - ClientAppID: utils.String(clientAppId), - ServerAppID: utils.String(serverAppId), - ServerAppSecret: utils.String(serverAppSecret), - TenantID: utils.String(tenantId), + aad = &containerservice.ManagedClusterAADProfile{ + ClientAppID: utils.String(clientAppId), + ServerAppID: utils.String(serverAppId), + ServerAppSecret: utils.String(serverAppSecret), + TenantID: utils.String(tenantId), + } } + + return rbacEnabled, aad } func flattenKubernetesClusterRoleBasedAccessControl(input *containerservice.ManagedClusterProperties, d *schema.ResourceData) []interface{} {