Skip to content

Commit 79494a6

Browse files
committed
update modulo
1 parent dd5175f commit 79494a6

File tree

3 files changed

+55
-35
lines changed

3 files changed

+55
-35
lines changed

src/aks-platform/10_argocd.tf

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ data "azurerm_key_vault_secret" "argocd_entra_app_client_id" {
1616
key_vault_id = data.azurerm_key_vault.kv_core_ita.id
1717
}
1818

19+
#
20+
# Admin Password
21+
#
22+
data "azurerm_key_vault_secret" "argocd_admin_password" {
23+
key_vault_id = data.azurerm_key_vault.kv_core_ita.id
24+
name = "argocd-admin-password"
25+
}
26+
1927
#
2028
# Setup ArgoCD (module)
2129
#
@@ -27,38 +35,27 @@ module "argocd" {
2735
argocd_application_namespaces = var.argocd_application_namespaces
2836
argocd_force_reinstall_version = var.argocd_force_reinstall_version
2937
tenant_id = data.azurerm_subscription.current.tenant_id
30-
app_client_id = data.azurerm_key_vault_secret.argocd_entra_app_client_id.value
38+
entra_app_client_id = data.azurerm_key_vault_secret.argocd_entra_app_client_id.value
3139
argocd_internal_url = local.argocd_internal_url
32-
kv_core_id = data.azurerm_key_vault.kv_core_ita.id
40+
kv_id = data.azurerm_key_vault.kv_core_ita.id
3341
aks_name = module.aks.name
3442
aks_resource_group_name = azurerm_resource_group.rg_aks.name
3543
workload_identity_resource_group_name = azurerm_resource_group.rg_aks.name
3644
location = var.location
3745
internal_dns_zone_name = data.azurerm_private_dns_zone.internal.name
3846
internal_dns_zone_resource_group_name = local.internal_dns_zone_resource_group_name
3947
ingress_load_balancer_ip = var.ingress_load_balancer_ip
40-
ingress_hostname_prefix = local.ingress_hostname_prefix
48+
dns_record_name_for_ingress = local.ingress_hostname_prefix
4149
admin_password = data.azurerm_key_vault_secret.argocd_admin_password.value
4250

4351
depends_on = [
4452
module.aks,
4553
]
4654
}
4755

48-
#
49-
# Admin Password
50-
#
51-
data "azurerm_key_vault_secret" "argocd_admin_password" {
52-
key_vault_id = data.azurerm_key_vault.kv_core_ita.id
53-
name = "argocd-admin-password"
54-
}
55-
56-
# moved to module
57-
58-
#
56+
#---------------------------------------------------------------
5957
# tools
60-
#
61-
# moved to module
58+
#---------------------------------------------------------------
6259

6360
module "cert_mounter_argocd_internal" {
6461
source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//cert_mounter?ref=v8.77.0"
@@ -88,8 +85,3 @@ resource "helm_release" "reloader_argocd" {
8885
value = "false"
8986
}
9087
}
91-
92-
#
93-
# 🌐 Network
94-
#
95-
# moved to module

src/aks-platform/modules/argocd/main.tf

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
locals {
22
tls_secret_name = coalesce(var.ingress_tls_secret_name, replace(var.argocd_internal_url, ".", "-"))
3+
effective_admin_password = (
4+
var.admin_password != null && var.admin_password != ""
5+
) ? var.admin_password : random_password.argocd_admin_password[0].result
6+
}
7+
8+
resource "random_password" "argocd_admin_password" {
9+
count = var.admin_password == null || var.admin_password == "" ? 1 : 0
10+
length = 28
11+
special = true
12+
min_upper = 1
13+
min_lower = 1
14+
min_numeric = 1
15+
min_special = 1
16+
override_special = "!@#$%*+-=?"
317
}
418

