Files
autonomic-bot f283a371bb recipe-maintainer: public snapshot (secrets + deployment plans removed, single commit)
Sanitized single-commit public mirror of recipe-maintainer.
- Removed test-ssh/.testenv (live creds); added test-ssh/.testenv.example placeholders.
- Removed plans/ and planned-updates/ (deployment-planning docs) so no client/
  deployment domains appear in the public repo.
- All other secret stores were already gitignored.
- docs.coopcloud.tech retained as a submodule (public upstream).
2026-06-16 20:18:24 +00:00

100 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Provision the terraform test droplet end-to-end.
#
# Usage:
# 1. Create terraform/.testenv with your DO token:
# DO_TOKEN=dop_v1_...
# 2. Run: ./terraform/setup.sh
#
# On first run this allocates a DigitalOcean reserved IP and saves it
# to .testenv as RESERVED_IP. On subsequent runs it reuses that IP.
# The reserved IP survives droplet destroy/recreate — set your DNS once.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
TESTENV="$SCRIPT_DIR/.testenv"
# --- Source .testenv ---
if [[ ! -f "$TESTENV" ]]; then
echo "ERROR: $TESTENV not found."
echo ""
echo "Create it with your DigitalOcean API token:"
echo " echo 'DO_TOKEN=dop_v1_...' > $TESTENV"
exit 1
fi
# shellcheck source=/dev/null
source "$TESTENV"
if [[ -z "${DO_TOKEN:-}" ]]; then
echo "ERROR: DO_TOKEN is not set in $TESTENV"
exit 1
fi
# --- Ensure a reserved IP exists ---
if [[ -z "${RESERVED_IP:-}" ]]; then
echo "No RESERVED_IP in .testenv, allocating one..."
RESERVED_IP="$(curl -s -X POST \
-H "Authorization: Bearer $DO_TOKEN" \
-H "Content-Type: application/json" \
-d '{"region":"ams3"}' \
https://api.digitalocean.com/v2/reserved_ips \
| grep -o '"ip":"[^"]*"' | head -1 | cut -d'"' -f4)"
if [[ -z "$RESERVED_IP" ]]; then
echo "ERROR: Failed to allocate reserved IP"
exit 1
fi
echo "RESERVED_IP=$RESERVED_IP" >> "$TESTENV"
echo "Allocated and saved reserved IP: $RESERVED_IP"
else
echo "Using existing reserved IP: $RESERVED_IP"
fi
# --- Generate terraform.tfvars ---
TFVARS="$SCRIPT_DIR/terraform.tfvars"
cat > "$TFVARS" <<EOF
do_token = "$DO_TOKEN"
reserved_ip = "$RESERVED_IP"
EOF
echo "Wrote $TFVARS"
# --- Terraform init + apply ---
cd "$SCRIPT_DIR"
if [[ ! -d .terraform ]]; then
echo "Running terraform init..."
terraform init
fi
echo "Running terraform apply..."
terraform apply -auto-approve
# --- Grab outputs ---
DOMAIN="$(terraform output -raw domain)"
echo ""
echo "Reserved IP: $RESERVED_IP"
echo "Domain: $DOMAIN"
echo ""
echo "Point DNS for $DOMAIN (A + wildcard) to: $RESERVED_IP"
# --- Switch repo to terraform mode ---
cd "$REPO_DIR"
./switch-test-instance.sh t1cc
echo ""
echo "Setup complete. You can now SSH with:"
echo " cd test-ssh && ssh -F ssh-config $DOMAIN"