self-hosting/instances.tf

82 lines
1.7 KiB
Terraform
Raw Normal View History

data "hcloud_image" "nixos_stable" {
with_selector = "nixos=21.05"
}
data "hcloud_floating_ip" "main_ip" {
with_selector = "external=main"
}
resource "hcloud_network" "private_network" {
2021-11-29 02:04:29 +01:00
name = "private"
ip_range = "10.0.0.0/16"
}
resource "hcloud_network_subnet" "db_network_subnet" {
2021-11-29 02:04:29 +01:00
type = "cloud"
network_id = hcloud_network.private_network.id
network_zone = "eu-central"
2021-11-29 02:04:29 +01:00
ip_range = "10.0.1.0/24"
}
2021-07-17 00:24:30 +02:00
resource "hcloud_network_subnet" "banditlair_vswitch_network_subnet" {
2021-11-29 02:04:29 +01:00
type = "vswitch"
network_id = hcloud_network.private_network.id
2021-07-17 00:24:30 +02:00
network_zone = "eu-central"
2021-11-29 02:04:29 +01:00
ip_range = "10.0.2.0/24"
2022-04-01 01:22:29 +02:00
vswitch_id = 29224
2021-07-17 00:24:30 +02:00
}
resource "hcloud_server" "db1" {
2021-11-29 02:04:29 +01:00
name = "db1"
image = data.hcloud_image.nixos_stable.id
server_type = "cpx11"
ssh_keys = [
hcloud_ssh_key.phfroidmont-desktop.id
]
keep_disk = true
2021-11-29 02:04:29 +01:00
location = "hel1"
network {
network_id = hcloud_network.private_network.id
2021-11-29 02:04:29 +01:00
ip = "10.0.1.11"
}
labels = {
type = "db"
}
depends_on = [
hcloud_network_subnet.db_network_subnet
]
}
resource "hcloud_server" "backend1" {
2021-11-29 02:04:29 +01:00
name = "backend1"
image = data.hcloud_image.nixos_stable.id
server_type = "cpx21"
ssh_keys = [
hcloud_ssh_key.phfroidmont-desktop.id
]
keep_disk = true
2021-11-29 02:04:29 +01:00
location = "hel1"
network {
network_id = hcloud_network.private_network.id
2021-11-29 02:04:29 +01:00
ip = "10.0.1.1"
}
labels = {
type = "backend"
}
depends_on = [
hcloud_network_subnet.db_network_subnet
]
}
resource "hcloud_floating_ip_assignment" "main" {
floating_ip_id = data.hcloud_floating_ip.main_ip.id
2021-11-29 02:04:29 +01:00
server_id = hcloud_server.backend1.id
}