# Create a new SSH key in cloud console resource "hcloud_ssh_key" "default" { name = "terraform-ansible" public_key = var.dtsv_hcloud_ssh_key } # Hetzner Primary IP resource "hcloud_primary_ip" "main_ipv4" { name = "primary_ipv4_web" datacenter = "fsn1-dc14" type = "ipv4" assignee_type = "server" auto_delete = false labels = { "mapping" : "WEB" } } resource "hcloud_primary_ip" "main_ipv6" { name = "primary_ipv6_web" datacenter = "fsn1-dc14" type = "ipv6" assignee_type = "server" auto_delete = false labels = { "mapping" : "WEB" } } # Hetzner Cloud Servers resource "hcloud_server" "web" { name = "WEB" server_type = "cpx21" image = "ubuntu-22.04" datacenter = "fsn1-dc14" ssh_keys = [hcloud_ssh_key.default.id] user_data = file("cloud.userdata") labels = { "env" : "prod" } network { network_id = hcloud_network.vpc.id ip = "10.0.0.2" } public_net { ipv4_enabled = true ipv4 = hcloud_primary_ip.main_ipv4.id ipv6_enabled = true ipv6 = hcloud_primary_ip.main_ipv6.id } # **Note**: the depends_on is important when directly attaching the # server to a network. Otherwise Terraform will attempt to create # server and sub-network in parallel. This may result in the server # creation failing randomly. depends_on = [ hcloud_network_subnet.subnet ] } resource "hcloud_server" "db" { name = "DB" server_type = "cpx11" image = "ubuntu-22.04" datacenter = "fsn1-dc14" ssh_keys = [hcloud_ssh_key.default.id] user_data = file("cloud.userdata") labels = { "env" : "prod" } network { network_id = hcloud_network.vpc.id ip = "10.0.0.3" } public_net { ipv4_enabled = true ipv6_enabled = true } # **Note**: the depends_on is important when directly attaching the # server to a network. Otherwise Terraform will attempt to create # server and sub-network in parallel. This may result in the server # creation failing randomly. depends_on = [ hcloud_network_subnet.subnet ] }