Skip to content

Commit 13339ea

Browse files
authored
Merge pull request #50 from datafold/gerard-p-3769-better-password-retrieval-management
fix: Disaster Recovery issues
2 parents 58d295e + 6e77174 commit 13339ea

File tree

11 files changed

+92
-15
lines changed

11 files changed

+92
-15
lines changed

main.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ module "load_balancer" {
7474
lb_access_logs = var.lb_access_logs
7575
lb_deploy_nlb = var.lb_deploy_nlb
7676
lb_vpces_details = var.lb_vpces_details
77+
initial_apply_complete = var.initial_apply_complete
7778

7879
vpces_security_group_id = local.vpces_sec_group_id
7980
}
@@ -195,6 +196,7 @@ module "database" {
195196
provider_region = var.provider_region
196197
vpc_private_subnets = local.vpc_private_subnets
197198
rds_username = var.rds_username
199+
rds_password_override = var.rds_password_override
198200
rds_instance = var.rds_instance
199201
rds_allocated_storage = var.rds_allocated_storage
200202
rds_max_allocated_storage = var.rds_max_allocated_storage
@@ -223,6 +225,7 @@ module "database" {
223225
rds_copy_tags_to_snapshot = var.rds_copy_tags_to_snapshot
224226
rds_performance_insights_enabled = var.rds_performance_insights_enabled
225227
rds_performance_insights_retention_period= var.rds_performance_insights_retention_period
228+
rds_monitoring_role_arn = var.rds_monitoring_role_arn
226229
rds_auto_minor_version_upgrade = var.rds_auto_minor_version_upgrade
227230
rds_monitoring_interval = var.rds_monitoring_interval
228231
}
@@ -340,3 +343,30 @@ module "vpc_peering" {
340343
vpc_private_route_table_id = module.networking.vpc_private_route_table_id
341344
vpc_public_route_table_id = module.networking.vpc_public_route_table_id
342345
}
346+
347+
resource "null_resource" "deployment_check" {
348+
triggers = {
349+
initial_apply_complete = var.initial_apply_complete
350+
}
351+
352+
provisioner "local-exec" {
353+
command = <<-EOT
354+
# Get the load balancer IPs value
355+
LB_IPS="${module.load_balancer.load_balancer_ips}"
356+
357+
echo $LB_IPS
358+
359+
# Check if it's empty, null, or just "[]"
360+
if [ -z "$LB_IPS" ] || [ "$LB_IPS" = "[]" ] || [ "$LB_IPS" = "[\"\"]" ]|| [ "$LB_IPS" = "null" ]; then
361+
echo "\n\nERROR: Initial deployment complete. Set 'initial_apply_complete = true' to resolve load balancer IP dependencies.\n\n"
362+
exit 1
363+
fi
364+
EOT
365+
interpreter = ["/bin/bash", "-c"]
366+
quiet = true
367+
}
368+
369+
depends_on = [
370+
module.load_balancer
371+
]
372+
}

modules/clickhouse_backup/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "clickhouse_backup" {
2020
expiration {
2121
days = 14
2222
}
23+
filter {}
2324
status = "Enabled"
2425
}
2526
}

