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

azurerm_kubernetes_cluster - Add support for OMS MSI authentication #20757

Merged
merged 5 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion examples/kubernetes/monitoring-log-analytics/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ resource "azurerm_kubernetes_cluster" "example" {
}

oms_agent {
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
msi_auth_for_monitoring_enabled = true
}
}
14 changes: 12 additions & 2 deletions internal/services/containers/kubernetes_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func schemaKubernetesAddOns() map[string]*pluginsdk.Schema {
Required: true,
ValidateFunc: workspaces.ValidateWorkspaceID,
},
"msi_auth_for_monitoring_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},
"oms_agent_identity": {
Type: pluginsdk.TypeList,
Computed: true,
Expand Down Expand Up @@ -318,6 +322,10 @@ func expandKubernetesAddOns(d *pluginsdk.ResourceData, input map[string]interfac
config["logAnalyticsWorkspaceResourceID"] = lawid.ID()
}

if useAADAuth, ok := value["msi_auth_for_monitoring_enabled"].(bool); ok {
config["useAADAuth"] = fmt.Sprintf("%t", useAADAuth)
}

addonProfiles[omsAgentKey] = managedclusters.ManagedClusterAddonProfile{
Enabled: true,
Config: &config,
Expand Down Expand Up @@ -495,11 +503,13 @@ func flattenKubernetesAddOns(profile map[string]managedclusters.ManagedClusterAd
}
}

useAADAuth := kubernetesAddonProfilelocateInConfig(omsAgent.Config, "useAADAuth")
EppO marked this conversation as resolved.
Show resolved Hide resolved
omsAgentIdentity := flattenKubernetesClusterAddOnIdentityProfile(omsAgent.Identity)

omsAgents = append(omsAgents, map[string]interface{}{
"log_analytics_workspace_id": workspaceID,
"oms_agent_identity": omsAgentIdentity,
"log_analytics_workspace_id": workspaceID,
"msi_auth_for_monitoring_enabled": useAADAuth,
"oms_agent_identity": omsAgentIdentity,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ func TestAccKubernetesCluster_addonProfileOMS(t *testing.T) {
})
}

func TestAccKubernetesCluster_addonProfileOMSWithMSI(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.addonProfileOMSConfigWithMSI(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesCluster_addonProfileOMSToggle(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}
Expand Down Expand Up @@ -509,6 +524,69 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) addonProfileOMSConfigWithMSI(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}

resource "azurerm_log_analytics_workspace" "test" {
name = "acctest-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "PerGB2018"
}

resource "azurerm_log_analytics_solution" "test" {
solution_name = "ContainerInsights"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
workspace_resource_id = azurerm_log_analytics_workspace.test.id
workspace_name = azurerm_log_analytics_workspace.test.name

plan {
publisher = "Microsoft"
product = "OMSGallery/ContainerInsights"
}
}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"

linux_profile {
admin_username = "acctestuser%d"

ssh_key {
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt [email protected]"
}
}

default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}

oms_agent {
log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id
msi_auth_for_monitoring_enabled = true
}

identity {
type = "SystemAssigned"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) addonProfileOMSDisabledConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ An `oms_agent` block exports the following:

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

* `msi_auth_for_monitoring_enabled` - Is managed identity authentication for monitoring enabled?
EppO marked this conversation as resolved.
Show resolved Hide resolved

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

---
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ An `oms_agent` block supports the following:

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

* `msi_auth_for_monitoring_enabled` - Is managed identity authentication for monitoring enabled?

---

An `ingress_application_gateway` block supports the following:
Expand Down Expand Up @@ -979,6 +981,8 @@ The `oms_agent` block exports the following:

* `oms_agent_identity` - An `oms_agent_identity` block is exported. The exported attributes are defined below.

* `msi_auth_for_monitoring_enabled` - Is managed identity authentication for monitoring enabled?

EppO marked this conversation as resolved.
Show resolved Hide resolved
---

The `oms_agent_identity` block exports the following:
Expand Down