forked from flatcar/flatcar-terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
digitaloecan-droplets.tf
57 lines (51 loc) · 1.48 KB
/
digitaloecan-droplets.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
terraform {
required_version = ">= 0.13"
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.5.1"
}
ct = {
source = "poseidon/ct"
version = "0.7.1"
}
template = {
source = "hashicorp/template"
version = "~> 2.2.0"
}
null = {
source = "hashicorp/null"
version = "~> 3.0.0"
}
}
}
resource "digitalocean_ssh_key" "first" {
name = var.cluster_name
public_key = var.ssh_keys.0
}
resource "digitalocean_custom_image" "flatcar" {
name = "flatcar-stable-${var.flatcar_stable_version}"
url = "https://stable.release.flatcar-linux.net/amd64-usr/${var.flatcar_stable_version}/flatcar_production_digitalocean_image.bin.bz2"
regions = [var.datacenter]
}
resource "digitalocean_droplet" "machine" {
for_each = toset(var.machines)
name = "${var.cluster_name}-${each.key}"
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
}
data "ct_config" "machine-ignitions" {
for_each = toset(var.machines)
content = data.template_file.machine-configs[each.key].rendered
}
data "template_file" "machine-configs" {
for_each = toset(var.machines)
template = file("${path.module}/cl/machine-${each.key}.yaml.tmpl")
vars = {
ssh_keys = jsonencode(var.ssh_keys)
name = each.key
}
}