Skip to content

Commit b2a0351

Browse files
committed
Adjust admin-login module to handle replica
Saves the replica database url to the same secrets so its value can be exposed as env variable when needed.
1 parent b58d985 commit b2a0351

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

rds-postgres/admin-login/main.tf

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@ module "secret" {
88
resource_tags = var.tags
99
trust_tags = var.trust_tags
1010

11-
initial_value = jsonencode({
12-
dbname = var.database_name
13-
engine = data.aws_db_instance.this.engine
14-
host = data.aws_db_instance.this.address
15-
replica_host = data.aws_db_instance.replica.address
16-
password = var.initial_password
17-
port = tostring(data.aws_db_instance.this.port)
18-
username = var.username
19-
})
11+
initial_value = jsonencode(local.initial_secret_value)
2012
}
2113

2214
module "rotation" {
@@ -79,9 +71,22 @@ data "aws_db_instance" "this" {
7971
}
8072

8173
data "aws_db_instance" "replica" {
74+
count = var.replica_identifier ? 1 : 0
75+
8276
db_instance_identifier = var.replica_identifier
8377
}
8478

8579
locals {
8680
full_name = join("-", ["rds-postgres", var.identifier])
81+
82+
base_value = {
83+
dbname = var.database_name
84+
engine = data.aws_db_instance.this.engine
85+
host = data.aws_db_instance.this.address
86+
password = var.initial_password
87+
port = tostring(data.aws_db_instance.this.port)
88+
username = var.username
89+
}
90+
91+
initial_secret_value = var.replica_identifier ? local.base_value : merge(locals.base_value, { replica_host = data.aws_db_instance.replica.address })
8792
}

rds-postgres/admin-login/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ variable "read_principals" {
3434
variable "replica_identifier" {
3535
description = "Identifier of the database replica"
3636
type = string
37+
<<<<<<< HEAD
38+
=======
39+
default = null
40+
>>>>>>> 0940a0b (Adjust admin-login module to handle replica)
3741
}
3842
3943
variable "secret_name" {

0 commit comments

Comments
 (0)