Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conditional use balancer public ip and create role assignment on … #356

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion modules/azure-aks/aks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module "aks" {
key_vault_secrets_provider_enabled = var.key_vault_secrets_provider_enabled
kubernetes_version = var.aks_kubernetes_version
load_balancer_profile_enabled = var.load_balancer_profile_enabled
load_balancer_profile_outbound_ip_address_ids = [data.azurerm_public_ip.aks_public_ip.id]
load_balancer_profile_outbound_ip_address_ids = var.load_balancer_profile_outbound_ip_address_enabled ? [for ip in data.azurerm_public_ip.aks_public_ip : ip.id] : null
load_balancer_sku = var.load_balancer_sku
log_analytics_workspace_enabled = false
network_contributor_role_assigned_subnet_ids = { aks_subnet = data.azurerm_subnet.aks_subnet.id }
Expand Down
1 change: 1 addition & 0 deletions modules/azure-aks/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data "azurerm_subnet" "aks_subnet" {

# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/public_ip
data "azurerm_public_ip" "aks_public_ip" {
count = var.load_balancer_profile_outbound_ip_address_enabled ? 1 : 0
name = var.public_ip_name
resource_group_name = var.resource_group_name
}
2 changes: 1 addition & 1 deletion modules/azure-aks/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ output "oidc_issuer_url" {
}

output "outbound_ip_address" {
value = data.azurerm_public_ip.aks_public_ip.id
value = data.azurerm_public_ip.aks_public_ip[0].id
}

# Data section
Expand Down
4 changes: 2 additions & 2 deletions modules/azure-aks/role_assignment.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment
resource "azurerm_role_assignment" "role_assignment_network_contributor_over_public_ip_aks" {
count = var.create_role_assignment_public_ip ? 1 : 0
scope = data.azurerm_public_ip.aks_public_ip.id
count = var.load_balancer_profile_outbound_ip_address_enabled ? 1 : 0
scope = data.azurerm_public_ip.aks_public_ip[count.index].id
role_definition_name = "Network Contributor"
principal_id = module.aks.cluster_identity.principal_id
}
13 changes: 6 additions & 7 deletions modules/azure-aks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ variable "load_balancer_sku" {
default = "standard"
}

variable "load_balancer_profile_outbound_ip_address_enabled" {
description = "Boolean value to enable or not the load balancer profile outbound ip address"
type = bool
default = false
}

variable "node_os_channel_upgrade" {
description = "The automatic node channel upgrade setting for the AKS cluster"
default = "None"
Expand Down Expand Up @@ -268,10 +274,3 @@ variable "api_server_authorized_ip_ranges" {
type = list(string)
default = null
}

# Role assignment for public IP
variable "create_role_assignment_public_ip" {
description = "Boolean value to create a role assignment for the public IP"
type = bool
default = false
}