One config. Full cloud platform lifecycle.
Terraform, Kubernetes, and GitOps from one args.yaml and a self-describing template repo. GCP-first today; multi-cloud by design.
Quick Start · Docs · 中文说明 · bl-template-personal (solo GCP)
Adoption snapshot (2026-11-23): 12 release downloads · 4 GitHub stars · latest v0.1.3 · Releases
blcli bootstraps and operates multi-environment GCP platforms end-to-end — from Terraform project creation through Kubernetes add-on deployment to GitOps application rollout — driven by one args.yaml and a self-describing template repository.
args.yaml + bl-template → blcli → GCP projects + GKE clusters + ArgoCD apps
Most teams stitch Terraform blueprints + shell scripts + ArgoCD by hand. blcli replaces that glue with a single CLI and a template protocol (config.yaml + args.yaml) you can fork without changing the tool.
| Audience | Template | Typical goal |
|---|---|---|
| Platform / SRE teams | bl-template | Multi-project GCP org (corp / stg / prd), ArgoCD, full GitOps |
| Solo developers & AI-assisted workflows | bl-template-personal | Single project + cluster, minimal / full profiles, low config burden |
- Full lifecycle, not just codegen —
initgenerates IaC and manifests;apply,status, androllbackcover deploy and ops. - Self-describing templates — components, parameters, and dependencies live in the template repo;
init-argsandexplainkeep humans and agents aligned. - Ordered, plannable changes — Terraform and Kubernetes run in dependency order with an execution plan and
--dry-runbefore anything touches your cluster. - One config, layered inheritance —
global → terraform → project → componentso environment differences stay inargs.yaml, not copy-paste. - Agent-friendly —
contract,diagnose, andrunsexpose stable schemas and failure hints for automation.
| Without blcli | With blcli |
|---|---|
| Manually copy Terraform per project | One template → N environments |
| Hand-wire Kubernetes add-on install scripts | Dependency-ordered component graph |
| Separately manage GitOps Application CRDs | blcli apply gitops in one command |
| No standard destroy path | Two-prompt safety confirmation + full teardown |
| Approach | Best for | blcli adds |
|---|---|---|
| CFT / Fabric FAST | Enterprise GCP landing zones (Terraform) | Kubernetes + GitOps orchestration in one CLI |
Kubestack / kbst |
Terraform-centric Kubernetes platforms | External template repo + args-driven workflow; lighter to fork |
| gke-tf | GKE Terraform codegen from YAML | Full stack plus apply / status / rollback |
| DIY scripts | Maximum control | Conventions, docs, dependency order, and safety rails out of the box |
blcli is the orchestration layer for “GCP platform from zero to running” — it does not replace Terraform, kubectl, or Argo CD.
We are collecting early adopters. If blcli runs in your team or lab, open a PR to add your org below (logo optional). The list is mirrored to README_zh.md automatically.
- What is blcli?
- Who is it for?
- Why blcli?
- How it compares
- Prerequisites
- Prepare
- Installation
- Quick Start (5 minutes)
- Full Workflow
- Commands Reference
- Configuration Reference
- Template Repository
- Generated Output Structure
- Architecture
- Logging and Debugging
- Troubleshooting
- Contributing
| Tool | Purpose | Required |
|---|---|---|
go 1.21+ |
Build blcli | Build only |
terraform |
GCP infrastructure | apply terraform |
kubectl |
Kubernetes resources | apply kubernetes |
helm |
Helm chart installs | apply kubernetes |
kustomize |
Kustomize overlays | apply kubernetes |
istioctl |
Istio mesh install | apply kubernetes |
gcloud |
GCP auth & credentials | apply terraform |
gh |
GitHub repo creation | apply init-repos |
Verify all tools at once:
blcli checkGCP Prerequisites:
gcloud auth loginwith a project-creation-capable account- A valid GCP Billing Account ID
- Sufficient CPU / address quota per region (recommend requesting increases before deploying large clusters)
ArgoCD / GitOps Prerequisites:
- A GitOps repository on GitHub (e.g.
my-org/infra-gitops) — use the actual repo name, not a generic placeholder likegitops - Repository must contain the application manifest directories referenced in
args.yaml:stg/hello-world/stg/hello-world-2/prd/hello-world/
- An SSH deploy key (
argocd_github.pub) added to that repository as a read-only deploy key.blcli initgenerates the key pair in<workspace>/keys/(mode 0700, setBLCLI_KEYS_DIRto use another directory), next to and never inside theterraform,kubernetesandgitopsdirectories. Older blcli versions wrote it to<workspace>/kubernetes/keys/;blcli initmoves it out. If that directory was ever committed or pushed, treat the key as leaked and rotate it. - GitOps repo URLs in SSH format (
git@github.com:org/repo.git) in.env— HTTP URLs will cause ArgoCD auth failures - ArgoCD sealed secret generated without the
useSshAgentfield (its presence breaks SSH authentication)
- A valid Google Cloud Platform account
- Billing enabled with a linked credit/debit card
- Sufficient quota for required services (for example, GKE, networking, storage)
- A dedicated GitHub Organization (for example:
ggsrc) - One or more repositories to store:
- Infrastructure code (Terraform / manifests)
- Application code
- GitOps configurations
-
Create an OAuth App in the GitHub Organization
-
Configure it for Argo CD authentication
-
Required setup:
-
Homepage URL: Argo CD server URL
-
Callback URL:
https://<argocd-domain>/api/dex/callback
-
-
Save and securely store:
- Client ID (goes into args or
.envasBLCLI_ARGOCD_<PROJECT>_DEX_GITHUB_CLIENT_ID) - Client Secret: never put it in args,
.envor the generated repositories. When you run the ArgoCD install, export it asDEX_GITHUB_CLIENT_SECRET(or answer the prompt); the template'sgen_dex_sealed_secret.shseals it into a SealedSecret thatargocd-cmreferences.blcli apply kubernetespassesDEX_GITHUB_CLIENT_SECRETthrough from your environment only.
- Client ID (goes into args or
-
Install the Google Cloud CLI (
gcloud) -
Authenticate your user account:
gcloud auth login
-
Configure Application Default Credentials (ADC):
gcloud auth application-default login
Install the following tools on your local machine:
- kubectl: Manage Kubernetes clusters and resources
- istioctl: Install and manage Istio (for example, Gateway API, Ambient mode)
- Terraform: Provision GCP resources (GKE, VPC, IAM, etc.)
- Git: Source code and GitOps workflow
- Domain name (for Argo CD / services exposure)
- DNS management (for example, Cloud DNS or external provider)
- Access control:
- GitHub team permissions
- GCP IAM roles
git clone https://github.com/ggsrc/blcli
cd blcli
# Build binary in current directory
go build -o blcli ./cmd/blcli
# Or install globally to $GOPATH/bin
go install ./cmd/blcliblcli version
blcli check# 1. Generate a starter args.yaml from the template repository
blcli init-args ../bl-template
# 2. Fill in your GCP credentials in args.yaml
# OrganizationID, BillingAccountID, GlobalName, TerraformBackendBucket
# 3. Generate all infrastructure code
blcli init -a args.yaml -f ../bl-template
# 4. Create GCP projects + remote state bucket
blcli apply init -d ./terraform/
# 5. Deploy GCP resources (VPCs, GKE, DNS, certs…)
blcli apply terraform -d ./terraform/
# 6. Deploy Kubernetes add-ons (Istio, ArgoCD, monitoring…)
gcloud container clusters get-credentials corp-cluster --region us-west1 --project <corp-project-id>
blcli apply kubernetes -d ./kubernetes/ -r ../bl-template -p corp \
--context gke_<corp-project-id>_us-west1_corp-cluster
# 7. Register ArgoCD Application CRDs
blcli apply gitops -d ./gitops/ --args args.yaml \
--context gke_<corp-project-id>_us-west1_corp-cluster
# 8. Tear everything down (interactive — requires double confirmation)
blcli destroy terraform --args=args.yaml| # | Stage | Command | Idempotent |
|---|---|---|---|
| 1 | Build & install | go build -o blcli ./cmd/blcli |
✅ |
| 2 | Generate config scaffold | blcli init-args -f ../bl-template |
✅ |
| 3 | Edit config & generate code | blcli init -a args.yaml -f ../bl-template |
✅ (with --overwrite) |
| 4 | Create GCP projects + state bucket | blcli apply init -d ./terraform/ |
✅ |
| 5 | Dry-run validation | blcli apply terraform -d ./terraform/ --dry-run |
✅ |
| 6 | Deploy GCP resources | blcli apply terraform -d ./terraform/ |
✅ |
| 7 | Deploy Kubernetes add-ons | blcli apply kubernetes -d ./kubernetes/ -p corp |
✅ |
| 8 | Deploy GitOps apps | blcli apply gitops -d ./gitops/ --args args.yaml |
✅ |
| 9 | Destroy all resources | blcli destroy terraform --args=args.yaml |
— |
| 10 | Clean up & E2E idempotency check | Re-run init + apply from scratch | — |
cd blcli
go build -o blcli ./cmd/blcli
go install ./cmd/blcli # optional: make globally available# From a local template repository
blcli init-args -f ../bl-template
# From a remote GitHub repository
blcli init-args github.com/ggsrc/bl-templateThis writes args.yaml and .env to the current directory with all available parameters pre-populated.
Edit args.yaml to set your organisation-specific values:
global:
GlobalName: "my-org" # Used as prefix in all resource names
terraform:
global:
OrganizationID: "123456789012" # GCP Organisation ID (set "0" to omit)
BillingAccountID: "01ABCD-2EFGH3-4IJKL5" # GCP Billing Account
TerraformBackendBucket: "my-org-tfstore" # GCS bucket for Terraform state
projects:
- name: prd
components:
- name: vpc
parameters:
enable_nat: true
enable_private_pool_route: true
ip_cidr_range: 10.12.0.0/16
- name: gke
parameters:
cluster_name: prd-cluster
machine_type: e2-small
deletion_protection: trueEdit .env to provide SSH-format GitOps URLs and other overrides (not the Dex client secret, see
OAuth Application for Argo CD):
BLCLI_GITOPS_SOURCE_REPO_URL=git@github.com:my-org/infra-gitops.git
BLCLI_ARGOCD_GIT_REPOSITORY_URL="git@github.com:my-org/infra-gitops.git"Generate all infrastructure code:
blcli init -a args.yaml -f ../bl-template
# Regenerate only Terraform files (overwrite existing)
blcli init -a args.yaml -f ../bl-template -m terraform --overwriteblcli apply init runs the init/ Terraform directories in the order defined by .blcli.marker — prepare items first (state bucket), then the rest (project creation).
# First run (creates state bucket and GCP projects)
blcli apply init -d ./terraform/
# Idempotency check — expect "No changes" on second run
blcli apply init -d ./terraform/If projects already exist (409 errors): blcli auto-imports them into Terraform state via
google_project.projects["<id>"]. If projects are inDELETE_REQUESTEDstate, undelete them first:gcloud projects undelete <project-id>
Validate plans before spending real GCP resources:
# Terraform plan (no apply)
blcli apply terraform -d ./terraform/ --dry-run > dryrun_tf.log 2>&1
# Kubernetes dry-run (requires cluster already running)
blcli apply kubernetes -d ./kubernetes/ -r ../bl-template -p corp \
--context gke_<corp-project-id>_us-west1_corp-cluster \
--dry-run > dryrun_k8s.log 2>&1
# GitOps dry-run (requires ArgoCD deployed)
blcli apply gitops -d ./gitops/ --args args.yaml \
--context gke_<corp-project-id>_us-west1_corp-cluster \
--dry-run > dryrun_gitops.log 2>&1blcli apply terraform -d ./terraform/blcli apply terraform runs both init/ directories and gcp/ project directories in full:
init phase:
[1/2] init/0-terraform-statestore (GCS backend bucket — prepare:true)
[2/2] init/1-my-org-projects (GCP project creation)
apply phase (parallel-safe, dependency-ordered):
gcp/corp → gcp/prd → gcp/stg
Each directory runs: terraform init → validate → plan → apply.
Cross-project dependency note: On first apply, IAM bindings referencing service accounts in other projects may fail. Re-run
blcli apply terraform -d ./terraform/— it converges in 2–3 passes.
Get cluster credentials for all environments, then apply each:
REGION=us-west1
gcloud container clusters get-credentials corp-cluster --region $REGION --project <corp-project-id>
gcloud container clusters get-credentials prd-cluster --region $REGION --project <prd-project-id>
gcloud container clusters get-credentials stg-cluster --region $REGION --project <stg-project-id>
# Corp
blcli apply kubernetes -d ./kubernetes/ -r ../bl-template -p corp \
--context gke_<corp-project-id>_${REGION}_corp-cluster
# Prd
blcli apply kubernetes -d ./kubernetes/ -r ../bl-template -p prd \
--context gke_<prd-project-id>_${REGION}_prd-cluster
# Stg
blcli apply kubernetes -d ./kubernetes/ -r ../bl-template -p stg \
--context gke_<stg-project-id>_${REGION}_stg-clusterComponents are applied in dependency order per project (e.g. external-secrets-operator before argocd).
Verify ArgoCD:
# Get initial admin password
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" \
--context gke_<corp-project-id>_us-west1_corp-cluster | base64 -d && echo
# Port-forward to access UI
kubectl port-forward svc/argocd-server -n argocd 8080:80 \
--context gke_<corp-project-id>_us-west1_corp-cluster
# Open: http://localhost:8080/argocd (user: admin)blcli apply gitops -d ./gitops/ --args args.yaml \
--context gke_<corp-project-id>_us-west1_corp-cluster
# --skip-sync: apply Application CRDs without waiting for ArgoCD sync
blcli apply gitops -d ./gitops/ --args args.yaml \
--context gke_<corp-project-id>_us-west1_corp-cluster --skip-syncArgoCD syncs the actual application manifests from your infra-gitops repository automatically once Applications are registered.
⚠️ Destructive — test/non-production environments only.
Before destroying, disable GKE deletion protection if deletion_protection = true:
# 1. Set deletionProtection: false in args.yaml for each project
# 2. Regenerate terraform output
blcli init -a args.yaml -f ../bl-template -m terraform --overwrite
# 3. Apply the change (updates cluster metadata only — no resource deletion)
blcli apply terraform -d ./terraform/ -p corp
# 4. Now destroy
blcli destroy terraform --args=args.yaml# Destroy (requires two interactive confirmations)
blcli destroy terraform --args=args.yaml
# Verify
gcloud projects list --filter="projectId:my-org-*"Expected behaviour:
init/0-terraform-statestorewill report "Instance cannot be destroyed" — this is intentional (prevent_destroy = trueprotects Terraform state). Record but do not treat as a blocker.- All three GCP projects (
corp,prd,stg) and their resources are destroyed.
If destroy reports "No changes / 0 destroyed" but projects/clusters still exist in GCP, this indicates a backend or state mismatch. Diagnose with:
terraform -chdir=terraform/gcp/prd state pull | jq '.resources | length'If state is empty (0), the GCS backend connection is lost — re-run
blcli init -m terraform --overwrite, reinitialise each project directory with-backend-config=config.gcs.tfbackend, then retry destroy. As a last resort (test environments only):gcloud projects delete my-org-corp-<suffix> gcloud projects delete my-org-prd-<suffix> gcloud projects delete my-org-stg-<suffix> # Keep the tfstore bucket: my-org-tfstore-<suffix>
# Remove all generated output
rm -rf terraform/ kubernetes/ gitops/Re-run the full pipeline from scratch to confirm self-healing behaviour:
# Regenerate all infrastructure code
blcli init -a args.yaml -f ../bl-template
# Re-apply init (must produce same GCP projects, same state bucket)
blcli apply init -d ./terraform/
# Re-apply terraform (must converge to "No changes" on second pass)
blcli apply terraform -d ./terraform/A successful E2E idempotency run confirms that:
- Template rendering is deterministic
- Terraform state is intact in GCS
- No manual fixups are required on a clean second run
Redirect each stage's output to a numbered log file for easier post-mortem analysis:
# Stage-by-stage log naming convention
blcli apply init -d ./terraform/ > execution_stage4.log 2>&1
blcli apply terraform -d ./terraform/ > execution_stage5.log 2>&1
blcli apply kubernetes -d ./kubernetes/ ... > execution_stage6.log 2>&1
blcli apply gitops -d ./gitops/ ... > execution_stage7.log 2>&1
blcli destroy terraform --args=args.yaml > execution_stage9.log 2>&1
# After a fix, append to a _fix variant
blcli apply init -d ./terraform/ > execution_stage4_fix.log 2>&1When a stage fails, match error keywords against the Troubleshooting section and re-run only the affected stage. Do not start over from stage 1.
Quick error triage:
| Error keyword | Likely cause | Section |
|---|---|---|
DELETE_REQUESTED |
Projects soft-deleted | GCP projects in DELETE_REQUESTED state |
already exists / 409 |
Resource exists outside state | 409 conflicts |
BILLING_DISABLED |
Billing detached after project restore | Billing disabled |
prevent_destroy |
State bucket plan forces replace | prevent_destroy error |
resource address "google_project.main" does not exist |
Wrong import address | google_project.main import error |
config.lock |
Stale kubectl lock file | config.lock error |
Missing backend configuration |
Project lacks backend "gcs" {} block |
Missing backend |
useSshAgent |
ArgoCD sealed secret field present | ArgoCD SSH auth |
No changes / 0 destroyed but resources exist |
State lost or backend mismatch | Stage 9 note |
Generate a starter args.yaml from a template repository's parameter definitions.
blcli init-args [template-repo] [flags]
# Examples
blcli init-args # uses default template
blcli init-args github.com/ggsrc/bl-template # from GitHub
blcli init-args ../bl-template # from local path
blcli init-args github.com/org/repo@v2.0.0 # pinned tag
blcli init-args ../bl-template -o myconfig.yaml # custom output path
blcli init-args ../bl-template --format toml # TOML output| Flag | Short | Default | Description |
|---|---|---|---|
--output |
-o |
args.yaml |
Output file path |
--format |
yaml |
Output format: yaml or toml |
|
--force-update |
-f |
false | Force pull latest template |
--cache-expiry |
24h |
Template cache TTL (0 = no expiry) |
Render infrastructure code from templates using your args.yaml.
blcli init [template-repo] -a args.yaml [flags]
# Examples
blcli init ../bl-template -a args.yaml # all modules
blcli init ../bl-template -a args.yaml -m terraform # terraform only
blcli init ../bl-template -a args.yaml -m kubernetes -m gitops
blcli init ../bl-template -a args.yaml -m terraform --overwrite # regenerate
blcli init ../bl-template -a base.yaml -a override.yaml # multi-file merge
blcli init ../bl-template -a args.yaml -o workspace/output # custom output dir| Flag | Short | Default | Description |
|---|---|---|---|
--args |
-a |
required | Args file (YAML/TOML); repeatable, earlier files win |
--modules |
-m |
all | Modules to render: terraform, kubernetes, gitops |
--output |
-o |
from config | Output directory |
--overwrite |
-w |
false | Overwrite blcli-managed directories |
--force-update |
-f |
false | Force pull latest template |
--cache-expiry |
24h |
Template cache TTL |
What blcli init does:
- Loads and merges all
--argsfiles (earlier overrides later) - Validates merged config against template parameter definitions (
required,pattern,enum,numberRange,stringLength,validation.unique) - Renders only the components explicitly listed in
args.yaml - Writes
terraform/.blcli.markerwith orderedinit_prepare_dirsandinit_dirs - Copies shared modules to
terraform/gcp/modules/
Run only the init/ Terraform directories (state bucket first, then project creation). Use this before blcli apply terraform when setting up a fresh environment.
blcli apply init -d ./terraform/ [flags]
# With options
blcli apply init -d ./terraform/ --auto-approve --timeout 30m
blcli apply init -d ./terraform/ --init-delay=0 # skip inter-directory wait| Flag | Default | Description |
|---|---|---|
-d, --dir |
required | Terraform root directory |
--auto-approve |
false | Skip interactive confirmation |
--timeout |
1h |
Overall timeout |
--init-delay |
30s |
Wait between directories (allows GCP API propagation) |
--skip-backend |
false | Skip backend init (testing only) |
Run init/ directories then all gcp/ project directories. Each directory runs terraform init → validate → plan → apply.
blcli apply terraform -d ./terraform/ [flags]
# Apply a single project only
blcli apply terraform -d ./terraform/ -p prd
# Use template repo for dependency-ordered project execution
blcli apply terraform -d ./terraform/ -r ../bl-template
# Dry-run (plan only, no apply)
blcli apply terraform -d ./terraform/ --dry-run| Flag | Short | Default | Description |
|---|---|---|---|
--dir |
-d |
required | Terraform root directory |
--project |
-p |
all | Apply only this project name |
--template-repo |
-r |
— | Template repo path for dependency ordering |
--auto-approve |
false | Skip confirmation prompts | |
--timeout |
1h |
Overall timeout | |
--dry-run |
false | Plan only, no apply | |
--skip-backend |
false | Skip GCS backend init |
Deploy Kubernetes components (Helm charts, kustomize overlays, install scripts) to a cluster in dependency order.
blcli apply kubernetes -d ./kubernetes/ -r ../bl-template -p corp \
--context gke_<project>_<region>_corp-cluster [flags]| Flag | Short | Default | Description |
|---|---|---|---|
--dir |
-d |
required | Kubernetes root directory |
--project |
-p |
required | Project name (corp, prd, stg) |
--template-repo |
-r |
required | Template repo path (for component ordering) |
--context |
current | kubectl context to use | |
--dry-run |
false | Print plan, do not apply |
Apply ArgoCD Application CRDs from the generated gitops/ directory. ArgoCD handles the actual application sync from the GitOps repository.
blcli apply gitops -d ./gitops/ --args args.yaml \
--context gke_<project>_<region>_corp-cluster [flags]| Flag | Default | Description |
|---|---|---|
--args |
required | Path to args.yaml |
--context |
current | kubectl context |
--skip-sync |
false | Apply CRDs without waiting for ArgoCD sync |
--kubeconfig |
~/.kube/config |
Path to kubeconfig |
Initialise generated directories as git repositories, create GitHub repos via gh, and push initial commits.
blcli apply init-repos -d ./workspace/output --org my-github-org| Flag | Short | Default | Description |
|---|---|---|---|
--dir |
-d |
required | Root directory (contains terraform/, kubernetes/, gitops/) |
--org |
-o |
required | GitHub organisation or username |
--terraform-dir |
{dir}/terraform |
Override terraform path | |
--kubernetes-dir |
{dir}/kubernetes |
Override kubernetes path | |
--gitops-dir |
{dir}/gitops |
Override gitops path |
Before running any git or gh command, init-repos checks the three directories for private-key
material and refuses to continue if it finds any: files with a PEM/OpenSSH private key header,
file names id_* (except *.pub), *.pem, *.key, *.p12, *.pfx, and keys/ directories
that hold more than public keys. A .gitignore entry does not count: move the files out of the
directory and run the command again. It also adds keys/ to kubernetes/.gitignore.
Destroy all resources managed by blcli. Requires double interactive confirmation.
# Destroy terraform resources only
blcli destroy terraform --args=args.yaml
# Destroy all modules
blcli destroy --args=args.yamlSafety prompts:
- Type
yesto confirm destruction - If
global.organization_idorglobal.nameis set in args, type its value as a second confirmation
⚠️ This removes GCP projects, GKE clusters, VPCs, DNS zones, and cleans up local generated Terraform directories. Use only in non-production environments.
Verify all required external tools are installed:
blcli checkPrint the v2 AI-agent tool contract. Use JSON for automation.
blcli contract --format json
blcli contract "apply terraform" --format yamlThe contract includes command inputs, outputs, JSON schemas, exit codes, examples, compatibility policy, and agent guidance.
Classify a failed command output and return repair guidance.
blcli diagnose --message "Error 409: already exists" --format json
blcli diagnose --file execution_stage5.logThe diagnosis includes a stable category, confidence, matched keywords, likely cause, next steps, and repair commands.
When a normal blcli command fails with a known pattern, blcli also appends this diagnosis to stderr. Capture the failed command output and pass it to blcli diagnose --file <log> --format json for machine-readable triage.
Offline failure samples are available under integration/fixtures/failures/ for safe replay without running Terraform, kubectl, gcloud, or gh.
Agent replay playbooks are available under integration/fixtures/agent-replay/ for contract, diagnose, and runs workflows.
List and inspect persisted run records from ~/.blcli/progress.
blcli runs list --format json
blcli runs list --status failed
blcli runs show op-20260529-103000-app --format yamlUse this to look up run ids, inspect step status, and retrieve stored error messages for later diagnosis or replay planning.
Step records include timestamps, duration, status, command/action, output excerpt, error location, and error message when available.
For apply all, Terraform, Kubernetes, and GitOps steps record the actual subprocess command and captured output excerpt.
# ── Global (repo-level) ────────────────────────────────────────────────────
global:
GlobalName: "my-org" # Prefix for all resource names
# ── Terraform ─────────────────────────────────────────────────────────────
terraform:
global:
OrganizationID: "123456789012" # GCP Org ID; "0" = omit org_id
BillingAccountID: "01ABCD-2EFGH3-4IJKL5"
GlobalName: "my-org"
TerraformBackendBucket: "my-org-tfstore-abc123"
TerraformVersion: "1.9.0"
init:
components:
projects: # GCP project creation
ProjectServices:
"${project.prd.id}":
- compute.googleapis.com
- container.googleapis.com
- dns.googleapis.com
projects:
- name: prd
global:
project_name: prd
region: us-west1
components:
- name: backend
parameters: {}
- name: variables
parameters:
zone: us-west1-a
- name: vpc
parameters:
enable_nat: true
enable_private_pool_route: true
ip_cidr_range: 10.12.0.0/16
- name: gke
parameters:
cluster_name: prd-cluster
machine_type: e2-small
deletion_protection: true
min_node_count: 1
max_node_count: 50
- name: stg
global:
project_name: stg
region: us-west1
components:
- name: vpc
parameters:
enable_nat: true # ← must be true for private GKE egress
enable_private_pool_route: true
ip_cidr_range: 10.11.0.0/16
- name: corp
global:
project_name: corp
region: us-west1
components:
- name: vpc
parameters:
enable_nat: true
enable_private_pool_route: true
ip_cidr_range: 10.10.0.0/16
# ── GitOps ─────────────────────────────────────────────────────────────────
gitops:
argocd:
- project: stg
apps:
- name: hello-world
- name: hello-world-2
- project: prd
apps:
- name: hello-worldParameters are merged from broadest → narrowest scope:
global.*
└── terraform.global.*
└── terraform.projects[n].global.*
└── terraform.projects[n].components[m].parameters.*
All global parameters are flattened for template access:
global.GlobalName → {{ .GlobalName }}
terraform.global.OrganizationID → {{ .OrganizationID }}
projects[n].global.project_name → {{ .project_name }}
components[m].parameters.enable_nat → {{ .enable_nat }}
Setting
OrganizationID: "0"suppressesorg_idfrom all generated Terraform resources and variables — useful when deploying without a GCP Organisation.
Place a .env file next to args.yaml for secrets and environment-specific overrides:
# GitOps repository — must use SSH format for ArgoCD
BLCLI_GITOPS_SOURCE_REPO_URL=git@github.com:my-org/infra-gitops.git
BLCLI_GITOPS_STG_HELLO_WORLD_APPLICATION_REPO=git@github.com:my-org/infra-gitops.git
BLCLI_GITOPS_PRD_HELLO_WORLD_APPLICATION_REPO=git@github.com:my-org/infra-gitops.git
BLCLI_ARGOCD_GIT_REPOSITORY_URL="git@github.com:my-org/infra-gitops.git"Values already set in
args.yamlare not overridden by.env. Use.envonly for values absent fromargs.yaml.
.envvalues end up in the rendered files, so blcli ignores Dex client secret variables (BLCLI_ARGOCD_[<PROJECT>_]DEX_GITHUB_CLIENT_SECRET,..._GITHUB_AUTH_CLIENT_SECRET) with a one-line notice. ExportDEX_GITHUB_CLIENT_SECRETwhen running the ArgoCD install instead.
bl-template/
├── args.yaml # Repo-level parameter definitions
├── terraform/
│ ├── config.yaml # Init items, modules, projects, dependencies
│ ├── args.yaml # Terraform-level parameters
│ ├── default.yaml # Default values for generated args.yaml
│ ├── init/
│ │ ├── args.yaml
│ │ ├── terraform-statestore.tf.tmpl
│ │ ├── projects.tf.tmpl
│ │ └── config.gcs.tfbackend.tmpl
│ ├── modules/
│ │ ├── gke/
│ │ ├── gke-node-pool/
│ │ └── gke-sm-accessor-sa/
│ └── project/
│ ├── args.yaml
│ ├── vpc.tf.tmpl
│ ├── gke.tf.tmpl
│ ├── dns.tf.tmpl
│ └── ...
├── kubernetes/
│ └── config.yaml
└── gitops/
└── config.yaml
version: "1.0.0"
# Init items — executed by `blcli apply init` and `blcli apply terraform`
init:
- name: statestore
prepare: true # prepare:true = run FIRST (creates state bucket)
path:
- terraform/init/terraform-statestore.tf.tmpl
- terraform/init/config.gcs.tfbackend.tmpl
destination: terraform/init/0-terraform-statestore/
args: terraform/init/args.yaml
- name: projects
path:
- terraform/init/projects.tf.tmpl
destination: terraform/init/1-{{.GlobalName}}-projects/
args: terraform/init/args.yaml
# Shared Terraform modules (copied verbatim)
modules:
- name: gke
path:
- terraform/modules/gke
# Project components (rendered per project listed in args.yaml)
projects:
- name: backend
path:
- terraform/project/backend.tf.tmpl
args: terraform/project/backend-args.yaml
dependencies: []
- name: vpc
path:
- terraform/project/vpc.tf.tmpl
args: terraform/project/vpc-args.yaml
dependencies: [backend, variables]
- name: gke
path:
- terraform/project/gke.tf.tmpl
args: terraform/project/gke-args.yaml
dependencies: [vpc]Key points:
prepare: truemarks an init item to run before all others (e.g. state bucket must exist before backends can be configured)destinationsupports Go template variables:1-{{.GlobalName}}-projects/dependenciesdefines DAG ordering within each module; components with no unmet dependencies run in parallel- Only components explicitly listed in
args.yamlare rendered
./
├── args.yaml
├── .env
├── terraform/
│ ├── .blcli.marker # Ordered init_prepare_dirs + init_dirs
│ ├── init/
│ │ ├── 0-terraform-statestore/ # GCS backend bucket (prepare:true)
│ │ │ ├── terraform-statestore.tf
│ │ │ └── config.gcs.tfbackend
│ │ └── 1-my-org-projects/ # GCP project creation
│ │ ├── projects.tf
│ │ └── config.gcs.tfbackend
│ └── gcp/
│ ├── modules/ # Copied from bl-template/terraform/modules/
│ │ ├── gke/
│ │ └── gke-node-pool/
│ ├── corp/
│ │ ├── backend.tf
│ │ ├── vpc.tf
│ │ ├── gke.tf
│ │ ├── dns.tf
│ │ └── config.gcs.tfbackend
│ ├── prd/
│ └── stg/
├── kubernetes/
│ ├── corp/
│ │ ├── external-secrets-operator/
│ │ ├── 0-external-secrets/
│ │ ├── 1-istio/
│ │ ├── 2-argocd/
│ │ ├── 3-victoria-metrics-operator/
│ │ └── 4-grafana/
│ ├── prd/
│ └── stg/
└── gitops/
├── stg/
│ ├── hello-world/
│ │ ├── deployment.yaml
│ │ ├── service.yaml
│ │ └── app.yaml # ArgoCD Application CRD
│ └── hello-world-2/
└── prd/
└── hello-world/
┌─────────────────────────────────────────────────────────┐
│ blcli │
│ ┌──────────┐ ┌──────────┐ ┌───────────────────────┐ │
│ │ CLI │ │ Template │ │ Bootstrap │ │
│ │ (Cobra) │→ │ Loader │→ │ terraform / k8s / │ │
│ │ │ │ (cache) │ │ gitops / destroy │ │
│ └──────────┘ └──────────┘ └───────────────────────┘ │
│ ↓ ↓ │
│ bl-template args.yaml │
│ config.yaml .env │
│ *.tf.tmpl │
└─────────────────────────────────────────────────────────┘
↓ ↓ ↓
terraform/gcp/ kubernetes/corp/ gitops/stg/
(generated HCL) (generated YAML) (ArgoCD apps)
Design principles:
| Principle | Implementation |
|---|---|
| Self-describing templates | Each template repo defines its own structure via config.yaml |
| Render plan before write | Builds a complete plan before touching the filesystem; fails fast on validation errors |
| Layered configuration | 4-level inheritance: global → terraform.global → project.global → component.parameters |
| Smart caching | git clone once, git pull on expiry; --force-update to bypass |
| Component filtering | Only components listed in args.yaml are rendered — no surprise files |
| Idempotent apply | Every apply subcommand is safe to re-run; converges to desired state |
Projects soft-deleted within the last 30 days cannot be imported by Terraform. Restore them first:
gcloud projects undelete <project-id>
# Restore all three at once
gcloud projects undelete my-org-corp-<suffix>
gcloud projects undelete my-org-prd-<suffix>
gcloud projects undelete my-org-stg-<suffix>If Terraform reports resource address "google_project.main" does not exist, your template uses for_each — import with the keyed address:
terraform import 'google_project.projects["my-org-prd-abc123"]' my-org-prd-abc123When existing GCP resources are not in Terraform state, terraform apply returns 409. Import them manually:
# VPC network
terraform -chdir=terraform/gcp/corp import google_compute_network.main \
projects/my-org-corp-<suffix>/global/networks/main
# Subnet
terraform -chdir=terraform/gcp/corp import google_compute_subnetwork.default \
my-org-corp-<suffix>/us-west1/us-west-1
# GKE cluster
terraform -chdir=terraform/gcp/corp import "module.gke.google_container_cluster.main" \
projects/my-org-corp-<suffix>/locations/us-west1/clusters/corp-cluster
# GKE node pool
terraform -chdir=terraform/gcp/corp import "module.gke.google_container_node_pool.main" \
projects/my-org-corp-<suffix>/locations/us-west1/clusters/corp-cluster/nodePools/mainRe-run blcli apply terraform -d ./terraform/ after each batch of imports — it converges progressively.
Re-attach billing after undeleting a project:
gcloud billing projects link <project-id> --billing-account=<BILLING_ACCOUNT_ID>
# Verify
gcloud billing projects describe <project-id>A concurrent kubectl config write left a stale lock:
rm -f ~/.kube/config.lockThe GCS state bucket has lifecycle.prevent_destroy = true by design. If a plan tries to replace it (e.g. after adding an explicit project = attribute to google_storage_bucket), remove that attribute from the statestore template — the provider default project is sufficient and avoids a forced replacement.
Large node pools (e2-standard-8) consume quota quickly. Scale down idle pools before Terraform creates new ones:
gcloud container clusters resize <cluster> --node-pool=on-demand \
--num-nodes=0 --region=<region> --project=<project-id> --quiet
# Verify quota freed
gcloud compute project-info describe --project=<project-id> \
--format="json" | jq '.quotas[] | select(.metric | test("CPU"))'If you see Warning: Missing backend configuration, the generated project Terraform is missing the terraform { backend "gcs" {} } block, so -backend-config is silently ignored and state falls back to local.
Fix: Ensure the template's backend.tf.tmpl contains:
terraform {
backend "gcs" {}
}Then regenerate and re-initialise:
blcli init -a args.yaml -f ../bl-template -m terraform --overwrite
terraform -chdir=terraform/gcp/prd init -input=false -backend-config=config.gcs.tfbackend
terraform -chdir=terraform/gcp/prd state pull | jq '.resources | length'ArgoCD fails to clone the GitOps repository if:
- HTTPS URL used instead of SSH — all GitOps repo URLs in
.envmust begit@github.com:org/repo.git - Wrong repository name — use the real repo name (e.g.
infra-gitops), not a placeholder likegitops useSshAgentpresent in the sealed secret — regenerate the ArgoCD SSH secret and ensureuseSshAgentis absent from the secret YAML before sealing
terraform init -input=false -backend-config=config.gcs.tfbackend
terraform state pull | jq '.resources | length'
# Must be > 0 if resources were previously created- Fork the repository
- Create a feature branch:
git checkout -b feat/my-feature - Make changes and add tests in
workspace/ - Build and run the verification suite:
go build -o blcli ./cmd/blcli && blcli check - Open a Pull Request against
main
Conventional commit prefixes: feat:, fix:, docs:, refactor:, test:
MIT © ggsrc