move random_pet to host module
This commit is contained in:
@@ -10,4 +10,7 @@ locals {
|
||||
ssh_identity_file = var.private_key == null ? var.public_key : var.private_key
|
||||
# shared flags for ssh to ignore host keys, to use our ssh identity file for all connections during provisioning.
|
||||
ssh_args = "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${local.ssh_identity_file}"
|
||||
|
||||
# the hosts name with its unique suffix attached
|
||||
name = "${var.name}-${random_pet.server.id}"
|
||||
}
|
||||
|
@@ -1,5 +1,25 @@
|
||||
resource "random_pet" "server" {
|
||||
length = 1
|
||||
keepers = {
|
||||
# We re-create the id (and server) whenever one of those attributes
|
||||
# changes. This should include all input variables to this module,
|
||||
# but NO SENSITIVE values as they might be logged here.
|
||||
name = var.name
|
||||
public_key = var.public_key
|
||||
additional_public_keys = join(",", var.additional_public_keys)
|
||||
ssh_keys = join(",", var.ssh_keys)
|
||||
firewall_ids = join(",", var.firewall_ids)
|
||||
placement_group_id = var.placement_group_id
|
||||
labels = join(",", [for k, v in var.labels: "${k}=${v}" ])
|
||||
location = var.location
|
||||
ipv4_subnet_id = var.ipv4_subnet_id
|
||||
private_ipv4 = var.private_ipv4
|
||||
server_type = var.server_type
|
||||
}
|
||||
}
|
||||
|
||||
resource "hcloud_server" "server" {
|
||||
name = var.name
|
||||
name = local.name
|
||||
|
||||
image = "ubuntu-20.04"
|
||||
rescue = "linux64"
|
||||
@@ -90,7 +110,7 @@ data "template_cloudinit_config" "config" {
|
||||
content = templatefile(
|
||||
"${path.module}/templates/userdata.yaml.tpl",
|
||||
{
|
||||
hostname = var.name
|
||||
hostname = local.name
|
||||
sshAuthorizedKeys = concat([local.ssh_public_key], var.additional_public_keys)
|
||||
}
|
||||
)
|
||||
|
Reference in New Issue
Block a user