Skip to content

Commit

Permalink
Wrap log_analytics_solution_id to an object to fix #263.
Browse files Browse the repository at this point in the history
Add symbolic links notice in the readme.
  • Loading branch information
lonegunmanb committed Oct 18, 2022
1 parent 3d63a90 commit ec677b7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <repository_url>
```

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.
Expand Down Expand Up @@ -305,7 +318,7 @@ No modules.
| <a name="input_kubernetes_version"></a> [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 |
| <a name="input_local_account_disabled"></a> [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 |
| <a name="input_location"></a> [location](#input\_location) | Location of cluster, if not defined it will be read from the resource-group | `string` | `null` | no |
| <a name="input_log_analytics_solution_id"></a> [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 |
| <a name="input_log_analytics_solution"></a> [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. | <pre>object({<br> id = string<br> })</pre> | `null` | no |
| <a name="input_log_analytics_workspace"></a> [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. | <pre>object({<br> id = string<br> name = string<br> })</pre> | `null` | no |
| <a name="input_log_analytics_workspace_enabled"></a> [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 |
| <a name="input_log_analytics_workspace_resource_group_name"></a> [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 |
Expand Down
18 changes: 17 additions & 1 deletion examples/named_cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "../.."

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion locals.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/unit/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit ec677b7

Please sign in to comment.