|
|
|
@ -12,6 +12,14 @@ terraform {
|
|
|
|
|
source = "hashicorp/null"
|
|
|
|
|
version = "3.2.4"
|
|
|
|
|
}
|
|
|
|
|
time = {
|
|
|
|
|
source = "hashicorp/time"
|
|
|
|
|
version = "0.13.1"
|
|
|
|
|
}
|
|
|
|
|
cloudflare = {
|
|
|
|
|
source = "cloudflare/cloudflare"
|
|
|
|
|
version = "5.8.2"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -20,11 +28,6 @@ variable "do_token" {
|
|
|
|
|
type = string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "machines" {
|
|
|
|
|
type = list(string)
|
|
|
|
|
description = "Machine names, corresponding to machine-NAME.yaml.tmpl files"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "cluster_name" {
|
|
|
|
|
type = string
|
|
|
|
|
description = "Cluster name used as prefix for the machine names"
|
|
|
|
@ -51,10 +54,39 @@ variable "flatcar_stable_version" {
|
|
|
|
|
description = "The Flatcar Stable release you want to use for the initial installation, e.g., 2605.12.0"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "cloudflare_zone_id" {
|
|
|
|
|
type = string
|
|
|
|
|
description = "Cloudflare zone ID"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "cloudflare_account_id" {
|
|
|
|
|
type = string
|
|
|
|
|
description = "Cloudflare account id"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "cloudflare_api_token" {
|
|
|
|
|
type = string
|
|
|
|
|
description = "Cloudflare api token"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "domain" {
|
|
|
|
|
type = string
|
|
|
|
|
description = "Root domain to use"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "subdomains" {
|
|
|
|
|
type = list
|
|
|
|
|
description = "Subdomains to setup"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
provider "digitalocean" {
|
|
|
|
|
token = var.do_token
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
provider "cloudflare" {
|
|
|
|
|
api_token = var.cloudflare_api_token
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_ssh_key" "first" {
|
|
|
|
|
name = var.cluster_name
|
|
|
|
|
public_key = var.ssh_keys.0
|
|
|
|
@ -67,49 +99,68 @@ resource "digitalocean_custom_image" "flatcar" {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_reserved_ip" "machine" {
|
|
|
|
|
for_each = toset(var.machines)
|
|
|
|
|
region = digitalocean_droplet.machine[each.key].region
|
|
|
|
|
region = digitalocean_droplet.machine.region
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "cloudflare_dns_record" "root" {
|
|
|
|
|
zone_id = var.cloudflare_zone_id
|
|
|
|
|
name = "@"
|
|
|
|
|
content = digitalocean_reserved_ip.machine.ip_address
|
|
|
|
|
type = "A"
|
|
|
|
|
proxied = false
|
|
|
|
|
ttl = 300
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "cloudflare_dns_record" "subdomains" {
|
|
|
|
|
for_each = toset(var.subdomains)
|
|
|
|
|
zone_id = var.cloudflare_zone_id
|
|
|
|
|
name = each.key
|
|
|
|
|
content = var.domain
|
|
|
|
|
type = "CNAME"
|
|
|
|
|
proxied = false
|
|
|
|
|
ttl = 300
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_volume" "machine" {
|
|
|
|
|
region = var.datacenter
|
|
|
|
|
name = "${var.cluster_name}"
|
|
|
|
|
size = 60
|
|
|
|
|
initial_filesystem_type = "ext4"
|
|
|
|
|
initial_filesystem_label = "appstorage"
|
|
|
|
|
description = "persistent storage for docker apps"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_droplet" "machine" {
|
|
|
|
|
for_each = toset(var.machines)
|
|
|
|
|
name = "${var.cluster_name}-${each.key}"
|
|
|
|
|
name = "${var.cluster_name}"
|
|
|
|
|
image = digitalocean_custom_image.flatcar.id
|
|
|
|
|
region = var.datacenter
|
|
|
|
|
size = var.server_type
|
|
|
|
|
ssh_keys = [digitalocean_ssh_key.first.fingerprint]
|
|
|
|
|
# user_data = data.ct_config.machine-ignitions[each.key].rendered
|
|
|
|
|
user_data = file("flatcar/ignition.json")
|
|
|
|
|
lifecycle {
|
|
|
|
|
create_before_destroy = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "digitalocean_reserved_ip_assignment" "machine" {
|
|
|
|
|
for_each = toset(var.machines)
|
|
|
|
|
ip_address = digitalocean_reserved_ip.machine[each.key].ip_address
|
|
|
|
|
droplet_id = digitalocean_droplet.machine[each.key].id
|
|
|
|
|
resource "time_sleep" "wait_10_seconds" {
|
|
|
|
|
create_duration = "10s"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
# }
|
|
|
|
|
resource "digitalocean_reserved_ip_assignment" "machine" {
|
|
|
|
|
ip_address = digitalocean_reserved_ip.machine.ip_address
|
|
|
|
|
droplet_id = digitalocean_droplet.machine.id
|
|
|
|
|
# sometimes digital ocean throws an error for this resource
|
|
|
|
|
# saying the droplet has a pending event so we delay a few seconds
|
|
|
|
|
depends_on = [time_sleep.wait_10_seconds]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output "ip-addresses" {
|
|
|
|
|
value = {
|
|
|
|
|
for key in var.machines :
|
|
|
|
|
"${var.cluster_name}-${key}" => digitalocean_droplet.machine[key].ipv4_address
|
|
|
|
|
}
|
|
|
|
|
resource "digitalocean_volume_attachment" "machine" {
|
|
|
|
|
droplet_id = digitalocean_droplet.machine.id
|
|
|
|
|
volume_id = digitalocean_volume.machine.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output "reserved-ip-addresses" {
|
|
|
|
|
output "domain-mappings" {
|
|
|
|
|
value = {
|
|
|
|
|
for key in var.machines :
|
|
|
|
|
"${var.cluster_name}-${key}" => digitalocean_reserved_ip.machine[key].ip_address
|
|
|
|
|
"${var.domain}" = digitalocean_reserved_ip.machine.ip_address
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|