Skip to content

Commit 1351da5

Browse files
Add Conditional Support for System Assigned Identity and Service Principal in AKS Module (#15)
* DEVOPS-292 data file * DEVOPS-301 added plan files to gitignore * DEVOPS-292 kubernetes terraform code * DEVOPS-300 output tf code * DEVOPS-300 providers and variables tf code * Update terraform tf files DEVOPS-301 DEVOPS-302 * remove role assignment resource block * DEVOPS-301 added dynamic block for using sp or identity
1 parent 7e529a8 commit 1351da5

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

kubernetes-cluster/kubernetes.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,19 @@ resource "azurerm_kubernetes_cluster" "aks_cluster" {
3838
dns_service_ip = cidrhost((var.service_cidr_subnet), 5) # 5th ip on service cidr subnet
3939
}
4040

41-
service_principal {
42-
client_id = data.azurerm_key_vault_secret.appid.value
43-
client_secret = data.azurerm_key_vault_secret.secret.value
41+
dynamic "identity" {
42+
for_each = var.authentication_method == "identity" ? [1] : []
43+
content {
44+
type = "SystemAssigned"
45+
}
46+
}
47+
48+
dynamic "service_principal" {
49+
for_each = var.authentication_method == "service_principal" ? [1] : []
50+
content {
51+
client_id = data.azurerm_key_vault_secret.appid.value
52+
client_secret = data.azurerm_key_vault_secret.secret.value
53+
}
4454
}
4555

4656
workload_identity_enabled = var.workload_identity_enabled

kubernetes-cluster/variables.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,14 @@ variable "kubernetes_version" {
343343
condition = can(regex("^[0-9]+\\.[0-9]+\\.[0-9]+$", var.kubernetes_version))
344344
error_message = "The version must be in the format 'major.minor.patch', where major, minor, and patch are non-negative integers."
345345
}
346-
}
346+
}
347+
348+
variable "authentication_method" {
349+
description = "Specify 'identity' to use SystemAssigned identity or 'service_principal' to use service principal"
350+
type = string
351+
default = ""
352+
validation {
353+
condition = contains(["identity", "service_principal"], var.authentication_method)
354+
error_message = "This Value should be either identity or service_principal."
355+
}
356+
}

0 commit comments

Comments
 (0)