Skip to content

Commit

Permalink
Add Conditional Support for System Assigned Identity and Service Prin…
Browse files Browse the repository at this point in the history
…cipal 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
  • Loading branch information
githubofkrishnadhas authored Dec 28, 2024
1 parent 7e529a8 commit 1351da5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
16 changes: 13 additions & 3 deletions kubernetes-cluster/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ resource "azurerm_kubernetes_cluster" "aks_cluster" {
dns_service_ip = cidrhost((var.service_cidr_subnet), 5) # 5th ip on service cidr subnet
}

service_principal {
client_id = data.azurerm_key_vault_secret.appid.value
client_secret = data.azurerm_key_vault_secret.secret.value
dynamic "identity" {
for_each = var.authentication_method == "identity" ? [1] : []
content {
type = "SystemAssigned"
}
}

dynamic "service_principal" {
for_each = var.authentication_method == "service_principal" ? [1] : []
content {
client_id = data.azurerm_key_vault_secret.appid.value
client_secret = data.azurerm_key_vault_secret.secret.value
}
}

workload_identity_enabled = var.workload_identity_enabled
Expand Down
12 changes: 11 additions & 1 deletion kubernetes-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,14 @@ variable "kubernetes_version" {
condition = can(regex("^[0-9]+\\.[0-9]+\\.[0-9]+$", var.kubernetes_version))
error_message = "The version must be in the format 'major.minor.patch', where major, minor, and patch are non-negative integers."
}
}
}

variable "authentication_method" {
description = "Specify 'identity' to use SystemAssigned identity or 'service_principal' to use service principal"
type = string
default = ""
validation {
condition = contains(["identity", "service_principal"], var.authentication_method)
error_message = "This Value should be either identity or service_principal."
}
}

0 comments on commit 1351da5

Please sign in to comment.