Skip to content

Instantly share code, notes, and snippets.

@colinwilson
Created July 16, 2020 13:54
Show Gist options
  • Save colinwilson/e4331a902dc552079b554594e2b9600f to your computer and use it in GitHub Desktop.
Save colinwilson/e4331a902dc552079b554594e2b9600f to your computer and use it in GitHub Desktop.
Create 3 private network connected servers on Hetzner Cloud via Terraform
provider "hcloud" {
token = var.hcloud_token
}
resource "hcloud_ssh_key" "default" {
name = var.ssh_public_key_name
public_key = var.ssh_public_key
}
resource "hcloud_network" "default" {
name = var.private_network_name
ip_range = var.hcloud_network_ip_range
}
resource "hcloud_network_subnet" "default" {
network_id = hcloud_network.default.id
type = "server"
network_zone = var.private_network_zone
ip_range = var.hcloud_network_subnet_ip_range
}
resource "hcloud_server" "server" {
for_each = var.servers
name = each.value.name
image = each.value.image
server_type = each.value.server_type
location = each.value.location
backups = each.value.backups
ssh_keys = [var.ssh_public_key_name]
}
resource "hcloud_server_network" "server_network" {
for_each = var.servers
network_id = hcloud_network.default.id
server_id = hcloud_server.server[each.key].id
#ip = each.value.private_ip_address
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment