Add support for ephemeral hosts
This commit is contained in:
parent
5bfb1a167a
commit
92e16eea34
6 changed files with 21 additions and 2 deletions
|
|
@ -23,4 +23,13 @@ hosts = {
|
||||||
server_type = "cx32"
|
server_type = "cx32"
|
||||||
datacenter = "fsn1-dc14"
|
datacenter = "fsn1-dc14"
|
||||||
},
|
},
|
||||||
|
#"node004" = {
|
||||||
|
# hostname = "node004"
|
||||||
|
# rdns = "node004.serguzim.net"
|
||||||
|
# provider = "hetzner"
|
||||||
|
# ephemeral = true
|
||||||
|
# image = "debian-12"
|
||||||
|
# server_type = "cpx62"
|
||||||
|
# datacenter = "fsn1-dc14"
|
||||||
|
#},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,9 @@ resource "hcloud_server" "nodes" {
|
||||||
server_type = each.value.server_type
|
server_type = each.value.server_type
|
||||||
ssh_keys = [hcloud_ssh_key.default.id]
|
ssh_keys = [hcloud_ssh_key.default.id]
|
||||||
user_data = templatefile("./templates/cloud-init.yaml.tpl", {
|
user_data = templatefile("./templates/cloud-init.yaml.tpl", {
|
||||||
tailscale_authkey = tailscale_tailnet_key.cloud_init_key.key,
|
tailscale_authkey = each.value.ephemeral ? tailscale_tailnet_key.cloud_init_ephemeral_key.key : tailscale_tailnet_key.cloud_init_key.key,
|
||||||
default_ssh_key = var.default_ssh_key.public_key
|
default_ssh_key = var.default_ssh_key.public_key
|
||||||
|
hostname = each.value.hostname
|
||||||
})
|
})
|
||||||
placement_group_id = hcloud_placement_group.default.id
|
placement_group_id = hcloud_placement_group.default.id
|
||||||
public_net {
|
public_net {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,13 @@ resource "tailscale_tailnet_key" "cloud_init_key" {
|
||||||
expiry = 21600 # 6 hours
|
expiry = 21600 # 6 hours
|
||||||
description = "Cloud-init key used by opentofu"
|
description = "Cloud-init key used by opentofu"
|
||||||
}
|
}
|
||||||
|
resource "tailscale_tailnet_key" "cloud_init_ephemeral_key" {
|
||||||
|
reusable = true
|
||||||
|
ephemeral = true
|
||||||
|
preauthorized = true
|
||||||
|
expiry = 21600 # 6 hours
|
||||||
|
description = "Ephemeral cloud-init key used by opentofu"
|
||||||
|
}
|
||||||
|
|
||||||
resource "time_sleep" "wait_for_hosts" {
|
resource "time_sleep" "wait_for_hosts" {
|
||||||
for_each = var.hosts
|
for_each = var.hosts
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ variable "hosts" {
|
||||||
hostname = string
|
hostname = string
|
||||||
rdns = string
|
rdns = string
|
||||||
provider = string
|
provider = string
|
||||||
|
ephemeral = optional(bool, false)
|
||||||
image = optional(string)
|
image = optional(string)
|
||||||
server_type = optional(string)
|
server_type = optional(string)
|
||||||
datacenter = optional(string)
|
datacenter = optional(string)
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,5 @@ runcmd:
|
||||||
#####################################################################
|
#####################################################################
|
||||||
# One-command install, from https://tailscale.com/download/
|
# One-command install, from https://tailscale.com/download/
|
||||||
- ['sh', '-c', 'curl -fsSL https://tailscale.com/install.sh | sh']
|
- ['sh', '-c', 'curl -fsSL https://tailscale.com/install.sh | sh']
|
||||||
- ['tailscale', 'up', '--authkey=${tailscale_authkey}']
|
- ['tailscale', 'up', '--authkey=${tailscale_authkey}', '--hostname=${hostname}']
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,7 @@ variable "hosts" {
|
||||||
hostname = string
|
hostname = string
|
||||||
rdns = string
|
rdns = string
|
||||||
provider = string
|
provider = string
|
||||||
|
ephemeral = optional(bool, false)
|
||||||
image = optional(string)
|
image = optional(string)
|
||||||
server_type = optional(string)
|
server_type = optional(string)
|
||||||
datacenter = optional(string)
|
datacenter = optional(string)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue