-
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
azurerm_kubernetes_cluster
- add managed_cluster_identity
support
#5168
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2c126ec
Start of kubernetes MSI work
mbfrahry b9cbbfc
Add test/docs for managed cluster identity
mbfrahry d458957
gosimple
mbfrahry b9a0004
Update website/docs/r/kubernetes_cluster.html.markdown
katbyte 333e8e1
Addressing review
mbfrahry 2c21fbb
Merge branch 'f-kubernetes-msi' of https://github.com/terraform-provi…
mbfrahry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -560,6 +560,34 @@ func resourceArmKubernetesCluster() *schema.Resource { | |||||
Computed: true, | ||||||
Sensitive: true, | ||||||
}, | ||||||
|
||||||
"managed_cluster_identity": { | ||||||
Type: schema.TypeList, | ||||||
Optional: true, | ||||||
MaxItems: 1, | ||||||
ForceNew: true, | ||||||
Elem: &schema.Resource{ | ||||||
Schema: map[string]*schema.Schema{ | ||||||
"type": { | ||||||
Type: schema.TypeString, | ||||||
Required: true, | ||||||
ForceNew: true, | ||||||
ValidateFunc: validation.StringInSlice([]string{ | ||||||
string(containerservice.None), | ||||||
string(containerservice.SystemAssigned), | ||||||
}, false), | ||||||
}, | ||||||
"principal_id": { | ||||||
Type: schema.TypeString, | ||||||
Computed: true, | ||||||
}, | ||||||
"tenant_id": { | ||||||
Type: schema.TypeString, | ||||||
Computed: true, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
@@ -640,6 +668,9 @@ func resourceArmKubernetesClusterCreate(d *schema.ResourceData, meta interface{} | |||||
|
||||||
enablePodSecurityPolicy := d.Get("enable_pod_security_policy").(bool) | ||||||
|
||||||
managedClusterIdentityRaw := d.Get("managed_cluster_identity").([]interface{}) | ||||||
managedClusterIdentity := expandKubernetesClusterManagedClusterIdentity(managedClusterIdentityRaw) | ||||||
|
||||||
parameters := containerservice.ManagedCluster{ | ||||||
Name: &name, | ||||||
Location: &location, | ||||||
|
@@ -658,7 +689,8 @@ func resourceArmKubernetesClusterCreate(d *schema.ResourceData, meta interface{} | |||||
NodeResourceGroup: utils.String(nodeResourceGroup), | ||||||
EnablePodSecurityPolicy: utils.Bool(enablePodSecurityPolicy), | ||||||
}, | ||||||
Tags: tags.Expand(t), | ||||||
Identity: managedClusterIdentity, | ||||||
Tags: tags.Expand(t), | ||||||
} | ||||||
|
||||||
future, err := client.CreateOrUpdate(ctx, resGroup, name, parameters) | ||||||
|
@@ -792,6 +824,13 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} | |||||
existing.ManagedClusterProperties.WindowsProfile = windowsProfile | ||||||
} | ||||||
|
||||||
if d.HasChange("managed_cluster_identity") { | ||||||
updateCluster = true | ||||||
managedClusterIdentityRaw := d.Get("managed_cluster_identity").([]interface{}) | ||||||
managedClusterIdentity := expandKubernetesClusterManagedClusterIdentity(managedClusterIdentityRaw) | ||||||
existing.Identity = managedClusterIdentity | ||||||
} | ||||||
|
||||||
if updateCluster { | ||||||
log.Printf("[DEBUG] Updating the Kubernetes Cluster %q (Resource Group %q)..", name, resourceGroup) | ||||||
future, err := clusterClient.CreateOrUpdate(ctx, resourceGroup, name, existing) | ||||||
|
@@ -974,6 +1013,10 @@ func resourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}) | |||||
} | ||||||
} | ||||||
|
||||||
if err := d.Set("managed_cluster_identity", flattenKubernetesClusterManagedClusterIdentity(resp.Identity)); err != nil { | ||||||
return fmt.Errorf("Error setting `managed_cluster_identity`: %+v", err) | ||||||
} | ||||||
|
||||||
kubeConfigRaw, kubeConfig := flattenKubernetesClusterAccessProfile(profile) | ||||||
d.Set("kube_config_raw", kubeConfigRaw) | ||||||
if err := d.Set("kube_config", kubeConfig); err != nil { | ||||||
|
@@ -1403,6 +1446,20 @@ func expandKubernetesClusterRoleBasedAccessControl(input []interface{}, provider | |||||
return rbacEnabled, aad | ||||||
} | ||||||
|
||||||
func expandKubernetesClusterManagedClusterIdentity(input []interface{}) *containerservice.ManagedClusterIdentity { | ||||||
if len(input) == 0 || input[0] == nil { | ||||||
return nil | ||||||
} | ||||||
|
||||||
val := input[0].(map[string]interface{}) | ||||||
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. would
Suggested change
|
||||||
|
||||||
managedClusterIdentity := &containerservice.ManagedClusterIdentity{ | ||||||
Type: containerservice.ResourceIdentityType(val["type"].(string)), | ||||||
} | ||||||
|
||||||
return managedClusterIdentity | ||||||
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. This could also be
as there is no value is assigning it to a var |
||||||
} | ||||||
|
||||||
func flattenKubernetesClusterRoleBasedAccessControl(input *containerservice.ManagedClusterProperties, d *schema.ResourceData) []interface{} { | ||||||
rbacEnabled := false | ||||||
if input.EnableRBAC != nil { | ||||||
|
@@ -1529,3 +1586,20 @@ func flattenKubernetesClusterKubeConfigAAD(config kubernetes.KubeConfigAAD) []in | |||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
func flattenKubernetesClusterManagedClusterIdentity(input *containerservice.ManagedClusterIdentity) []interface{} { | ||||||
if input == nil { | ||||||
return []interface{}{} | ||||||
} | ||||||
|
||||||
identity := make(map[string]interface{}) | ||||||
if input.PrincipalID != nil { | ||||||
katbyte marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
identity["principal_id"] = *input.PrincipalID | ||||||
} | ||||||
if input.TenantID != nil { | ||||||
identity["tenant_id"] = *input.TenantID | ||||||
} | ||||||
identity["type"] = string(input.Type) | ||||||
|
||||||
return []interface{}{identity} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
minor but this could be
if the expand sig is changed