|
1 | 1 | locals { |
2 | 2 | count = var.sonarqube_config.postgresql_external_server_url != "" ? [] : [1] |
| 3 | + |
| 4 | + effective_sonarqube_password = var.sonarqube_config.sonarqube_password != "" ? var.sonarqube_config.sonarqube_password : random_password.sonarqube_password.result |
| 5 | + |
| 6 | + effective_postgresql_password = var.sonarqube_config.postgresql_current_password != "" && var.sonarqube_config.updateExistingSonarqube == true ? var.sonarqube_config.postgresql_current_password : random_password.postgresql_password.result |
3 | 7 | } |
4 | 8 | resource "random_password" "sonarqube_password" { |
5 | 9 | length = 20 |
@@ -34,9 +38,9 @@ resource "helm_release" "sonarqube" { |
34 | 38 | volume_size = var.sonarqube_config.sonarqube_volume_size |
35 | 39 | sonarqube_sc = var.sonarqube_config.storage_class_name |
36 | 40 | postgresql_enable = var.sonarqube_config.postgresql_external_server_url != "" ? false : true |
37 | | - sonarqube_password = var.sonarqube_config.sonarqube_password != "" ? var.sonarqube_config.sonarqube_password : random_password.sonarqube_password.result |
| 41 | + sonarqube_password = local.effective_sonarqube_password |
38 | 42 | sonarqube_current_password = var.sonarqube_config.updateExistingSonarqube == true ? var.sonarqube_config.sonarqube_current_password : "admin" |
39 | | - postgresql_password = var.sonarqube_config.postgresql_current_password != "" && var.sonarqube_config.updateExistingSonarqube == true ? var.sonarqube_config.postgresql_current_password : random_password.postgresql_password.result |
| 43 | + postgresql_password = local.effective_postgresql_password |
40 | 44 | postgresql_disk_size = var.sonarqube_config.postgresql_volume_size |
41 | 45 | prometheus_exporter_enable = var.sonarqube_config.grafana_monitoring_enabled |
42 | 46 | postgresql_external_server_url = var.sonarqube_config.postgresql_external_server_url |
@@ -96,3 +100,47 @@ resource "kubernetes_manifest" "migration_job" { |
96 | 100 | } |
97 | 101 | } |
98 | 102 | } |
| 103 | + |
| 104 | + |
| 105 | +resource "kubernetes_manifest" "sonarqube_password_reset_job" { |
| 106 | + count = var.sonarqube_config.updateExistingSonarqubePassword ? 1 : 0 |
| 107 | + |
| 108 | + manifest = { |
| 109 | + apiVersion = "batch/v1" |
| 110 | + kind = "Job" |
| 111 | + metadata = { |
| 112 | + name = "sonarqube-password-reset" |
| 113 | + namespace = "sonarqube" |
| 114 | + } |
| 115 | + spec = { |
| 116 | + backoffLimit = 4 |
| 117 | + completions = 1 |
| 118 | + parallelism = 1 |
| 119 | + ttlSecondsAfterFinished: 60 |
| 120 | + template = { |
| 121 | + spec = { |
| 122 | + restartPolicy = "Never" |
| 123 | + containers = [ |
| 124 | + { |
| 125 | + name = "password-reset" |
| 126 | + image = "curlimages/curl:8.5.0" |
| 127 | + command = [ |
| 128 | + "sh", "-c", <<-EOT |
| 129 | + echo "Resetting SonarQube admin password..." && |
| 130 | + curl -s -X POST -u admin:"${var.sonarqube_config.sonarqube_current_password}" \ |
| 131 | + "http://sonarqube-sonarqube:9000/api/users/change_password" \ |
| 132 | + --data-urlencode "login=admin" \ |
| 133 | + --data-urlencode "previousPassword=${var.sonarqube_config.sonarqube_current_password}" \ |
| 134 | + --data-urlencode "password=${var.sonarqube_config.sonarqube_password}" \ |
| 135 | + -w "%%{http_code}" -o /dev/null |
| 136 | + echo "Password change complete." |
| 137 | + EOT |
| 138 | + ] |
| 139 | + } |
| 140 | + ] |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | +} |
| 146 | + |
0 commit comments