From 4b823c35af4225b9bdba715c6f9d3c597fc1c2ea Mon Sep 17 00:00:00 2001 From: zjhe Date: Mon, 10 Oct 2022 17:49:01 +0800 Subject: [PATCH 1/2] Wrap `log_analytics_solution_id` to an object to fix #263. Add symbolic links notice in the readme. --- README.md | 2 +- examples/named_cluster/main.tf | 18 +++++++++++++++++- locals.tf | 2 +- test/unit/unit_test.go | 4 +++- variables.tf | 13 ++++++++++--- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7fbf29fc..3073a715 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ No modules. | [load\_balancer\_sku](#input\_load\_balancer\_sku) | (Optional) Specifies the SKU of the Load Balancer used for this Kubernetes Cluster. Possible values are `basic` and `standard`. Defaults to `standard`. Changing this forces a new kubernetes cluster to be created. | `string` | `"standard"` | 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 6d1badc3..9e33f701 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 c3b154cb..ae748c0b 100644 --- a/locals.tf +++ b/locals.tf @@ -11,7 +11,7 @@ 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 18d71d4d..519c808b 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 0600f5b6..4fe52cb5 100644 --- a/variables.tf +++ b/variables.tf @@ -561,10 +561,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 + 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" { From 8d788907327b400dae15f9d768f58796059a488f Mon Sep 17 00:00:00 2001 From: hezijie Date: Mon, 10 Apr 2023 12:13:43 +0800 Subject: [PATCH 2/2] fix tflint issue --- variables.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/variables.tf b/variables.tf index 4fe52cb5..29853ee2 100644 --- a/variables.tf +++ b/variables.tf @@ -571,7 +571,6 @@ variable "log_analytics_solution" { 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" {