519
resource "helm_release" "argocd" {
@@ -13,7 +27,7 @@ resource "helm_release" "argocd" {
1327
templatefile("${path.root}/src/aks-platform/argocd/argocd_helm_setup_values.yaml", {
1428
ARGOCD_APPLICATION_NAMESPACES = var.argocd_application_namespaces
1529
TENANT_ID = var.tenant_id
16-
APP_CLIENT_ID = var.app_client_id
30+
APP_CLIENT_ID = var.entra_app_client_id
1731
ENTRA_ADMIN_GROUP_OBJECT_IDS = var.entra_admin_group_object_ids
1832
ENTRA_DEVELOPER_GROUP_OBJECT_IDS = var.entra_developer_group_object_ids
1933
ENTRA_READER_GROUP_OBJECT_IDS = var.entra_reader_group_object_ids
@@ -27,26 +41,34 @@ resource "helm_release" "argocd" {
2741

2842
resource "azurerm_key_vault_secret" "argocd_admin_username" {
2943
count = var.enable_store_admin_username ? 1 : 0
30-
key_vault_id = var.kv_core_id
44+
key_vault_id = var.kv_id
3145
name = "argocd-admin-username"
3246
value = "admin"
3347
}
3448

49+
resource "azurerm_key_vault_secret" "argocd_admin_password" {
50+
count = var.enable_store_admin_password ? 1 : 0
51+
key_vault_id = var.kv_id
52+
name = "argocd-admin-password"
53+
value = local.effective_admin_password
54+
}
55+
3556
resource "null_resource" "argocd_change_admin_password" {
3657
count = var.enable_change_admin_password ? 1 : 0
3758

3859
triggers = {
39-
argocd_password = var.admin_password
60+
argocd_password = local.effective_admin_password
4061
force_reinstall = var.argocd_force_reinstall_version
4162
}
4263

4364
provisioner "local-exec" {
44-
command = "kubectl -n ${var.namespace} patch secret argocd-secret -p '{\"stringData\": {\"admin.password\": \"${bcrypt(var.admin_password)}\", \"admin.passwordMtime\": \"'$(date +%FT%T%Z)'\"}}'"
65+
command = "kubectl -n ${var.namespace} patch secret argocd-secret -p '{\"stringData\": {\"admin.password\": \"${bcrypt(local.effective_admin_password)}\", \"admin.passwordMtime\": \"'$(date +%FT%T%Z)'\"}}'"
4566
}
4667

4768
depends_on = [
4869
# Ensure helm release is applied before patching the secret when enabled
4970
helm_release.argocd,
71+
azurerm_key_vault_secret.argocd_admin_password,
5072
]
5173
}
5274

@@ -88,7 +110,7 @@ module "argocd_workload_identity_configuration" {
88110
aks_resource_group_name = var.aks_resource_group_name
89111
namespace = var.namespace
90112

91-
key_vault_id = var.kv_core_id
113+
key_vault_id = var.kv_id
92114
key_vault_certificate_permissions = ["Get"]
93115
key_vault_key_permissions = ["Get"]
94116
key_vault_secret_permissions = ["Get"]
@@ -98,10 +120,9 @@ module "argocd_workload_identity_configuration" {
98120

99121
resource "azurerm_private_dns_a_record" "argocd_ingress" {
100122
count = var.enable_private_dns_a_record ? 1 : 0
101-
name = var.ingress_hostname_prefix
123+
name = var.dns_record_name_for_ingress
102124
zone_name = var.internal_dns_zone_name
103125
resource_group_name = var.internal_dns_zone_resource_group_name
104126
ttl = 3600
105127
records = [var.ingress_load_balancer_ip]
106128
}
107-

src/aks-platform/modules/argocd/variables.tf

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ variable "tenant_id" {
2424
type = string
2525
}
2626

27-
variable "app_client_id" {
27+
variable "entra_app_client_id" {
2828
description = "Workload identity application client id"
2929
type = string
3030
}
@@ -40,8 +40,8 @@ variable "ingress_tls_secret_name" {
4040
default = null
4141
}
4242

43-
variable "kv_core_id" {
44-
description = "Core Key Vault id"
43+
variable "kv_id" {
44+
description = "Key Vault id"
4545
type = string
4646
}
4747

@@ -80,15 +80,23 @@ variable "ingress_load_balancer_ip" {
8080
type = string
8181
}
8282

83-
variable "ingress_hostname_prefix" {
84-
description = "Hostname prefix for the ArgoCD ingress A record"
83+
variable "dns_record_name_for_ingress" {
84+
description = "DNS A record name for the ArgoCD ingress"
8585
type = string
8686
default = "argocd"
8787
}
8888

8989
variable "admin_password" {
90-
description = "Admin password (plain) stored in KV; used to patch ArgoCD secret"
90+
description = "Admin password (plain). If null, a random one is generated."
9191
type = string
92+
default = null
93+
sensitive = true
94+
}
95+
96+
variable "enable_store_admin_password" {
97+
description = "Enable storing of ArgoCD admin password in Key Vault"
98+
type = bool
99+
default = true
92100
}
93101

94102
# Optional Entra group object IDs; default to empty
@@ -158,4 +166,3 @@ variable "enable_private_dns_a_record" {
158166
type = bool
159167
default = true
160168
}
161-

0 commit comments

Comments
 (0)