use resource-level connection blocks...

this is now possible, since all our provisioners are using
the same settings. And it saves a bunch of lines
This commit is contained in:
phaer 2022-02-11 16:00:19 +01:00
parent 9dc4952665
commit c46e912d3e
3 changed files with 21 additions and 105 deletions

View File

@ -16,31 +16,24 @@ resource "hcloud_server" "agents" {
"engine" = "k3s", "engine" = "k3s",
} }
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
provisioner "file" { provisioner "file" {
content = templatefile("${path.module}/templates/config.ign.tpl", { content = templatefile("${path.module}/templates/config.ign.tpl", {
name = self.name name = self.name
ssh_public_key = local.ssh_public_key ssh_public_key = local.ssh_public_key
}) })
destination = "/root/config.ign" destination = "/root/config.ign"
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Install MicroOS # Install MicroOS
provisioner "remote-exec" { provisioner "remote-exec" {
inline = local.MicroOS_install_commands inline = local.MicroOS_install_commands
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Issue a reboot command # Issue a reboot command
@ -67,13 +60,6 @@ resource "hcloud_server" "agents" {
token = random_password.k3s_token.result token = random_password.k3s_token.result
}) })
destination = "/etc/rancher/k3s/agent.conf" destination = "/etc/rancher/k3s/agent.conf"
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Generating k3s agent config file # Generating k3s agent config file
@ -85,13 +71,6 @@ resource "hcloud_server" "agents" {
node-ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 257 + count.index) node-ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 257 + count.index)
}) })
destination = "/etc/rancher/k3s/config.yaml" destination = "/etc/rancher/k3s/config.yaml"
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Run the agent # Run the agent
@ -112,13 +91,6 @@ resource "hcloud_server" "agents" {
done done
EOT EOT
] ]
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
network { network {

View File

@ -14,31 +14,24 @@ resource "hcloud_server" "first_control_plane" {
"engine" = "k3s" "engine" = "k3s"
} }
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
provisioner "file" { provisioner "file" {
content = templatefile("${path.module}/templates/config.ign.tpl", { content = templatefile("${path.module}/templates/config.ign.tpl", {
name = self.name name = self.name
ssh_public_key = local.ssh_public_key ssh_public_key = local.ssh_public_key
}) })
destination = "/root/config.ign" destination = "/root/config.ign"
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Install MicroOS # Install MicroOS
provisioner "remote-exec" { provisioner "remote-exec" {
inline = local.MicroOS_install_commands inline = local.MicroOS_install_commands
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Issue a reboot command # Issue a reboot command
@ -72,39 +65,18 @@ resource "hcloud_server" "first_control_plane" {
node-taint = var.allow_scheduling_on_control_plane ? [] : ["node-role.kubernetes.io/master:NoSchedule"] node-taint = var.allow_scheduling_on_control_plane ? [] : ["node-role.kubernetes.io/master:NoSchedule"]
}) })
destination = "/etc/rancher/k3s/config.yaml" destination = "/etc/rancher/k3s/config.yaml"
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Upload kustomization.yaml, containing Hetzner CSI & CSM, as well as kured. # Upload kustomization.yaml, containing Hetzner CSI & CSM, as well as kured.
provisioner "file" { provisioner "file" {
content = local.post_install_kustomization content = local.post_install_kustomization
destination = "/tmp/kustomization.yaml" destination = "/tmp/kustomization.yaml"
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Upload traefik config # Upload traefik config
provisioner "file" { provisioner "file" {
content = local.traefik_config content = local.traefik_config
destination = "/tmp/traefik.yaml" destination = "/tmp/traefik.yaml"
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Run the first control plane # Run the first control plane
@ -133,13 +105,6 @@ resource "hcloud_server" "first_control_plane" {
"kubectl apply -f /tmp/traefik.yaml", "kubectl apply -f /tmp/traefik.yaml",
"rm /tmp/traefik.yaml /tmp/kustomization.yaml" "rm /tmp/traefik.yaml /tmp/kustomization.yaml"
] ]
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
network { network {

View File

@ -15,31 +15,24 @@ resource "hcloud_server" "control_planes" {
"engine" = "k3s", "engine" = "k3s",
} }
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
provisioner "file" { provisioner "file" {
content = templatefile("${path.module}/templates/config.ign.tpl", { content = templatefile("${path.module}/templates/config.ign.tpl", {
name = self.name name = self.name
ssh_public_key = local.ssh_public_key ssh_public_key = local.ssh_public_key
}) })
destination = "/root/config.ign" destination = "/root/config.ign"
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Install MicroOS # Install MicroOS
provisioner "remote-exec" { provisioner "remote-exec" {
inline = local.MicroOS_install_commands inline = local.MicroOS_install_commands
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Issue a reboot command # Issue a reboot command
@ -75,13 +68,6 @@ resource "hcloud_server" "control_planes" {
node-taint = var.allow_scheduling_on_control_plane ? [] : ["node-role.kubernetes.io/master:NoSchedule"] node-taint = var.allow_scheduling_on_control_plane ? [] : ["node-role.kubernetes.io/master:NoSchedule"]
}) })
destination = "/etc/rancher/k3s/config.yaml" destination = "/etc/rancher/k3s/config.yaml"
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
# Run an other control plane server # Run an other control plane server
@ -102,13 +88,6 @@ resource "hcloud_server" "control_planes" {
done done
EOT EOT
] ]
connection {
user = "root"
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
} }
network { network {