feat: load tailscale oauth credential for edge bootstrap

This commit is contained in:
juvenal.diaz 2026-10-26 21:37:33 -06:00
parent 4e9631dc71
commit 8fa9ae3c0e
4 changed files with 26 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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}"

View File

@ -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}"