Skip to content

Commit b1fdae8

Browse files
lonegunmanbCopilot
andauthored
feat: add check block to warn about blob CSI driver subnet drift (fixes #424) (#743)
When storage_profile_blob_driver_enabled is true, the AKS Blob CSI driver may automatically add a Microsoft.Storage service endpoint to the subnet out-of-band, causing Terraform state drift. This adds a check block that warns users to proactively declare the service endpoint on their subnet. The check block uses a conditional data.azurerm_subnet lookup and only triggers when storage_profile_enabled, storage_profile_blob_driver_enabled are both true and vnet_subnet is provided. It produces a warning (not an error), so it is non-breaking. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent cd23d4e commit b1fdae8

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,21 @@ resource "azurerm_kubernetes_cluster" "main" {
735735
}
736736
}
737737

738+
data "azurerm_subnet" "blob_driver_check" {
739+
count = (var.storage_profile_enabled && var.storage_profile_blob_driver_enabled && var.vnet_subnet != null) ? 1 : 0
740+
741+
name = local.default_nodepool_subnet_segments[10]
742+
virtual_network_name = local.default_nodepool_subnet_segments[8]
743+
resource_group_name = local.default_nodepool_subnet_segments[4]
744+
}
745+
746+
check "blob_driver_subnet_service_endpoint" {
747+
assert {
748+
condition = var.vnet_subnet == null || !var.storage_profile_enabled || !var.storage_profile_blob_driver_enabled || contains(try(data.azurerm_subnet.blob_driver_check[0].service_endpoints, []), "Microsoft.Storage")
749+
error_message = "The subnet used by the default node pool does not have 'Microsoft.Storage' in its service_endpoints. When storage_profile_blob_driver_enabled is true, the AKS Blob CSI driver may automatically add this service endpoint out-of-band, causing Terraform state drift. To prevent this, add service_endpoints = [\"Microsoft.Storage\"] to your subnet configuration. See: https://github.com/Azure/terraform-azurerm-aks/issues/424"
750+
}
751+
}
752+
738753
resource "null_resource" "kubernetes_cluster_name_keeper" {
739754
triggers = {
740755
name = local.cluster_name

0 commit comments

Comments
 (0)