-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Enable RBAC without AAD #2347
Enable RBAC without AAD #2347
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,12 +315,17 @@ func resourceArmKubernetesCluster() *schema.Resource { | |
Type: schema.TypeList, | ||
Optional: true, | ||
ForceNew: true, | ||
MaxItems: 1, | ||
MaxItems: 2, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"enabled": { | ||
Type: schema.TypeBool, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"azure_active_directory": { | ||
Type: schema.TypeList, | ||
Required: true, | ||
Optional: true, | ||
ForceNew: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
|
@@ -450,8 +455,8 @@ func resourceArmKubernetesClusterCreateUpdate(d *schema.ResourceData, meta inter | |
} | ||
|
||
rbacRaw := d.Get("role_based_access_control").([]interface{}) | ||
azureADProfile := expandKubernetesClusterRoleBasedAccessControl(rbacRaw, tenantId) | ||
roleBasedAccessControlEnabled := azureADProfile != nil | ||
roleBasedAccessControlEnabled, azureADProfile := expandKubernetesClusterRoleBasedAccessControl(rbacRaw, tenantId) | ||
//roleBasedAccessControlEnabled := azureADProfile != nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can remove this line, since it's not being used |
||
|
||
parameters := containerservice.ManagedCluster{ | ||
Name: &name, | ||
|
@@ -552,7 +557,7 @@ func resourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}) | |
return fmt.Errorf("Error setting `network_profile`: %+v", err) | ||
} | ||
|
||
roleBasedAccessControl := flattenKubernetesClusterRoleBasedAccessControl(props.AadProfile, d) | ||
roleBasedAccessControl := flattenKubernetesClusterRoleBasedAccessControl(props.EnableRBAC, props.AadProfile, d) | ||
if err := d.Set("role_based_access_control", roleBasedAccessControl); err != nil { | ||
return fmt.Errorf("Error setting `role_based_access_control`: %+v", err) | ||
} | ||
|
@@ -914,14 +919,18 @@ func flattenKubernetesClusterNetworkProfile(profile *containerservice.NetworkPro | |
return []interface{}{values} | ||
} | ||
|
||
func expandKubernetesClusterRoleBasedAccessControl(input []interface{}, providerTenantId string) *containerservice.ManagedClusterAADProfile { | ||
func expandKubernetesClusterRoleBasedAccessControl(input []interface{}, providerTenantId string) (bool, *containerservice.ManagedClusterAADProfile) { | ||
if len(input) == 0 { | ||
return nil | ||
return false, nil | ||
} | ||
|
||
val := input[0].(map[string]interface{}) | ||
|
||
enabled := val["enabled"].(bool) | ||
azureADsRaw := val["azure_active_directory"].([]interface{}) | ||
if len(azureADsRaw) == 0 { | ||
return enabled, nil | ||
} | ||
|
||
azureAdRaw := azureADsRaw[0].(map[string]interface{}) | ||
|
||
clientAppId := azureAdRaw["client_app_id"].(string) | ||
|
@@ -933,17 +942,21 @@ func expandKubernetesClusterRoleBasedAccessControl(input []interface{}, provider | |
tenantId = providerTenantId | ||
} | ||
|
||
return &containerservice.ManagedClusterAADProfile{ | ||
return enabled, &containerservice.ManagedClusterAADProfile{ | ||
ClientAppID: utils.String(clientAppId), | ||
ServerAppID: utils.String(serverAppId), | ||
ServerAppSecret: utils.String(serverAppSecret), | ||
TenantID: utils.String(tenantId), | ||
} | ||
} | ||
|
||
func flattenKubernetesClusterRoleBasedAccessControl(input *containerservice.ManagedClusterAADProfile, d *schema.ResourceData) []interface{} { | ||
func flattenKubernetesClusterRoleBasedAccessControl(enabledRBAC *bool, input *containerservice.ManagedClusterAADProfile, d *schema.ResourceData) []interface{} { | ||
if input == nil { | ||
return []interface{}{} | ||
return []interface{}{ | ||
map[string]interface{}{ | ||
"enabled": *enabledRBAC, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's a crash we should check here |
||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we still need to set the |
||
} | ||
} | ||
|
||
profile := make(map[string]interface{}) | ||
|
@@ -978,6 +991,7 @@ func flattenKubernetesClusterRoleBasedAccessControl(input *containerservice.Mana | |
|
||
return []interface{}{ | ||
map[string]interface{}{ | ||
"enabled": *enabledRBAC, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's a potential crash here which we can nil-check around |
||
"azure_active_directory": []interface{}{ | ||
profile, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,7 @@ func TestAccAzureRMKubernetesCluster_roleBasedAccessControl(t *testing.T) { | |
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMKubernetesClusterExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "role_based_access_control.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.enabled", "true"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it'd be good to ensure this is set to |
||
resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.azure_active_directory.#", "1"), | ||
resource.TestCheckResourceAttrSet(resourceName, "role_based_access_control.0.azure_active_directory.0.client_app_id"), | ||
resource.TestCheckResourceAttrSet(resourceName, "role_based_access_control.0.azure_active_directory.0.server_app_id"), | ||
|
@@ -596,6 +597,7 @@ resource "azurerm_kubernetes_cluster" "test" { | |
} | ||
|
||
role_based_access_control { | ||
enabled=true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor can we fix the formatting here? |
||
azure_active_directory { | ||
server_app_id = "%s" | ||
server_app_secret = "%s" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there can only be a single block - so this can be flipped back to
1