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

Support for azurerm_kubernetes_cluster OMS Agent Identity export #7056

Merged
merged 1 commit into from May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 58 additions & 5 deletions azurerm/internal/services/containers/kubernetes_addons.go
Expand Up @@ -127,6 +127,26 @@ func schemaKubernetesAddOnProfiles() *schema.Schema {
Optional: true,
ValidateFunc: azureHelpers.ValidateResourceID,
},
"oms_agent_identity": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_id": {
Type: schema.TypeString,
Computed: true,
},
"object_id": {
Type: schema.TypeString,
Computed: true,
},
"user_assigned_identity_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -170,8 +190,8 @@ func expandKubernetesAddOnProfiles(input []interface{}, env azure.Environment) (
config := make(map[string]*string)
enabled := value["enabled"].(bool)

if workspaceId, ok := value["log_analytics_workspace_id"]; ok && workspaceId != "" {
config["logAnalyticsWorkspaceResourceID"] = utils.String(workspaceId.(string))
if workspaceID, ok := value["log_analytics_workspace_id"]; ok && workspaceID != "" {
config["logAnalyticsWorkspaceResourceID"] = utils.String(workspaceID.(string))
}

addonProfiles[omsAgentKey] = &containerservice.ManagedClusterAddonProfile{
Expand Down Expand Up @@ -330,14 +350,17 @@ func flattenKubernetesAddOnProfiles(profile map[string]*containerservice.Managed
enabled = *enabledVal
}

workspaceId := ""
workspaceID := ""
if workspaceResourceID := omsAgent.Config["logAnalyticsWorkspaceResourceID"]; workspaceResourceID != nil {
workspaceId = *workspaceResourceID
workspaceID = *workspaceResourceID
}

omsagentIdentity := flattenKubernetesClusterOmsAgentIdentityProfile(omsAgent.Identity)

omsAgents = append(omsAgents, map[string]interface{}{
"enabled": enabled,
"log_analytics_workspace_id": workspaceId,
"log_analytics_workspace_id": workspaceID,
"oms_agent_identity": omsagentIdentity,
})
}

Expand All @@ -356,3 +379,33 @@ func flattenKubernetesAddOnProfiles(profile map[string]*containerservice.Managed
},
}
}

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

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

objectID := ""
if objectid := profile.ObjectID; objectid != nil {
objectID = *objectid
}

userAssignedIdentityID := ""
if resourceid := profile.ResourceID; resourceid != nil {
userAssignedIdentityID = *resourceid
}

identity = append(identity, map[string]interface{}{
"client_id": clientID,
"object_id": objectID,
"user_assigned_identity_id": userAssignedIdentityID,
})

return identity
}
Expand Up @@ -68,6 +68,26 @@ func dataSourceArmKubernetesCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"oms_agent_identity": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_id": {
Type: schema.TypeString,
Computed: true,
},
"object_id": {
Type: schema.TypeString,
Computed: true,
},
"user_assigned_identity_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -664,14 +684,17 @@ func flattenKubernetesClusterDataSourceAddonProfiles(profile map[string]*contain
enabled = *enabledVal
}

workspaceId := ""
workspaceID := ""
if workspaceResourceID := omsAgent.Config["logAnalyticsWorkspaceResourceID"]; workspaceResourceID != nil {
workspaceId = *workspaceResourceID
workspaceID = *workspaceResourceID
}

omsagentIdentity := flattenKubernetesClusterDataSourceOmsAgentIdentityProfile(omsAgent.Identity)

output := map[string]interface{}{
"enabled": enabled,
"log_analytics_workspace_id": workspaceId,
"log_analytics_workspace_id": workspaceID,
"oms_agent_identity": omsagentIdentity,
}
agents = append(agents, output)
}
Expand Down Expand Up @@ -708,6 +731,36 @@ func flattenKubernetesClusterDataSourceAddonProfiles(profile map[string]*contain
return []interface{}{values}
}

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

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

objectID := ""
if objectid := profile.ObjectID; objectid != nil {
objectID = *objectid
}

userAssignedIdentityID := ""
if resourceid := profile.ResourceID; resourceid != nil {
userAssignedIdentityID = *resourceid
}

identity = append(identity, map[string]interface{}{
"client_id": clientID,
"object_id": objectID,
"user_assigned_identity_id": userAssignedIdentityID,
})

return identity
}

func flattenKubernetesClusterDataSourceAgentPoolProfiles(input *[]containerservice.ManagedClusterAgentPoolProfile) []interface{} {
agentPoolProfiles := make([]interface{}, 0)

Expand Down Expand Up @@ -865,8 +918,8 @@ func flattenKubernetesClusterDataSourceServicePrincipalProfile(profile *containe

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

if clientId := profile.ClientID; clientId != nil {
values["client_id"] = *clientId
if clientID := profile.ClientID; clientID != nil {
values["client_id"] = *clientID
}

return []interface{}{values}
Expand Down
Expand Up @@ -138,6 +138,9 @@ func testAccAzureRMKubernetesCluster_addonProfileOMS(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.#", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.0.enabled", "true"),
resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.oms_agent_identity.0.client_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.oms_agent_identity.0.object_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.oms_agent_identity.0.user_assigned_identity_id"),
),
},
data.ImportStep(),
Expand Down
Expand Up @@ -415,6 +415,9 @@ func testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMS(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.#", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.0.enabled", "true"),
resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.oms_agent_identity.0.client_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.oms_agent_identity.0.object_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.oms_agent_identity.0.user_assigned_identity_id"),
),
},
},
Expand Down
12 changes: 12 additions & 0 deletions website/docs/d/kubernetes_cluster.html.markdown
Expand Up @@ -211,6 +211,18 @@ A `oms_agent` block exports the following:

* `log_analytics_workspace_id` - The ID of the Log Analytics Workspace which the OMS Agent should send data to.

* `oms_agent_identity` - An `oms_agent_identity` block as defined below.

---

The `oms_agent_identity` block exports the following:

* `client_id` - The Client ID of the user-defined Managed Identity used by the OMS Agents.

* `object_id` - The Object ID of the user-defined Managed Identity used by the OMS Agents.

* `user_assigned_identity_id` - The ID of the User Assigned Identity used by the OMS Agents.

---

A `kube_dashboard` block supports the following:
Expand Down
12 changes: 12 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Expand Up @@ -313,6 +313,8 @@ A `oms_agent` block supports the following:

* `log_analytics_workspace_id` - (Optional) The ID of the Log Analytics Workspace which the OMS Agent should send data to. Must be present if `enabled` is `true`.

* `oms_agent_identity` - An `oms_agent_identity` block as defined below.

---

A `role_based_access_control` block supports the following:
Expand Down Expand Up @@ -400,6 +402,16 @@ The `kubelet_identity` block exports the following:

---

The `oms_agent_identity` block exports the following:

* `client_id` - The Client ID of the user-defined Managed Identity used by the OMS Agents.

* `object_id` - The Object ID of the user-defined Managed Identity used by the OMS Agents.

* `user_assigned_identity_id` - The ID of the User Assigned Identity used by the OMS Agents.

---

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