forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-workspace.sh
More file actions
26 lines (21 loc) · 784 Bytes
/
Copy pathcreate-workspace.sh
File metadata and controls
26 lines (21 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env bash
# Creates an isolated Terraform workspace for a CI run (PR or branch).
# Usage: create-workspace.sh <workspace_name>
set -euo pipefail
WORKSPACE="${1:-}"
if [[ -z "$WORKSPACE" ]]; then
echo "Error: workspace name required" >&2
exit 1
fi
cd "$(dirname "$0")/../terraform"
echo "==> Initialising Terraform backend"
terraform init -input=false -reconfigure
echo "==> Creating workspace: $WORKSPACE"
if terraform workspace list | grep -qE "^\s+$WORKSPACE\s*$"; then
echo "Workspace $WORKSPACE already exists — selecting"
terraform workspace select "$WORKSPACE"
else
terraform workspace new "$WORKSPACE"
fi
echo "==> Active workspace: $(terraform workspace show)"
echo "TERRAFORM_WORKSPACE=$WORKSPACE" >> "${GITHUB_ENV:-/dev/null}" 2>/dev/null || true