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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,18 @@ The following sections are generated by [terraform-docs](https://github.com/terr
| Name | Version |
|---------------------------------------------------------------------------|------------------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_azapi"></a> [azapi](#requirement\_azapi) | >= 1.4.0, < 2.0 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | >= 3.51.0, < 4.0 |
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.0 |
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 3.1 |

## Providers

| Name | Version |
|---------------------------------------------------------------|------------------|
| <a name="provider_azapi"></a> [azapi](#provider\_azapi) | >= 1.4.0, < 2.0 |
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | >= 3.51.0, < 4.0 |
| <a name="provider_null"></a> [null](#provider\_null) | >= 3.0 |
| <a name="provider_tls"></a> [tls](#provider\_tls) | >= 3.1 |

## Modules
Expand All @@ -260,12 +264,14 @@ No modules.

| Name | Type |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
| [azapi_update_resource.aks_cluster_post_create](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/update_resource) | resource |
| [azurerm_kubernetes_cluster.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster) | resource |
| [azurerm_kubernetes_cluster_node_pool.node_pool](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster_node_pool) | resource |
| [azurerm_log_analytics_solution.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_solution) | resource |
| [azurerm_log_analytics_workspace.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_workspace) | resource |
| [azurerm_role_assignment.acr](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
| [azurerm_role_assignment.network_contributor](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
| [null_resource.kubernetes_version_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_resource_group.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |

Expand Down
25 changes: 25 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ resource "azurerm_kubernetes_cluster" "main" {
}

lifecycle {
ignore_changes = [kubernetes_version]

precondition {
condition = (var.client_id != "" && var.client_secret != "") || (var.identity_type != "")
error_message = "Either `client_id` and `client_secret` or `identity_type` must be set."
Expand Down Expand Up @@ -399,6 +401,27 @@ resource "azurerm_kubernetes_cluster" "main" {
}
}

resource "null_resource" "kubernetes_version_keeper" {
triggers = {
version = var.kubernetes_version
}
}

resource "azapi_update_resource" "aks_cluster_post_create" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So an update of AKS would be done through this resource rather than the actual cluster resource?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@the-technat yes, since in this approach we rely on null_resource's replacement to trigger the update, we cannot execute the update via azurerm resource since the whole resource would be re-created, so it must be a virtual resource like azapi_update_resource.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@the-technat So we're currently upgrading our AKS module from 6.2.0 --> 7.2.0. We're getting a module.aks.azapi_update_resource.aks_cluster_post_create to be added. Can you please make me understand what is the purpose the resource created and is it safe to apply? Will the future updates of AKS take place through the created resource? Also we don't have azapi provider in our code is it necessary to add? Thanks.

type = "Microsoft.ContainerService/managedClusters@2023-01-02-preview"
body = jsonencode({
properties = {
kubernetesVersion = var.kubernetes_version
}
})
resource_id = azurerm_kubernetes_cluster.main.id

lifecycle {
ignore_changes = all
replace_triggered_by = [null_resource.kubernetes_version_keeper.id]
}
}

resource "azurerm_kubernetes_cluster_node_pool" "node_pool" {
for_each = var.node_pools

Expand Down Expand Up @@ -522,6 +545,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "node_pool" {
}
}

depends_on = [azapi_update_resource.aks_cluster_post_create]

lifecycle {
precondition {
condition = var.agents_type == "VirtualMachineScaleSets"
Expand Down
8 changes: 8 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ terraform {
required_version = ">= 1.3"

required_providers {
azapi = {
source = "Azure/azapi"
version = ">= 1.4.0, < 2.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.51.0, < 4.0"
}
null = {
source = "hashicorp/null"
version = ">= 3.0"
}
tls = {
source = "hashicorp/tls"
version = ">= 3.1"
Expand Down