diff --git a/bootstrap/edge/main.tf b/bootstrap/edge/main.tf index 52e0955..2b0b57c 100644 --- a/bootstrap/edge/main.tf +++ b/bootstrap/edge/main.tf @@ -183,6 +183,7 @@ set -eu install_dir="${self.triggers.install_dir}" install_docker="${self.triggers.install_docker}" tailscale_auth_key='${var.edge_tailscale_auth_key}' +tailscale_tag='${var.edge_tailscale_tag}' server_name="${self.triggers.server_name}" server_names="${self.triggers.server_names}" certbot_domain_args="${self.triggers.certbot_domain_args}" @@ -227,7 +228,7 @@ if ! tailscale ip -4 >/dev/null 2>&1; then echo "Tailscale is not connected on the edge VM. Set LAB_EDGE_TAILSCALE_AUTH_KEY for a fresh edge bootstrap." >&2 exit 1 fi - sudo tailscale up --auth-key "$tailscale_auth_key" --hostname homelab-oci-edge --accept-routes + sudo tailscale up --auth-key "$tailscale_auth_key" --hostname homelab-oci-edge --advertise-tags "$tailscale_tag" --accept-routes fi if ! tailscale ip -4 >/dev/null 2>&1; then echo "Tailscale did not obtain an IPv4 address on the edge VM." >&2 diff --git a/bootstrap/edge/variables.tf b/bootstrap/edge/variables.tf index 05c584b..98eb509 100644 --- a/bootstrap/edge/variables.tf +++ b/bootstrap/edge/variables.tf @@ -30,6 +30,12 @@ variable "edge_tailscale_auth_key" { default = "" } +variable "edge_tailscale_tag" { + description = "Tailscale tag to advertise when joining a recreated OCI edge VM." + type = string + default = "tag:homelab-edge" +} + variable "edge_install_docker" { type = bool default = false diff --git a/lib/jeannie/env.sh b/lib/jeannie/env.sh index 4e68b55..26111e0 100644 --- a/lib/jeannie/env.sh +++ b/lib/jeannie/env.sh @@ -269,7 +269,15 @@ export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_edge_host "${LAB_EDGE_HOST:-}" export_if_unset TF_VAR_edge_user "${LAB_EDGE_USER:-}" export_if_unset TF_VAR_edge_install_dir "${LAB_EDGE_INSTALL_DIR:-}" - export_if_unset TF_VAR_edge_tailscale_auth_key "${LAB_EDGE_TAILSCALE_AUTH_KEY:-}" + local edge_tailscale_auth_key="${LAB_EDGE_TAILSCALE_AUTH_KEY:-}" + if [[ -z "${edge_tailscale_auth_key}" ]]; then + local edge_tailscale_credentials_file="${LAB_EDGE_TAILSCALE_OAUTH_CREDENTIAL_FILE:-${HOME}/tailscaled.txt}" + if [[ -r "${edge_tailscale_credentials_file}" ]]; then + edge_tailscale_auth_key="$(sed -n 's/^secret:[[:space:]]*//p' "${edge_tailscale_credentials_file}" | head -n 1)" + fi + fi + export_if_unset TF_VAR_edge_tailscale_auth_key "${edge_tailscale_auth_key}" + export_if_unset TF_VAR_edge_tailscale_tag "${LAB_EDGE_TAILSCALE_TAG:-tag:homelab-edge}" export_if_unset TF_VAR_server_name "${LAB_DOMAIN:-}" export_if_unset TF_VAR_additional_server_names "${LAB_ADDITIONAL_SERVER_NAMES_JSON:-}" export_if_unset TF_VAR_jeannie_api_metrics_target "${LAB_JEANNIE_API_METRICS_TARGET:-api.${LAB_DOMAIN:-lab2025.duckdns.org}:443}" diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 66ea870..5e9a08b 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -225,7 +225,15 @@ export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_edge_host "${LAB_EDGE_HOST:-}" export_if_unset TF_VAR_edge_user "${LAB_EDGE_USER:-}" export_if_unset TF_VAR_edge_install_dir "${LAB_EDGE_INSTALL_DIR:-}" - export_if_unset TF_VAR_edge_tailscale_auth_key "${LAB_EDGE_TAILSCALE_AUTH_KEY:-}" + local edge_tailscale_auth_key="${LAB_EDGE_TAILSCALE_AUTH_KEY:-}" + if [[ -z "${edge_tailscale_auth_key}" ]]; then + local edge_tailscale_credentials_file="${LAB_EDGE_TAILSCALE_OAUTH_CREDENTIAL_FILE:-${HOME}/tailscaled.txt}" + if [[ -r "${edge_tailscale_credentials_file}" ]]; then + edge_tailscale_auth_key="$(sed -n 's/^secret:[[:space:]]*//p' "${edge_tailscale_credentials_file}" | head -n 1)" + fi + fi + export_if_unset TF_VAR_edge_tailscale_auth_key "${edge_tailscale_auth_key}" + export_if_unset TF_VAR_edge_tailscale_tag "${LAB_EDGE_TAILSCALE_TAG:-tag:homelab-edge}" export_if_unset TF_VAR_server_name "${LAB_DOMAIN:-}" export_if_unset TF_VAR_additional_server_names "${LAB_ADDITIONAL_SERVER_NAMES_JSON:-}" export_if_unset TF_VAR_jeannie_api_metrics_target "${LAB_JEANNIE_API_METRICS_TARGET:-api.${LAB_DOMAIN:-lab2025.duckdns.org}:443}"