Skip to content

Commit c819011

Browse files
committed
infra: add servers to tailscale
1 parent b134a68 commit c819011

File tree

10 files changed

+100
-16
lines changed

10 files changed

+100
-16
lines changed

infra/aggregation_mode/terraform/.terraform.lock.hcl

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/aggregation_mode/terraform/cloudinit/postgres-monitor-cloud-init.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ packages:
3636

3737
runcmd:
3838
- loginctl enable-linger app
39+
# Tailscale installation https://tailscale.com/kb/1293/cloud-init
40+
- curl -fsSL https://tailscale.com/install.sh | sh
41+
- tailscale up --ssh --advertise-tags=tag:server --auth-key=${tailscale_auth_key}
42+
- tailscale set --auto-update

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ packages:
3636

3737
runcmd:
3838
- loginctl enable-linger app
39+
# Tailscale installation https://tailscale.com/kb/1293/cloud-init
40+
- curl -fsSL https://tailscale.com/install.sh | sh
41+
- tailscale up --ssh --advertise-tags=tag:server --auth-key=${tailscale_auth_key}
42+
- tailscale set --auto-update

infra/aggregation_mode/terraform/main.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ provider "aws" {
22
region = "us-east-2"
33
}
44

5+
provider "tailscale" {
6+
# Configure via environment variables:
7+
# TAILSCALE_API_KEY
8+
}
59

610
module "postgres_monitor" {
711
source = "./postgres_monitor"
812
}
913

10-
module "postgres_primary" {
11-
source = "./postgres_primary"
12-
}
14+
# module "postgres_primary" {
15+
# source = "./postgres_primary"
16+
# }
1317

14-
module "postgres_secondary" {
15-
source = "./postgres_secondary"
16-
}
18+
# module "postgres_secondary" {
19+
# source = "./postgres_secondary"
20+
# }
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
output "postgres_monitor_instance_hostname" {
2-
description = "Private DNS name of the EC2 instance."
3-
value = module.postgres_monitor.instance_hostname
4-
}
5-
61
output "postgres_monitor_public_ip" {
7-
description = "Public IP address of the EC2 instance."
2+
description = "Public IP address of the Postgres Monitor."
83
value = module.postgres_monitor.public_ip
94
}
5+
6+
# output "postgres_primary_public_ip" {
7+
# description = "Public IP address of the Postgres Primary."
8+
# value = module.postgres_primary.public_ip
9+
# }
10+
#
11+
# output "postgres_secondary_public_ip" {
12+
# description = "Public IP address of the Postgres Secondary."
13+
# value = module.postgres_secondary.public_ip
14+
# }

infra/aggregation_mode/terraform/postgres_monitor/main.tf

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
terraform {
2+
required_providers {
3+
tailscale = {
4+
source = "tailscale/tailscale"
5+
}
6+
}
7+
}
8+
9+
# Create ephemeral Tailscale auth key
10+
resource "tailscale_tailnet_key" "postgres_monitor" {
11+
reusable = false
12+
ephemeral = true
13+
preauthorized = true
14+
expiry = 3600
15+
description = "Ephemeral key for postgres-monitor"
16+
tags = ["tag:server"]
17+
}
18+
119
# Upload existing SSH public key to AWS
220
resource "aws_key_pair" "ssh_key" {
321
key_name = var.ssh_key_name
@@ -58,8 +76,9 @@ resource "aws_instance" "postgres_monitor" {
5876
vpc_security_group_ids = [aws_security_group.ssh_access.id]
5977

6078
user_data = templatefile("${path.module}/../cloudinit/postgres-monitor-cloud-init.yaml", {
61-
hostname = var.hostname
62-
ssh_public_key = trimspace(file(var.ssh_public_key_path))
79+
hostname = var.hostname
80+
ssh_public_key = trimspace(file(var.ssh_public_key_path))
81+
tailscale_auth_key = tailscale_tailnet_key.postgres_monitor.key
6382
})
6483

6584
user_data_replace_on_change = true

infra/aggregation_mode/terraform/postgres_primary/main.tf

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ terraform {
33
scaleway = {
44
source = "scaleway/scaleway"
55
}
6+
tailscale = {
7+
source = "tailscale/tailscale"
8+
}
69
}
710
}
811

12+
# Create ephemeral Tailscale auth key
13+
resource "tailscale_tailnet_key" "postgres_primary" {
14+
reusable = false
15+
ephemeral = true
16+
preauthorized = true
17+
expiry = 3600
18+
description = "Ephemeral key for postgres-primary"
19+
tags = ["tag:server"]
20+
}
21+
922
# Get available bare metal offer
1023
data "scaleway_baremetal_offer" "offer" {
1124
zone = var.zone
@@ -41,8 +54,9 @@ resource "scaleway_baremetal_server" "postgres_primary" {
4154

4255
# Cloud-init configuration
4356
# cloud_init = templatefile("${path.module}/../cloudinit/scaleway-cloud-init.yaml", {
44-
# hostname = var.hostname
45-
# ssh_public_key = trimspace(file(var.ssh_public_key_path))
57+
# hostname = var.hostname
58+
# ssh_public_key = trimspace(file(var.ssh_public_key_path))
59+
# tailscale_auth_key = tailscale_tailnet_key.postgres_primary.key
4660
# })
4761

4862
tags = var.tags
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output public_ip {
2+
description = "Public IP address of the Postgres Primary."
3+
value = scaleway_baremetal_server.postgres_primary.ips
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output public_ip {
2+
description = "Public IP address of the Postgres Secondary."
3+
value = scaleway_baremetal_server.postgres_secondary.ips
4+
}

infra/aggregation_mode/terraform/terraform.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ terraform {
88
source = "scaleway/scaleway"
99
version = "2.64.0"
1010
}
11+
tailscale = {
12+
source = "tailscale/tailscale"
13+
version = "0.24.0"
14+
}
1115
}
1216

1317
required_version = ">= 1.2"

0 commit comments

Comments
 (0)