From ec677b7e239414fe2e04f8cb521c74551dbba3d7 Mon Sep 17 00:00:00 2001 From: zjhe Date: Mon, 10 Oct 2022 17:49:01 +0800 Subject: [PATCH] Wrap `log_analytics_solution_id` to an object to fix #263. Add symbolic links notice in the readme. --- README.md | 15 ++++++++++++++- examples/named_cluster/main.tf | 18 +++++++++++++++++- locals.tf | 2 +- test/unit/unit_test.go | 4 +++- variables.tf | 14 ++++++++++---- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3fb3798a..5d8f8c46 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,19 @@ This Terraform module deploys a Kubernetes cluster on Azure using AKS (Azure Kub -> **NOTE:** If you have not assigned `client_id` or `client_secret`, A `SystemAssigned` identity will be created. +-> **NOTE:** Since this repo contains some symbolic links, clone this repo via the following command is **HIGHLY RECOMMENDED**, or your repo might not work as expected on your machine: + +```shell +$ git clone -c core.symlinks=true +``` + +Or you may need to set `core.sysmlinks` to `true` after you've cloned this repo then reset to the latest master branch: + +```shell +$ git config core.symlinks true +$ git reset --hard origin/master +``` + ## Notice on Upgrade to V6.x We've added a CI pipeline for this module to speed up our code review and to enforce a high code quality standard, if you want to contribute by submitting a pull request, please read [Pre-Commit & Pr-Check & Test](#Pre-Commit--Pr-Check--Test) section, or your pull request might be rejected by CI pipeline. @@ -305,7 +318,7 @@ No modules. | [kubernetes\_version](#input\_kubernetes\_version) | Specify which Kubernetes release to use. The default used is the latest Kubernetes version available in the region | `string` | `null` | no | | [local\_account\_disabled](#input\_local\_account\_disabled) | (Optional) - If `true` local accounts will be disabled. Defaults to `false`. See [the documentation](https://docs.microsoft.com/azure/aks/managed-aad#disable-local-accounts) for more information. | `bool` | `null` | no | | [location](#input\_location) | Location of cluster, if not defined it will be read from the resource-group | `string` | `null` | no | -| [log\_analytics\_solution\_id](#input\_log\_analytics\_solution\_id) | (Optional) Existing azurerm\_log\_analytics\_solution ID. Providing ID disables creation of azurerm\_log\_analytics\_solution. | `string` | `null` | no | +| [log\_analytics\_solution](#input\_log\_analytics\_solution) | (Optional) Object which contains existing azurerm\_log\_analytics\_solution ID. Providing ID disables creation of azurerm\_log\_analytics\_solution. |
object({
id = string
})
| `null` | no | | [log\_analytics\_workspace](#input\_log\_analytics\_workspace) | (Optional) Existing azurerm\_log\_analytics\_workspace to attach azurerm\_log\_analytics\_solution. Providing the config disables creation of azurerm\_log\_analytics\_workspace. |
object({
id = string
name = string
})
| `null` | no | | [log\_analytics\_workspace\_enabled](#input\_log\_analytics\_workspace\_enabled) | Enable the integration of azurerm\_log\_analytics\_workspace and azurerm\_log\_analytics\_solution: https://docs.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-onboard | `bool` | `true` | no | | [log\_analytics\_workspace\_resource\_group\_name](#input\_log\_analytics\_workspace\_resource\_group\_name) | (Optional) Resource group name to create azurerm\_log\_analytics\_solution. | `string` | `null` | no | diff --git a/examples/named_cluster/main.tf b/examples/named_cluster/main.tf index 4f1d4179..4e887adc 100644 --- a/examples/named_cluster/main.tf +++ b/examples/named_cluster/main.tf @@ -46,6 +46,19 @@ resource "azurerm_log_analytics_workspace" "main" { sku = "PerGB2018" } +resource "azurerm_log_analytics_solution" "main" { + location = local.resource_group.location + resource_group_name = local.resource_group.name + solution_name = "ContainerInsights" + workspace_name = azurerm_log_analytics_workspace.main.name + workspace_resource_id = azurerm_log_analytics_workspace.main.id + + plan { + product = "OMSGallery/ContainerInsights" + publisher = "Microsoft" + } +} + module "aks_cluster_name" { source = "../.." @@ -58,7 +71,10 @@ module "aks_cluster_name" { disk_encryption_set_id = azurerm_disk_encryption_set.des.id identity_ids = [azurerm_user_assigned_identity.test.id] identity_type = "UserAssigned" - log_analytics_workspace_enabled = true + log_analytics_solution = { + id = azurerm_log_analytics_solution.main.id + } + log_analytics_workspace_enabled = true log_analytics_workspace = { id = azurerm_log_analytics_workspace.main.id name = azurerm_log_analytics_workspace.main.name diff --git a/locals.tf b/locals.tf index a18ee0c3..168a798b 100644 --- a/locals.tf +++ b/locals.tf @@ -1,6 +1,6 @@ locals { # Abstract the decision whether to create an Analytics Workspace or not. - create_analytics_solution = var.log_analytics_workspace_enabled && var.log_analytics_solution_id == null + create_analytics_solution = var.log_analytics_workspace_enabled && var.log_analytics_solution == null create_analytics_workspace = var.log_analytics_workspace_enabled && var.log_analytics_workspace == null # Abstract the decision whether to use an Analytics Workspace supplied via vars, provision one ourselves or leave it null. # This guarantees that local.log_analytics_workspace will contain a valid `id` and `name` IFF log_analytics_workspace_enabled diff --git a/test/unit/unit_test.go b/test/unit/unit_test.go index 455b722e..1dddfef9 100644 --- a/test/unit/unit_test.go +++ b/test/unit/unit_test.go @@ -94,7 +94,9 @@ func TestLogAnalyticsWorkspaceEnabledNoSolutionProvidedShouldCreateSolution(t *t func TestLogAnalyticsWorkspaceEnabledSolutionProvidedShouldNotCreateSolution(t *testing.T) { vars := dummyRequiredVariables() vars["log_analytics_workspace_enabled"] = true - vars["log_analytics_solution_id"] = "dummySolutionId" + vars["log_analytics_solution"] = map[string]interface{}{ + "id": "dummySolutionId", + } test_helper.RunE2ETest(t, "../../", "unit-test-fixture", terraform.Options{ Upgrade: false, Vars: vars, diff --git a/variables.tf b/variables.tf index ba211f08..639bcf97 100644 --- a/variables.tf +++ b/variables.tf @@ -228,11 +228,17 @@ variable "location" { default = null } -variable "log_analytics_solution_id" { - type = string - description = "(Optional) Existing azurerm_log_analytics_solution ID. Providing ID disables creation of azurerm_log_analytics_solution." +variable "log_analytics_solution" { + type = object({ + id = string + }) + description = "(Optional) Object which contains existing azurerm_log_analytics_solution ID. Providing ID disables creation of azurerm_log_analytics_solution." default = null - nullable = true + validation { + condition = var.log_analytics_solution == null ? true : var.log_analytics_solution.id != null && var.log_analytics_solution.id != "" + error_message = "`var.log_analytics_solution` must be `null` or an object with a valid `id`." + } + nullable = true } variable "log_analytics_workspace" {