Skip to content

Commit

Permalink
kubelogin arguments for Github actions OIDC
Browse files Browse the repository at this point in the history
Required for configuring the kubernetes provider when running in a
workflow where OIDC is enabled
  • Loading branch information
saliceti committed Dec 19, 2024
1 parent 440927a commit fcf2292
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion aks/cluster_data/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ output "ingress_domain" {
}

output "kubelogin_args" {
value = local.spn_authentication ? local.kubelogin_args_map["spn"] : local.kubelogin_args_map["azurecli"]
description = "Kubelogin arguments to use configure the kubernetes provider. Allows workload identity, service principal secret and azure cli"
# If running in github actions, use either spn secret authentication or workload identity. If not, use azure cli.
value = (local.running_in_github_actions ? (
local.spn_secret_authentication ?
local.kubelogin_args_map["spn"] :
local.kubelogin_args_map["workloadidentity"]
) :
local.kubelogin_args_map["azurecli"]
)
}
output "azure_RBAC_enabled" {
value = local.azure_RBAC_enabled
Expand Down
2 changes: 1 addition & 1 deletion aks/cluster_data/tfdocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ No modules.
| <a name="output_azure_RBAC_enabled"></a> [azure\_RBAC\_enabled](#output\_azure\_RBAC\_enabled) | n/a |
| <a name="output_configuration_map"></a> [configuration\_map](#output\_configuration\_map) | n/a |
| <a name="output_ingress_domain"></a> [ingress\_domain](#output\_ingress\_domain) | n/a |
| <a name="output_kubelogin_args"></a> [kubelogin\_args](#output\_kubelogin\_args) | n/a |
| <a name="output_kubelogin_args"></a> [kubelogin\_args](#output\_kubelogin\_args) | Kubelogin arguments to use configure the kubernetes provider. Allows workload identity, service principal secret and azure cli |
| <a name="output_kubernetes_client_certificate"></a> [kubernetes\_client\_certificate](#output\_kubernetes\_client\_certificate) | n/a |
| <a name="output_kubernetes_client_key"></a> [kubernetes\_client\_key](#output\_kubernetes\_client\_key) | n/a |
| <a name="output_kubernetes_cluster_ca_certificate"></a> [kubernetes\_cluster\_ca\_certificate](#output\_kubernetes\_cluster\_ca\_certificate) | n/a |
Expand Down
10 changes: 9 additions & 1 deletion aks/cluster_data/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,18 @@ locals {
"azurecli",
"--server-id",
"6dae42f8-4368-4678-94ff-3960e28e3630"
],
workloadidentity = [
"get-token",
"--login",
"workloadidentity",
"--server-id",
"6dae42f8-4368-4678-94ff-3960e28e3630"
]
}

azure_RBAC_enabled = length(data.azurerm_kubernetes_cluster.main.azure_active_directory_role_based_access_control) > 0

spn_authentication = contains(keys(data.environment_variables.github_actions.items), "GITHUB_ACTIONS")
running_in_github_actions = contains(keys(data.environment_variables.github_actions.items), "GITHUB_ACTIONS")
spn_secret_authentication = contains(keys(data.environment_variables.github_actions.items), "AAD_SERVICE_PRINCIPAL_CLIENT_SECRET")
}

0 comments on commit fcf2292

Please sign in to comment.