Skip to content

Commit 665280f

Browse files
update password functionality
1 parent 3af719c commit 665280f

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed

examples/complete/aws/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
locals {
2-
name = ""
3-
region = ""
2+
name = "test"
3+
region = "us-east-1"
44
environment = ""
55
additional_tags = {
66
Owner = "organization_name"
77
Expires = "Never"
88
Department = "Engineering"
99
}
1010
}
11-
1211
module "sonarqube" {
1312
source = "squareops/sonarqube/kubernetes"
1413
version = "3.1.1"
@@ -22,10 +21,11 @@ module "sonarqube" {
2221
monitoringPasscode = ""
2322
postgresql_password_external = ""
2423
postgresql_external_server_url = ""
25-
sonarqube_password = ""
24+
sonarqube_password = "xxxxx"
2625

2726
updateExistingSonarqube = false # if you have existing sonarqube and want to upgrade,then enable it.
28-
sonarqube_current_password = "xxxxx" # if you upgrade sonarqube then you have to provide your previous sonarqube password ##Secret name=sonarqube-postgresql
27+
updateExistingSonarqubePassword = false #if you want ti update password,enable it and pass sonarqube_current_password(old),sonarqube_password(new)
28+
sonarqube_current_password = "xxxxxx" # if you upgrade sonarqube then you have to provide your previous sonarqube password ##Secret name=sonarqube-postgresql
2929
postgresql_current_password = "xxxxxxx" # if you upgrade sonarqube then you have to provide your previous postgresql password ##Secret name=sonarqube-sonarqube-admin-password
3030
}
3131
}

examples/complete/aws/provider.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ provider "aws" {
66
}
77

88
data "aws_eks_cluster" "cluster" {
9-
name = ""
9+
name = "test-divyanshu"
1010
}
1111

1212
data "aws_eks_cluster_auth" "cluster" {
13-
name = ""
13+
name = "test-divyanshu"
1414
}
1515

1616

main.tf

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
locals {
22
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
37
}
48
resource "random_password" "sonarqube_password" {
59
length = 20
@@ -34,9 +38,9 @@ resource "helm_release" "sonarqube" {
3438
volume_size = var.sonarqube_config.sonarqube_volume_size
3539
sonarqube_sc = var.sonarqube_config.storage_class_name
3640
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
3842
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
4044
postgresql_disk_size = var.sonarqube_config.postgresql_volume_size
4145
prometheus_exporter_enable = var.sonarqube_config.grafana_monitoring_enabled
4246
postgresql_external_server_url = var.sonarqube_config.postgresql_external_server_url
@@ -96,3 +100,47 @@ resource "kubernetes_manifest" "migration_job" {
96100
}
97101
}
98102
}
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+

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ output "sonarqube" {
22
description = "Sonarqube Credentials "
33
value = {
44
username = "admin",
5-
password = nonsensitive(random_password.sonarqube_password.result),
5+
password = nonsensitive(local.effective_sonarqube_password),
66
url = var.sonarqube_config.hostname
77
}
88
}
99

1010
output "sonarqube_postgresql_password" {
11-
value = random_password.postgresql_password.result
11+
value = nonsensitive(local.effective_postgresql_password)
1212
description = "Password for the PostgreSQL database deployed with SonarQube"
1313
sensitive = true
1414
}

0 commit comments

Comments
 (0)