Skip to content

Commit 401064a

Browse files
committed
infra(agg_mode): add gateway servers
infra: modularize code
1 parent 0175088 commit 401064a

File tree

8 files changed

+374
-117
lines changed

8 files changed

+374
-117
lines changed

infra/aggregation_mode/terraform/cloudinit/scaleway-cloud-init.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ packages:
3333
- htop
3434
- rsync
3535
- pkg-config
36+
- locales
37+
38+
write_files:
39+
- path: /etc/environment
40+
content: |
41+
LANG=en_US.UTF-8
42+
LC_ALL=C
43+
LANGUAGE=en_US.UTF-8
44+
LC_TYPE=en_US.UTF-8
45+
LC_CTYPE=en_US.UTF-8
3646
3747
runcmd:
3848
- loginctl enable-linger app

infra/aggregation_mode/terraform/environments/hoodi/main.tf

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ provider "tailscale" {
1515
module "postgres_monitor" {
1616
source = "../../modules/ec2"
1717

18-
ec2_instance_name = var.monitor_instance_name
19-
ec2_hostname = var.monitor_hostname
20-
ec2_instance_type = var.monitor_instance_type
21-
ec2_ssh_key_name = var.monitor_ssh_key_name
18+
ec2_instance_name = var.postgres_monitor_instance_name
19+
ec2_hostname = var.postgres_monitor_hostname
20+
ec2_instance_type = var.postgres_monitor_instance_type
21+
ec2_ssh_key_name = var.postgres_monitor_ssh_key_name
2222
ec2_ssh_public_key_path = var.ssh_public_key_path_aws
23-
ec2_cloud_init_template_path = var.monitor_cloud_init_template_path
24-
ec2_root_volume_size = var.monitor_root_volume_size
23+
ec2_cloud_init_template_path = var.postgres_monitor_cloud_init_template_path
24+
ec2_root_volume_size = var.postgres_monitor_root_volume_size
2525
ec2_tailscale_key_expiry = var.tailscale_key_expiry
2626
ec2_tailscale_tags = var.tailscale_tags
2727

@@ -32,36 +32,74 @@ module "postgres_monitor" {
3232
module "postgres_primary" {
3333
source = "../../modules/elastic_metal"
3434

35-
elastic_metal_zone = var.primary_zone
36-
elastic_metal_offer_name = var.primary_offer_name
35+
elastic_metal_zone = var.postgres_primary_zone
36+
elastic_metal_offer_name = var.postgres_primary_offer_name
3737
elastic_metal_subscription_period = var.subscription_period
38-
elastic_metal_server_name = var.primary_server_name
39-
elastic_metal_hostname = var.primary_hostname
40-
elastic_metal_description = var.primary_description
41-
elastic_metal_ssh_key_name = var.primary_ssh_key_name
38+
elastic_metal_server_name = var.postgres_primary_server_name
39+
elastic_metal_hostname = var.postgres_primary_hostname
40+
elastic_metal_description = var.postgres_primary_description
41+
elastic_metal_ssh_key_name = var.postgres_primary_ssh_key_name
4242
elastic_metal_ssh_public_key_path = var.ssh_public_key_path_scaleway
43-
elastic_metal_cloud_init_template_path = var.primary_cloud_init_template_path
43+
elastic_metal_cloud_init_template_path = var.postgres_primary_cloud_init_template_path
4444
elastic_metal_os_id = var.os_id
4545
elastic_metal_tailscale_key_expiry = var.tailscale_key_expiry
4646
elastic_metal_tailscale_tags = var.tailscale_tags
47-
elastic_metal_tags = var.primary_tags
47+
elastic_metal_tags = var.postgres_primary_tags
4848
}
4949

5050
# Postgres Secondary (Elastic Metal / Scaleway Bare Metal)
5151
module "postgres_secondary" {
5252
source = "../../modules/elastic_metal"
5353

54-
elastic_metal_zone = var.secondary_zone
55-
elastic_metal_offer_name = var.secondary_offer_name
54+
elastic_metal_zone = var.postgres_secondary_zone
55+
elastic_metal_offer_name = var.postgres_secondary_offer_name
5656
elastic_metal_subscription_period = var.subscription_period
57-
elastic_metal_server_name = var.secondary_server_name
58-
elastic_metal_hostname = var.secondary_hostname
59-
elastic_metal_description = var.secondary_description
60-
elastic_metal_ssh_key_name = var.secondary_ssh_key_name
57+
elastic_metal_server_name = var.postgres_secondary_server_name
58+
elastic_metal_hostname = var.postgres_secondary_hostname
59+
elastic_metal_description = var.postgres_secondary_description
60+
elastic_metal_ssh_key_name = var.postgres_secondary_ssh_key_name
6161
elastic_metal_ssh_public_key_path = var.ssh_public_key_path_scaleway
62-
elastic_metal_cloud_init_template_path = var.secondary_cloud_init_template_path
62+
elastic_metal_cloud_init_template_path = var.postgres_secondary_cloud_init_template_path
6363
elastic_metal_os_id = var.os_id
6464
elastic_metal_tailscale_key_expiry = var.tailscale_key_expiry
6565
elastic_metal_tailscale_tags = var.tailscale_tags
66-
elastic_metal_tags = var.secondary_tags
66+
elastic_metal_tags = var.postgres_secondary_tags
67+
}
68+
69+
# Gateway Primary (Elastic Metal / Scaleway Bare Metal)
70+
module "gateway_primary" {
71+
source = "../../modules/elastic_metal"
72+
73+
elastic_metal_zone = var.gateway_primary_zone
74+
elastic_metal_offer_name = var.gateway_primary_offer_name
75+
elastic_metal_subscription_period = var.subscription_period
76+
elastic_metal_server_name = var.gateway_primary_server_name
77+
elastic_metal_hostname = var.gateway_primary_hostname
78+
elastic_metal_description = var.gateway_primary_description
79+
elastic_metal_ssh_key_name = var.gateway_primary_ssh_key_name
80+
elastic_metal_ssh_public_key_path = var.ssh_public_key_path_scaleway
81+
elastic_metal_cloud_init_template_path = var.gateway_primary_cloud_init_template_path
82+
elastic_metal_os_id = var.os_id
83+
elastic_metal_tailscale_key_expiry = var.tailscale_key_expiry
84+
elastic_metal_tailscale_tags = var.tailscale_tags
85+
elastic_metal_tags = var.gateway_primary_tags
86+
}
87+
88+
# Gateway Secondary (Elastic Metal / Scaleway Bare Metal)
89+
module "gateway_secondary" {
90+
source = "../../modules/elastic_metal"
91+
92+
elastic_metal_zone = var.gateway_secondary_zone
93+
elastic_metal_offer_name = var.gateway_secondary_offer_name
94+
elastic_metal_subscription_period = var.subscription_period
95+
elastic_metal_server_name = var.gateway_secondary_server_name
96+
elastic_metal_hostname = var.gateway_secondary_hostname
97+
elastic_metal_description = var.gateway_secondary_description
98+
elastic_metal_ssh_key_name = var.gateway_secondary_ssh_key_name
99+
elastic_metal_ssh_public_key_path = var.ssh_public_key_path_scaleway
100+
elastic_metal_cloud_init_template_path = var.gateway_secondary_cloud_init_template_path
101+
elastic_metal_os_id = var.os_id
102+
elastic_metal_tailscale_key_expiry = var.tailscale_key_expiry
103+
elastic_metal_tailscale_tags = var.tailscale_tags
104+
elastic_metal_tags = var.gateway_secondary_tags
67105
}
Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,79 @@
11
# Postgres Monitor Outputs
2-
output "monitor_hostname" {
2+
output "postgres_monitor_name" {
3+
description = "Name of the postgres monitor EC2 instance"
4+
value = var.postgres_monitor_instance_name
5+
}
6+
7+
output "postgres_monitor_hostname" {
38
description = "Private DNS name of the postgres monitor EC2 instance"
49
value = module.postgres_monitor.instance_hostname
510
}
611

7-
output "monitor_public_ip" {
12+
output "postgres_monitor_public_ip" {
813
description = "Public IP address of the postgres monitor EC2 instance"
914
value = module.postgres_monitor.public_ip
1015
}
1116

1217
# Postgres Primary Outputs
13-
output "primary_server_id" {
18+
output "postgres_primary_server_name" {
19+
description = "Name of the postgres primary bare metal server"
20+
value = var.postgres_primary_server_name
21+
}
22+
23+
output "postgres_primary_server_id" {
1424
description = "ID of the postgres primary bare metal server"
1525
value = module.postgres_primary.server_id
1626
}
1727

18-
output "primary_server_ip" {
28+
output "postgres_primary_server_ip" {
1929
description = "IP address of the postgres primary bare metal server"
2030
value = module.postgres_primary.server_ip
2131
}
2232

2333
# Postgres Secondary Outputs
24-
output "secondary_server_id" {
34+
output "postgres_secondary_server_name" {
35+
description = "Name of the postgres secondary bare metal server"
36+
value = var.postgres_secondary_server_name
37+
}
38+
39+
output "postgres_secondary_server_id" {
2540
description = "ID of the postgres secondary bare metal server"
2641
value = module.postgres_secondary.server_id
2742
}
2843

29-
output "secondary_server_ip" {
44+
output "postgres_secondary_server_ip" {
3045
description = "IP address of the postgres secondary bare metal server"
3146
value = module.postgres_secondary.server_ip
3247
}
48+
49+
# Gateway Primary Outputs
50+
output "gateway_primary_server_name" {
51+
description = "Name of the gateway primary bare metal server"
52+
value = var.gateway_primary_server_name
53+
}
54+
55+
output "gateway_primary_server_id" {
56+
description = "ID of the gateway primary bare metal server"
57+
value = module.gateway_primary.server_id
58+
}
59+
60+
output "gateway_primary_server_ip" {
61+
description = "IP address of the gateway primary bare metal server"
62+
value = module.gateway_primary.server_ip
63+
}
64+
65+
# Gateway Secondary Outputs
66+
output "gateway_secondary_server_name" {
67+
description = "Name of the gateway secondary bare metal server"
68+
value = var.gateway_secondary_server_name
69+
}
70+
71+
output "gateway_secondary_server_id" {
72+
description = "ID of the gateway secondary bare metal server"
73+
value = module.gateway_secondary.server_id
74+
}
75+
76+
output "gateway_secondary_server_ip" {
77+
description = "IP address of the gateway secondary bare metal server"
78+
value = module.gateway_secondary.server_ip
79+
}
Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,69 @@
1+
# ============================================
12
# Provider Configuration
2-
aws_region = "us-east-1"
3-
scaleway_zone = "fr-par-2"
3+
# ============================================
4+
aws_region = "us-east-1"
5+
scaleway_zone = "fr-par-2"
46

7+
# ============================================
58
# Common Configuration
9+
# ============================================
610
ssh_public_key_path_aws = "~/.ssh/aws.pub"
711
ssh_public_key_path_scaleway = "~/.ssh/scaleway.pem.pub"
12+
subscription_period = "monthly"
813

14+
# ============================================
915
# Postgres Monitor Configuration (EC2)
10-
monitor_instance_type = "t2.micro"
16+
# ============================================
17+
postgres_monitor_instance_name = "agg-mode-hoodi-postgres-monitor"
18+
postgres_monitor_hostname = "agg-mode-hoodi-postgres-monitor"
19+
postgres_monitor_instance_type = "t2.micro"
20+
postgres_monitor_ssh_key_name = "agg-mode-hoodi-postgres-monitor-key"
21+
postgres_monitor_cloud_init_template_path = "../../cloudinit/postgres-monitor-cloud-init.yaml"
1122

23+
# ============================================
1224
# Postgres Primary Configuration (Elastic Metal)
13-
primary_zone = "fr-par-2"
14-
primary_offer_name = "EM-A610R-NVME"
25+
# ============================================
26+
postgres_primary_zone = "fr-par-2"
27+
postgres_primary_offer_name = "EM-A610R-NVME"
28+
postgres_primary_server_name = "agg-mode-hoodi-postgres-1"
29+
postgres_primary_hostname = "agg-mode-hoodi-postgres-1"
30+
postgres_primary_description = "PostgreSQL server 1 for hoodi"
31+
postgres_primary_ssh_key_name = "agg-mode-hoodi-postgres-1-key"
32+
postgres_primary_cloud_init_template_path = "../../cloudinit/scaleway-cloud-init.yaml"
33+
postgres_primary_tags = ["postgres", "postgres-1", "hoodi"]
1534

35+
# ============================================
1636
# Postgres Secondary Configuration (Elastic Metal)
17-
secondary_zone = "nl-ams-1"
18-
secondary_offer_name = "EM-A610R-NVME"
37+
# ============================================
38+
postgres_secondary_zone = "nl-ams-1"
39+
postgres_secondary_offer_name = "EM-A610R-NVME"
40+
postgres_secondary_server_name = "agg-mode-hoodi-postgres-2"
41+
postgres_secondary_hostname = "agg-mode-hoodi-postgres-2"
42+
postgres_secondary_description = "PostgreSQL server 2 for hoodi"
43+
postgres_secondary_ssh_key_name = "agg-mode-hoodi-postgres-2-key"
44+
postgres_secondary_cloud_init_template_path = "../../cloudinit/scaleway-cloud-init.yaml"
45+
postgres_secondary_tags = ["postgres", "postgres-2", "hoodi"]
46+
47+
# ============================================
48+
# Gateway Primary Configuration (Elastic Metal)
49+
# ============================================
50+
gateway_primary_zone = "fr-par-2"
51+
gateway_primary_offer_name = "EM-A610R-NVME"
52+
gateway_primary_server_name = "agg-mode-hoodi-gateway-1"
53+
gateway_primary_hostname = "agg-mode-hoodi-gateway-1"
54+
gateway_primary_description = "Gateway server 1 for hoodi"
55+
gateway_primary_ssh_key_name = "agg-mode-hoodi-gateway-1-key"
56+
gateway_primary_cloud_init_template_path = "../../cloudinit/scaleway-cloud-init.yaml"
57+
gateway_primary_tags = ["gateway", "gateway-1", "hoodi"]
58+
59+
# ============================================
60+
# Gateway Secondary Configuration (Elastic Metal)
61+
# ============================================
62+
gateway_secondary_zone = "nl-ams-1"
63+
gateway_secondary_offer_name = "EM-A610R-NVME"
64+
gateway_secondary_server_name = "agg-mode-hoodi-gateway-2"
65+
gateway_secondary_hostname = "agg-mode-hoodi-gateway-2"
66+
gateway_secondary_description = "Gateway server 2 for hoodi"
67+
gateway_secondary_ssh_key_name = "agg-mode-hoodi-gateway-2-key"
68+
gateway_secondary_cloud_init_template_path = "../../cloudinit/scaleway-cloud-init.yaml"
69+
gateway_secondary_tags = ["gateway", "gateway-2", "hoodi"]
Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,69 @@
1+
# ============================================
12
# Provider Configuration
2-
aws_region = "us-east-1"
3-
scaleway_zone = "fr-par-2"
4-
scaleway_project_id = "your-scaleway-project-id"
5-
tailscale_tailnet = "your-tailnet.ts.net"
3+
# ============================================
4+
aws_region = "us-east-1"
5+
scaleway_zone = "fr-par-2"
66

7+
# ============================================
78
# Common Configuration
9+
# ============================================
810
ssh_public_key_path_aws = "~/.ssh/aws.pub"
911
ssh_public_key_path_scaleway = "~/.ssh/scaleway.pem.pub"
12+
subscription_period = "monthly"
1013

14+
# ============================================
1115
# Postgres Monitor Configuration (EC2)
12-
monitor_instance_type = "t2.micro"
16+
# ============================================
17+
postgres_monitor_instance_name = "agg-mode-hoodi-postgres-monitor"
18+
postgres_monitor_hostname = "agg-mode-hoodi-postgres-monitor"
19+
postgres_monitor_instance_type = "t2.micro"
20+
postgres_monitor_ssh_key_name = "agg-mode-hoodi-postgres-monitor-key"
21+
postgres_monitor_cloud_init_template_path = "../../cloudinit/postgres-monitor-cloud-init.yaml"
1322

23+
# ============================================
1424
# Postgres Primary Configuration (Elastic Metal)
15-
primary_zone = "fr-par-2"
16-
primary_offer_name = "EM-A610R-NVME"
25+
# ============================================
26+
postgres_primary_zone = "fr-par-2"
27+
postgres_primary_offer_name = "EM-A610R-NVME"
28+
postgres_primary_server_name = "agg-mode-hoodi-postgres-1"
29+
postgres_primary_hostname = "agg-mode-hoodi-postgres-1"
30+
postgres_primary_description = "PostgreSQL server 1 for hoodi"
31+
postgres_primary_ssh_key_name = "agg-mode-hoodi-postgres-1-key"
32+
postgres_primary_cloud_init_template_path = "../../cloudinit/scaleway-cloud-init.yaml"
33+
postgres_primary_tags = ["postgres", "postgres-1", "hoodi"]
1734

35+
# ============================================
1836
# Postgres Secondary Configuration (Elastic Metal)
19-
secondary_zone = "nl-ams-1"
20-
secondary_offer_name = "EM-A610R-NVME"
37+
# ============================================
38+
postgres_secondary_zone = "nl-ams-1"
39+
postgres_secondary_offer_name = "EM-A610R-NVME"
40+
postgres_secondary_server_name = "agg-mode-hoodi-postgres-2"
41+
postgres_secondary_hostname = "agg-mode-hoodi-postgres-2"
42+
postgres_secondary_description = "PostgreSQL server 2 for hoodi"
43+
postgres_secondary_ssh_key_name = "agg-mode-hoodi-postgres-2-key"
44+
postgres_secondary_cloud_init_template_path = "../../cloudinit/scaleway-cloud-init.yaml"
45+
postgres_secondary_tags = ["postgres", "postgres-2", "hoodi"]
46+
47+
# ============================================
48+
# Gateway Primary Configuration (Elastic Metal)
49+
# ============================================
50+
gateway_primary_zone = "fr-par-2"
51+
gateway_primary_offer_name = "EM-A610R-NVME"
52+
gateway_primary_server_name = "agg-mode-hoodi-gateway-1"
53+
gateway_primary_hostname = "agg-mode-hoodi-gateway-1"
54+
gateway_primary_description = "Gateway server 1 for hoodi"
55+
gateway_primary_ssh_key_name = "agg-mode-hoodi-gateway-1-key"
56+
gateway_primary_cloud_init_template_path = "../../cloudinit/scaleway-cloud-init.yaml"
57+
gateway_primary_tags = ["gateway", "gateway-1", "hoodi"]
58+
59+
# ============================================
60+
# Gateway Secondary Configuration (Elastic Metal)
61+
# ============================================
62+
gateway_secondary_zone = "nl-ams-1"
63+
gateway_secondary_offer_name = "EM-A610R-NVME"
64+
gateway_secondary_server_name = "agg-mode-hoodi-gateway-2"
65+
gateway_secondary_hostname = "agg-mode-hoodi-gateway-2"
66+
gateway_secondary_description = "Gateway server 2 for hoodi"
67+
gateway_secondary_ssh_key_name = "agg-mode-hoodi-gateway-2-key"
68+
gateway_secondary_cloud_init_template_path = "../../cloudinit/scaleway-cloud-init.yaml"
69+
gateway_secondary_tags = ["gateway", "gateway-2", "hoodi"]

0 commit comments

Comments
 (0)