OSVauco/infrastructure/scripts/create_customer.sh
Chris Christiansen a807b0dd89 feat(C2): customer stamp-out struktur og create_customer.sh
- customers/_template/ med main.tf, variables.tf, terraform.tfvars
- customers/medioteq/ populert med produksjonsverdier
- infrastructure/scripts/create_customer.sh for stamp-out av nye kunder
- .gitignore: unntak for customers/**/*.tfvars
2026-05-30 14:56:13 +00:00

41 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [ -z "${1-}" ]; then
echo "Usage: $0 <customer_name>" >&2
exit 1
fi
CUSTOMER_NAME=$1
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CUSTOMER_DIR="${SCRIPT_DIR}/../terraform/customers/${CUSTOMER_NAME}"
TEMPLATE_DIR="${SCRIPT_DIR}/../terraform/customers/_template"
if [ -d "${CUSTOMER_DIR}" ]; then
echo "Error: Customer directory already exists: ${CUSTOMER_DIR}" >&2
exit 1
fi
cp -r "${TEMPLATE_DIR}" "${CUSTOMER_DIR}"
echo "✓ Directory created: ${CUSTOMER_DIR}"
read -p "GCP Project ID (e.g., ${CUSTOMER_NAME}-prod-eun1): " PROJECT_ID
read -p "GCP Billing Account ID: " BILLING_ACCOUNT_ID
read -p "Alert Email: " ALERT_EMAIL
read -p "Container Image URI: " CONTAINER_IMAGE
cat > "${CUSTOMER_DIR}/terraform.tfvars" << EOF
customer_id = "${CUSTOMER_NAME}"
project_id = "${PROJECT_ID}"
region = "europe-north1"
billing_account_id = "${BILLING_ACCOUNT_ID}"
alert_email = "${ALERT_EMAIL}"
billing_viewer_emails = ["chris.christiansen@vauco.no"]
container_image = "${CONTAINER_IMAGE}"
EOF
echo "✓ terraform.tfvars created."
terraform -chdir="${CUSTOMER_DIR}" init
terraform -chdir="${CUSTOMER_DIR}" apply -auto-approve
echo "=== Customer ${CUSTOMER_NAME} created successfully! ==="