modules/database/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module "db" {
3737
db_name = var.database_name
3838
username = var.rds_username
3939
manage_master_user_password = false
40-
password = random_password.rds_master_password.result
40+
password = local.rds_password
4141
port = var.rds_port
4242
copy_tags_to_snapshot = var.rds_copy_tags_to_snapshot
4343

@@ -68,6 +68,7 @@ module "db" {
6868

6969
performance_insights_enabled = var.rds_performance_insights_enabled
7070
create_monitoring_role = false
71+
monitoring_role_arn = var.rds_monitoring_role_arn
7172
monitoring_interval = var.rds_monitoring_interval
7273

7374
performance_insights_retention_period = var.rds_performance_insights_retention_period
@@ -101,7 +102,9 @@ module "db" {
101102

102103
locals {
103104
log_rds_automated_backups_replication_path = "${path.module}/../../logs/rds_automated_backups_replication.log"
105+
rds_password = var.rds_password_override != null ? var.rds_password_override : random_password.rds_master_password.result
104106
}
107+
105108
# https://docs.aws.amazon.com/cli/latest/reference/rds/start-db-instance-automated-backups-replication.html
106109
resource "null_resource" "rds-automated-backups-replication" {
107110
count = var.rds_backups_replication_target_region != null ? 1 : 0

modules/database/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ output "postgres_username" {
77
}
88

99
output "postgres_password" {
10-
value = random_password.rds_master_password.result
10+
value = local.rds_password
1111
}
1212

1313
output "postgres_database_name" {

modules/database/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ variable "rds_username" {
3434
description = "RDS username"
3535
}
3636

37+
variable "rds_password_override" {
38+
type = string
39+
default = null
40+
description = "Password override"
41+
}
42+
3743
variable "rds_instance" {
3844
type = string
3945
default = "db.t3.medium"
@@ -200,6 +206,12 @@ variable "rds_performance_insights_retention_period" {
200206
description = "RDS performance insights retention period"
201207
}
202208

209+
variable "rds_monitoring_role_arn" {
210+
type = string
211+
description = "The IAM role allowed to send RDS metrics to cloudwatch"
212+
default = null
213+
}
214+
203215
variable "rds_auto_minor_version_upgrade" {
204216
type = bool
205217
default = false

modules/eks/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module "eks" {
4747
# https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/docs
4848

4949
source = "terraform-aws-modules/eks/aws"
50-
version = "~> 20.13.1"
50+
version = "~> 20.35.0"
5151
# version = var.eks_module_version
5252

5353
cluster_name = var.deployment_name

modules/load_balancer/main.tf

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ data "aws_acm_certificate" "alb" {
2828
# https://registry.terraform.io/modules/terraform-aws-modules/alb/aws/latest
2929
module "alb_app" {
3030
source = "terraform-aws-modules/alb/aws"
31-
version = "~> 6.2.0"
31+
version = "~> 8.7.0"
3232

3333
name = var.lb_name_override == "" ? "${var.deployment_name}-app" : var.lb_name_override
3434

@@ -109,22 +109,29 @@ locals {
109109
vpc_subnets_joined = join(",", var.vpc_subnets)
110110
}
111111

112-
data "aws_network_interfaces" "lb_app" {
112+
data "aws_network_interface" "lb_app" {
113+
count = var.initial_apply_complete ? length(var.vpc_subnets) : 0
114+
113115
filter {
114-
name = "description"
116+
name = "description"
115117
values = ["ELB ${module.alb_app.lb_arn_suffix}"]
116118
}
117119

118-
depends_on = [ module.alb_app ]
119-
}
120+
filter {
121+
name = "subnet-id"
122+
values = [var.vpc_subnets[count.index]]
123+
}
120124

121-
data "aws_network_interface" "lb_app" {
122-
count = length(data.aws_network_interfaces.lb_app.ids)
123-
id = data.aws_network_interfaces.lb_app.ids[count.index]
125+
depends_on = [ module.alb_app ]
124126
}
125127

126128
locals {
127-
lb_ips = var.lb_internal ? jsonencode([for eni in data.aws_network_interface.lb_app : format("%s", eni.private_ip)]) : jsonencode([for eni in data.aws_network_interface.lb_app : format("%s", eni.association[0].public_ip)])
129+
lb_ips = jsonencode(var.initial_apply_complete ? (
130+
var.lb_internal ?
131+
[for eni in data.aws_network_interface.lb_app : format("%s", eni.private_ip)] :
132+
[for eni in data.aws_network_interface.lb_app : format("%s", eni.association[0].public_ip)]
133+
) : [""]
134+
)
128135
}
129136

130137
resource "aws_lb_target_group" "nlb_alb_target" {

modules/load_balancer/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,10 @@ variable "lb_vpces_details" {
110110
supported_ip_address_types = list(string)
111111
})
112112
description = "Endpoint service to define for internal traffic over private link"
113-
}
113+
}
114+
115+
variable "initial_apply_complete" {
116+
type = bool
117+
default = false
118+
description = "Indicates if this infra is deployed or not. Helps to resolve dependencies."
119+
}

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,4 @@ output "storage_worker_role_arn" {
286286
output "storage_worker_service_account_name" {
287287
value = module.eks.storage_worker_service_account_name
288288
description = "The name of the service account for storage_worker"
289-
}
289+
}

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ variable "private_subnet_index" {
104104
description = "Index of the private subnet"
105105
}
106106

107+
variable "initial_apply_complete" {
108+
type = bool
109+
default = false
110+
description = "Indicates if this infra is deployed or not. Helps to resolve dependencies."
111+
}
112+
107113
# ┏━┓┏━┓┏━┓╻ ╻╻╺┳┓┏━╸┏━┓
108114
# ┣━┛┣┳┛┃ ┃┃┏┛┃ ┃┃┣╸ ┣┳┛
109115
# ╹ ╹┗╸┗━┛┗┛ ╹╺┻┛┗━╸╹┗╸
@@ -403,6 +409,12 @@ variable "rds_username" {
403409
description = "Overrides the default RDS user name that is provisioned."
404410
}
405411

412+
variable "rds_password_override" {
413+
type = string
414+
default = null
415+
description = "Password override"
416+
}
417+
406418
variable "rds_identifier" {
407419
type = string
408420
default = ""
@@ -537,6 +549,12 @@ variable "rds_performance_insights_enabled" {
537549
description = "RDS performance insights enabled or not"
538550
}
539551

552+
variable "rds_monitoring_role_arn" {
553+
type = string
554+
description = "The IAM role allowed to send RDS metrics to cloudwatch"
555+
default = null
556+
}
557+
540558
variable "db_extra_parameters" {
541559
type = list
542560
default = []

0 commit comments

Comments
 (0)