Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ No modules.
| [null_resource.kubernetes_version_keeper](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [null_resource.pool_name_keeper](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [tls_private_key.ssh](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
| [azurerm_log_analytics_workspace.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/log_analytics_workspace) | data source |
| [azurerm_resource_group.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |

## Inputs
Expand Down
4 changes: 2 additions & 2 deletions examples/named_cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ resource "azurerm_user_assigned_identity" "test" {

# Just for demo purpose, not necessary to named cluster.
resource "azurerm_log_analytics_workspace" "main" {
location = local.resource_group.location
location = coalesce(var.log_analytics_workspace_location, local.resource_group.location)
name = "prefix-workspace"
resource_group_name = local.resource_group.name
retention_in_days = 30
sku = "PerGB2018"
}

resource "azurerm_log_analytics_solution" "main" {
location = local.resource_group.location
location = coalesce(var.log_analytics_workspace_location, local.resource_group.location)
resource_group_name = local.resource_group.name
solution_name = "ContainerInsights"
workspace_name = azurerm_log_analytics_workspace.main.name
Expand Down
4 changes: 4 additions & 0 deletions examples/named_cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ variable "location" {
default = "eastus"
}

variable "log_analytics_workspace_location" {
default = null
}

variable "managed_identity_principal_id" {
type = string
default = null
Expand Down
16 changes: 13 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ resource "azurerm_kubernetes_cluster" "main" {
service_cidr = var.net_profile_service_cidr

dynamic "load_balancer_profile" {
for_each = var.load_balancer_profile_enabled && var.load_balancer_sku == "standard" ? ["load_balancer_profile"] : []
for_each = var.load_balancer_profile_enabled && var.load_balancer_sku == "standard" ? [
"load_balancer_profile"
] : []

content {
idle_timeout_in_minutes = var.load_balancer_profile_idle_timeout_in_minutes
Expand Down Expand Up @@ -662,11 +664,19 @@ locals {
azurerm_log_analytics_workspace_name = try(azurerm_log_analytics_workspace.main[0].name, null)
}

data "azurerm_log_analytics_workspace" "main" {
count = local.log_analytics_workspace != null ? 1 : 0

name = local.log_analytics_workspace.name
# `azurerm_log_analytics_workspace`'s id format: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.OperationalInsights/workspaces/workspace1
resource_group_name = split("/", local.log_analytics_workspace.id)[4]
}

resource "azurerm_log_analytics_solution" "main" {
count = local.create_analytics_solution ? 1 : 0

location = coalesce(var.location, data.azurerm_resource_group.main.location)
resource_group_name = coalesce(var.log_analytics_workspace_resource_group_name, var.resource_group_name)
location = data.azurerm_log_analytics_workspace.main[0].location
resource_group_name = data.azurerm_log_analytics_workspace.main[0].resource_group_name
solution_name = "ContainerInsights"
workspace_name = local.log_analytics_workspace.name
workspace_resource_id = local.log_analytics_workspace.id
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/terraform_aks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,18 @@ func TestExamplesWithoutAssertion(t *testing.T) {
})
}
}

func TestExamples_differentLocationForLogAnalyticsSolution(t *testing.T) {
var vars map[string]any
managedIdentityId := os.Getenv("MSI_ID")
if managedIdentityId != "" {
vars = map[string]any{
"managed_identity_principal_id": managedIdentityId,
}
}
vars["log_analytics_workspace_location"] = "eastus2"
test_helper.RunE2ETest(t, "../../", "examples/named_cluster", terraform.Options{
Upgrade: true,
Vars: vars,
}, nil)
}