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

Update r/azurerm_kubernetes_cluster: add support for kubelet_identity #6393

Merged
merged 4 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,42 @@ func resourceArmKubernetesCluster() *schema.Resource {
},
},

"identity_profile": {
Type: schema.TypeList,
Optional: true,
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
Computed: true,
MaxItems: 1,
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kubelet_identity": {
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeList,
Optional: true,
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
Computed: true,
MaxItems: 1,
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_id": {
Type: schema.TypeString,
Optional: true,
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
Computed: true,
},
"object_id": {
Type: schema.TypeString,
Optional: true,
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
Computed: true,
},
"resource_id": {
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
Computed: true,
},
},
},
},
},
},
},

"linux_profile": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -909,6 +945,11 @@ func resourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("setting `default_node_pool`: %+v", err)
}

identityProfile := flattenKubernetesClusterIdentityProfile(props.IdentityProfile)
if err := d.Set("identity_profile", identityProfile); err != nil {
return fmt.Errorf("setting `identity_profile`: %+v", err)
}

linuxProfile := flattenKubernetesClusterLinuxProfile(props.LinuxProfile)
if err := d.Set("linux_profile", linuxProfile); err != nil {
return fmt.Errorf("setting `linux_profile`: %+v", err)
Expand Down Expand Up @@ -1042,6 +1083,42 @@ func expandKubernetesClusterLinuxProfile(input []interface{}) *containerservice.
}
}

func flattenKubernetesClusterIdentityProfile(profile map[string]*containerservice.ManagedClusterPropertiesIdentityProfileValue) []interface{} {
if profile == nil {
return []interface{}{}
}

kubeletIdentity := make([]interface{}, 0)
if kubeletidentity := profile["kubeletidentity"]; kubeletidentity != nil {
clientId := ""
if clientid := kubeletidentity.ClientID; clientid != nil {
clientId = *clientid
}

objectId := ""
if objectid := kubeletidentity.ObjectID; objectid != nil {
objectId = *objectid
}

resourceId := ""
if resourceid := kubeletidentity.ResourceID; resourceid != nil {
resourceId = *resourceid
}

kubeletIdentity = append(kubeletIdentity, map[string]interface{}{
"client_id": clientId,
"object_id": objectId,
"resource_id": resourceId,
})
}

return []interface{}{
map[string]interface{}{
"kubelet_identity": kubeletIdentity,
},
}
}

func flattenKubernetesClusterLinuxProfile(profile *containerservice.LinuxProfile) []interface{} {
if profile == nil {
return []interface{}{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func testAccAzureRMKubernetesCluster_managedClusterIdentity(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"),
resource.TestCheckResourceAttrSet(data.ResourceName, "identity_profile.0.kubelet_identity.0.client_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "identity_profile.0.kubelet_identity.0.object_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "identity_profile.0.kubelet_identity.0.resource_id"),
resource.TestCheckResourceAttr(data.ResourceName, "service_principal.%", "0"),
),
},
Expand Down
18 changes: 18 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ The following attributes are exported:

* `node_resource_group` - The auto-generated Resource Group which contains the resources for this Managed Kubernetes Cluster.

* `identity_profile` - A `identity_profile` block as defined below.

---

A `http_application_routing` block exports the following:
Expand All @@ -382,6 +384,22 @@ The `identity` block exports the following:

---

The `identity_profile` block exports the following:

* `kubelet_identity` - A `kubelet_identity` block as defined below.

---

The `kubelet_identity` block exports the following:

* `client_id` - The client id of the user-defined Managed Identity assigned to the kubelets.
aristosvo marked this conversation as resolved.
Show resolved Hide resolved

* `object_id` - The object id of the user-defined Managed Identity assigned to the kubelets.
aristosvo marked this conversation as resolved.
Show resolved Hide resolved

* `resource_id` - The resource id of the user-defined Managed Identity assigned to the kubelets.
aristosvo marked this conversation as resolved.
Show resolved Hide resolved

---

The `kube_admin_config` and `kube_config` blocks export the following:

* `client_key` - Base64 encoded private key used by clients to authenticate to the Kubernetes cluster.
Expand Down