|
|
@ -28,11 +28,6 @@ variable "do_token" {
|
|
|
|
type = string
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
variable "machines" {
|
|
|
|
|
|
|
|
type = list(string)
|
|
|
|
|
|
|
|
description = "Machine names, corresponding to machine-NAME.yaml.tmpl files"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
variable "cluster_name" {
|
|
|
|
variable "cluster_name" {
|
|
|
|
type = string
|
|
|
|
type = string
|
|
|
|
description = "Cluster name used as prefix for the machine names"
|
|
|
|
description = "Cluster name used as prefix for the machine names"
|
|
|
@ -99,24 +94,21 @@ resource "digitalocean_custom_image" "flatcar" {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_reserved_ip" "machine" {
|
|
|
|
resource "digitalocean_reserved_ip" "machine" {
|
|
|
|
for_each = toset(var.machines)
|
|
|
|
region = digitalocean_droplet.machine.region
|
|
|
|
region = digitalocean_droplet.machine[each.key].region
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "cloudflare_dns_record" "machine" {
|
|
|
|
resource "cloudflare_dns_record" "machine" {
|
|
|
|
for_each = toset(var.machines)
|
|
|
|
|
|
|
|
zone_id = var.cloudflare_zone_id
|
|
|
|
zone_id = var.cloudflare_zone_id
|
|
|
|
name = "${var.cluster_name}-${each.key}"
|
|
|
|
name = "wg-easy"
|
|
|
|
content = digitalocean_reserved_ip.machine[each.key].ip_address
|
|
|
|
content = digitalocean_reserved_ip.machine.ip_address
|
|
|
|
type = "A"
|
|
|
|
type = "A"
|
|
|
|
proxied = false
|
|
|
|
proxied = false
|
|
|
|
ttl = 300
|
|
|
|
ttl = 300
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_volume" "machine" {
|
|
|
|
resource "digitalocean_volume" "machine" {
|
|
|
|
for_each = toset(var.machines)
|
|
|
|
|
|
|
|
region = var.datacenter
|
|
|
|
region = var.datacenter
|
|
|
|
name = "${var.cluster_name}-${each.key}"
|
|
|
|
name = "${var.cluster_name}"
|
|
|
|
size = 30
|
|
|
|
size = 30
|
|
|
|
initial_filesystem_type = "ext4"
|
|
|
|
initial_filesystem_type = "ext4"
|
|
|
|
initial_filesystem_label = "appstorage"
|
|
|
|
initial_filesystem_label = "appstorage"
|
|
|
@ -124,57 +116,36 @@ resource "digitalocean_volume" "machine" {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_droplet" "machine" {
|
|
|
|
resource "digitalocean_droplet" "machine" {
|
|
|
|
for_each = toset(var.machines)
|
|
|
|
name = "${var.cluster_name}"
|
|
|
|
name = "${var.cluster_name}-${each.key}"
|
|
|
|
|
|
|
|
image = digitalocean_custom_image.flatcar.id
|
|
|
|
image = digitalocean_custom_image.flatcar.id
|
|
|
|
region = var.datacenter
|
|
|
|
region = var.datacenter
|
|
|
|
size = var.server_type
|
|
|
|
size = var.server_type
|
|
|
|
ssh_keys = [digitalocean_ssh_key.first.fingerprint]
|
|
|
|
ssh_keys = [digitalocean_ssh_key.first.fingerprint]
|
|
|
|
# user_data = data.ct_config.machine-ignitions[each.key].rendered
|
|
|
|
|
|
|
|
user_data = file("flatcar/ignition.json")
|
|
|
|
user_data = file("flatcar/ignition.json")
|
|
|
|
lifecycle {
|
|
|
|
lifecycle {
|
|
|
|
create_before_destroy = true
|
|
|
|
create_before_destroy = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "time_sleep" "wait_5_seconds" {
|
|
|
|
resource "time_sleep" "wait_10_seconds" {
|
|
|
|
create_duration = "5s"
|
|
|
|
create_duration = "10s"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_reserved_ip_assignment" "machine" {
|
|
|
|
resource "digitalocean_reserved_ip_assignment" "machine" {
|
|
|
|
for_each = toset(var.machines)
|
|
|
|
ip_address = digitalocean_reserved_ip.machine.ip_address
|
|
|
|
ip_address = digitalocean_reserved_ip.machine[each.key].ip_address
|
|
|
|
droplet_id = digitalocean_droplet.machine.id
|
|
|
|
droplet_id = digitalocean_droplet.machine[each.key].id
|
|
|
|
|
|
|
|
# sometimes digital ocean throws an error for this resource
|
|
|
|
# sometimes digital ocean throws an error for this resource
|
|
|
|
# saying the droplet has a pending event so we delay a few seconds
|
|
|
|
# saying the droplet has a pending event so we delay a few seconds
|
|
|
|
depends_on = [time_sleep.wait_5_seconds]
|
|
|
|
depends_on = [time_sleep.wait_10_seconds]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_volume_attachment" "machine" {
|
|
|
|
resource "digitalocean_volume_attachment" "machine" {
|
|
|
|
for_each = toset(var.machines)
|
|
|
|
droplet_id = digitalocean_droplet.machine.id
|
|
|
|
droplet_id = digitalocean_droplet.machine[each.key].id
|
|
|
|
volume_id = digitalocean_volume.machine.id
|
|
|
|
volume_id = digitalocean_volume.machine[each.key].id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# data "ct_config" "machine-ignitions" {
|
|
|
|
|
|
|
|
# for_each = toset(var.machines)
|
|
|
|
|
|
|
|
# content = templatefile("${path.module}/cl/machine-${each.key}.yaml.tmpl", {
|
|
|
|
|
|
|
|
# ssh_keys = jsonencode(var.ssh_keys),
|
|
|
|
|
|
|
|
# name = each.key
|
|
|
|
|
|
|
|
# })
|
|
|
|
|
|
|
|
# strict = true
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# output "ip-addresses" {
|
|
|
|
|
|
|
|
# value = {
|
|
|
|
|
|
|
|
# for key in var.machines :
|
|
|
|
|
|
|
|
# "${var.cluster_name}-${key}" => digitalocean_droplet.machine[key].ipv4_address
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output "domain-mappings" {
|
|
|
|
output "domain-mappings" {
|
|
|
|
value = {
|
|
|
|
value = {
|
|
|
|
for key in var.machines :
|
|
|
|
"wg-easy.${var.domain}" = digitalocean_reserved_ip.machine.ip_address
|
|
|
|
"${var.cluster_name}-${key}.${var.domain}" => digitalocean_reserved_ip.machine[key].ip_address
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|