Skip to content

Commit

Permalink
Merge pull request #30 from wenzel-felix/feature/migrate2templatefile…
Browse files Browse the repository at this point in the history
…function

removed the deprecated data source template file and added templatefile function instead
also activated firewall
  • Loading branch information
wenzel-felix authored Feb 10, 2023
2 parents 6bf3a07 + 22186b8 commit f54b89d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions hcloud_firewall.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* resource "hcloud_firewall" "default" {
resource "hcloud_firewall" "default" {
name = "default-firewall"
rule {
direction = "in"
Expand All @@ -18,4 +18,4 @@ resource "hcloud_firewall_attachment" "default" {
]
firewall_id = hcloud_firewall.default.id
label_selectors = [ "nomad-server", "nomad-client", "vault-server" ]
} */
}
22 changes: 18 additions & 4 deletions hcloud_server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resource "hcloud_server" "main" {
hcloud_server.vault
]
for_each = local.Aggregator_Data
name = "${each.key}"
name = each.key
server_type = "cpx11"
image = "ubuntu-20.04"
location = var.hetzner_datacenter
Expand Down Expand Up @@ -40,7 +40,21 @@ resource "null_resource" "deployment" {
}

provisioner "file" {
content = join("\n", [file("${path.module}/scripts/base_configuration.sh"), data.template_file.base_configuration[each.key].rendered])
content = join("\n", [file("${path.module}/scripts/base_configuration.sh"),
each.value.type == "server" ? templatefile("${path.module}/scripts/server_setup.sh",
{
VAULT_IP = hcloud_server.vault.ipv4_address
SERVER_COUNT = length(local.Server_Count)
IP_RANGE = local.IP_range
SERVER_IPs = jsonencode([for key, value in local.Extended_Aggregator_IPs : value.private_ipv4[0] if value.type == "server"])
}) : templatefile("${path.module}/scripts/client_setup.sh",
{
VAULT_IP = hcloud_server.vault.ipv4_address
SERVER_COUNT = length(local.Server_Count)
IP_RANGE = local.IP_range
SERVER_IPs = jsonencode([for key, value in local.Extended_Aggregator_IPs : value.private_ipv4[0] if value.type == "server"])
})
])
destination = "setup.sh"
}

Expand Down Expand Up @@ -91,6 +105,6 @@ resource "null_resource" "clean_up" {
rm -f ${path.root}/certs/nomad_token
rm -f ${path.root}/certs/machines.pem
EOF
when = destroy
when = destroy
}
}
}
11 changes: 0 additions & 11 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,4 @@ locals {
"id" = value.id
}
}
}

data "template_file" "base_configuration" {
for_each = local.Aggregator_Data
template = each.value.type == "server" ? file("${path.module}/scripts/server_setup.sh") : file("${path.module}/scripts/client_setup.sh")
vars = {
VAULT_IP = hcloud_server.vault.ipv4_address
SERVER_COUNT = length(local.Server_Count)
IP_RANGE = local.IP_range
SERVER_IPs = jsonencode([for key, value in local.Extended_Aggregator_IPs : value.private_ipv4[0] if value.type == "server"])
}
}

0 comments on commit f54b89d

Please sign in to comment.