Platform · Earlier generation

Five-Minute Customer Onboarding: Forms, Workspaces and a Subnet Allocator

The earlier generation of the pipeline: form submissions picked up by a scheduled workflow that creates workspaces and config per customer.

  • Google Forms
  • Apps Script
  • Python
  • Terraform Cloud
  • Consul/Vault KV
  • GitHub Actions
  • GCP Shared VPC

// Why this matters

A form-driven Terraform Cloud workspace factory is the quickest honest route from "a ticket per customer" to "a request becomes an environment". Before you build the full pipeline of From Form to Running Cluster: Self-Service Team Onboarding, this is what the minimal version looks like: a form, a script, a scheduler and one workspace per tenant.

It is worth studying for two reasons. First, it shows how little machinery is needed to remove humans from the repetitive path: roughly one Apps Script, one Python program, one CSV inventory and a cron. Second, it exposes the design choices that later had to be made stricter: how network space is allocated, how upper environments are gated, and how clean-up works.

This post documents the prototype as a reference implementation you can reproduce with your own cloud, and ends with what to change if you take it to production.

// The problem

Customers needed repeatable multi-project environments on a shared VPC. Each environment requires a workspace (state, variables, VCS trigger), a configuration set, and a subnet from a shared network that no other customer holds. Doing that by hand takes a platform engineer away from higher-value work, and a typo in a subnet name silently gives two customers the same range.

Shared VPC makes allocation harder than it looks. The subnets were created ahead of time in the host project, so allocation is not "make a subnet", it is "pick one that exists, in the right region, that nobody has and that was actually created". Mark it taken in one place or you will hand it out twice.

Finally, lower and upper environments need different risk postures, and teardown needs the same automation as setup. An auto-apply workspace on upper is an outage waiting for a typo, and a customer clean-up that is a wiki page is a clean-up that does not happen.

// The solution

The pipeline has five moving parts. A form trigger fires an Apps Script that appends the response to a per-customer temporary sheet, transposes columns into rows (so the CSV is key,value pairs), pushes it to a repository folder through the GitHub contents API, and deletes the sheet. A scheduled workflow, running every five minutes in an active window, moves new CSVs from the inputs folder to a working folder and runs a Python program. The program merges standard keys with the customer's values, allocates subnets from the inventory CSV, writes everything to the key-value store, and creates or updates the Terraform Cloud workspace through its API. Finally the processed CSV is archived with a timestamp and committed.

The commit is itself a trigger. The workspace is created with a VCS trigger prefix on the customer's archive path, so the archive commit queues a run in that workspace. That is how a file move becomes an infrastructure change with no extra plumbing. Execution mode, auto-apply and notification are workspace attributes set at creation, which is where the lower/upper policy lives: lower workspaces auto-apply, upper workspaces do not and notify chat for approval.

Subnet allocation is a CSV inventory with available and created columns. The allocator filters on region, available == 1 and created == 1, takes the first row, flips it, and writes the subnet, pod range, service range and master range into the key-value store as keys for the Terraform root to read. If there is none, it fails fast with a clear error naming the region, because proceeding without a subnet would produce a workspace that can never apply.

Alternatives rejected: a web portal with a database (more to run and secure for the same outcome), and creating subnets on demand (the host project's network is shared and subnet creation there needs elevated rights I did not want the pipeline to hold). The result was deliberately a prototype: it proved the model that was later rebuilt on a different cloud with subscriptions and stronger gates (Subscription Factory: Customer Onboarding That Starts by Minting Subscriptions).

How it flows flow1. Form submit → 2. Transpose and commit → 3. Scheduled pick-up → 4. Merge → 5. Allocate → 6. Create workspace → 7. Gate: environment policy → 8. Archive → 9. Clean-up form01Form submit02Transpose and commit03Scheduled pick-up04Merge05Allocate06Create workspace07 · GATEGate: environmentpolicy08Archive09Clean-up form
How it flows. End-to-end flow. Dashed pink nodes are gates: points where a human or a check must pass before the next stage runs.
  1. Form submita trigger fires Apps Script
  2. Transpose and commitsheet to rows, pushed to an inputs folder
  3. Scheduled pick-upworkflow every 5 minutes in an active window
  4. Mergecustomer inputs plus standard keys
  5. Allocatefirst available subnet per region from the inventory, marked used
  6. Create workspaceworkspace and config written
  7. Gate: environment policy gatelower auto-applies, upper needs approval
  8. Archiveinputs archived per customer
  9. Clean-up formmesh cleanup, destroy, release subnets, delete config
FormApps ScriptGit repoScheduled workflowTF Cloudon submit triggertransposed CSV to inputs folderevery 5 min: pick up new CSVscreate workspace, set variables, auto-apply by envarchive CSV, commit under trigger prefixVCS trigger queues a run
Form to workspace. A submission becomes a CSV, then config, then a queued Terraform run; the scheduler and the archive commit are the glue.
IntakeGoogle FormApps ScriptCSV in GitSchedulerCron workflowActive windowClean-up windowAllocator and configSubnet inventory CSVStandard keysKV storeExecutionWorkspace per customerLower auto-applyUpper approval
Prototype layers. Four small layers; each can be replaced independently.

// Before you start

  • A Terraform Cloud (or compatible) organisation with an API token that can create workspaces and variables, and a VCS connection to your infrastructure repository.
  • A Google Workspace account to own a Form, its response sheet and a bound Apps Script project.
  • A GitHub repository with an inputs folder, an archive folder and a token that can commit via the contents API.
  • A key-value store the Terraform root can read (Vault KV or Consul), and Python 3.10+ with requests, pandas and hvac.
  • A pre-created pool of subnets in the shared VPC host project, listed in an inventory CSV.

// Step-by-step implementation

  1. 01 Write the Apps Script: temp sheet, transpose, push to Git

    On each submission the script copies the last response into a new sheet named after the customer, with a header row. It then transposes that sheet so the first column is the key and the second the value; this gives a CSV that diffs well and is trivial to parse. Pushing uses the GitHub contents API with a token stored in script properties. The temporary sheet is deleted afterward, so the response spreadsheet never grows one sheet per customer.

    Keep the script thin. Validation belongs in the form (regex on the name question, choices for regions) and in the Python program, not in script logic that nobody tests.

  2. 02 Schedule the pick-up in an active window

    The scheduler is a cron workflow. Every five minutes inside an active window (so it does not poll overnight), it moves CSVs from the inputs folder into a working folder, creates the matching archive folder, and runs the Python program. A manual workflow_dispatch stays enabled for replays. A separate workflow with its own cron handles clean-up requests every fifteen minutes so the two cannot block each other.

    Move the files before running the program, and archive after, so a crash leaves the CSV in the working folder for the next tick. Make the commit step tolerant of "nothing to commit" so empty ticks stay green.

  3. 03 Build the subnet allocator from a CSV inventory

    The inventory is a CSV with one row per pre-created subnet: name, region, address range, pod range, service range, master range, and two flags. created says the subnet really exists in the host project; available says nobody holds it. The allocator filters on region and both flags, takes the first row, sets available to 0, and returns the values. Writing the inventory back is part of the same job as writing config, and the whole run holds the scheduler concurrency lock, so two requests cannot race.

    Fail fast and loudly when a region has no free subnet. A workspace created without one can never apply and creates support work.

  4. 04 Merge standard keys with the customer CSV and write config to the store

    The Python program reads the customer's CSV (first row gives the workspace name), loads the standard key defaults, lets the customer values overwrite, runs the allocator per requested region, and writes each key to the store. Using one secret per key keeps edits and rollbacks per setting (the reasoning is in Vault as the Control Plane: A Five-Tier Key Model with Locking).

    Make the writes idempotent. If the workspace or keys already exist, update them rather than failing, because the scheduler will reprocess a file after a partial failure.

  5. 05 Create the workspace through the API with environment-specific policy

    Creating a workspace is a single POST. Set the working directory to the lower or upper root, a VCS trigger prefix scoped to this customer's archive folder (so only their archive commits start runs), and auto-apply true for lower and false for upper. Then set workspace variables: the customer name as a Terraform variable and credentials as sensitive environment variables.

    Check for an existing workspace first and update it if present. If you let the create fail with "already exists", re-processing becomes an error path instead of a no-op.

  6. 06 Notify chat for upper approval and check required environment up front

    Because upper does not auto-apply, someone has to know a plan is waiting. Post a message to a channel with the workspace name and a link when an upper workspace is created. Keep this best-effort: a notification failure must not fail onboarding.

    Check required environment variables at program start and exit with a single message listing what is missing. In a scheduled job, a half-configured run is worse than a loud one, because it produces partial workspaces.

  7. 07 Add the clean-up path: return subnets and delete config

    Teardown gets its own form and its own window. The clean-up workflow reads the request, destroys infrastructure (including mesh clean-up), returns the customer's subnet rows to available == 1 and clears assigned_to, then deletes the customer's keys from the store and removes the workspace. Running it every fifteen minutes in its own window keeps it from competing with intake.

    Return the subnet only after the destroy has succeeded. The Azure generation encoded this as a hard guard (see Demolition in Dependency Order: Safe, Re-runnable Offboarding); in the prototype it was a convention, which is the first thing worth tightening.

// How to verify it works

  • Submit the form with a throwaway name. Expected: within a few minutes a customer_inputs/<name>.csv commit appears, then moves to inputs/ and finally archive/<name>/ with a timestamp.
  • Check the inventory CSV diff: exactly one row flipped to available = 0 with assigned_to set, for each requested region.
  • In the workspace list, a lower workspace exists with auto-apply on and a run queued by the archive commit; an upper workspace exists with auto-apply off and a chat message posted.
  • Reprocess the same CSV. Expected: the workspace is found rather than created, keys are updated in place, and no second subnet is allocated for the same customer and region.
  • Run the clean-up request. Expected: destroy succeeds, rows return to available = 1, keys and workspace are gone.

// Design decisions and trade-offs

  • Auto-apply is off in upper environments.
  • Availability flags prevent subnet reuse; the pipeline fails fast if no subnet is free for a region.
  • Clean-up runs in its own window every 15 minutes.
  • Required environment variables are checked at start.

// Pitfalls and lessons learned

  • Not recording who holds a subnet. A bare available flag cannot be reconciled with reality; add an assigned_to column.
  • Auto-apply on upper. A typo in a CSV becomes an upper change with no human in the loop; keep it off and notify.
  • Allocating a subnet that does not exist. The created flag exists because inventory rows are added before the host project subnet is; filter on both.
  • Sharing one cron lock between intake and clean-up. A long destroy then blocks new customers; use separate windows and groups.
  • Long-lived cloud keys as workspace variables. They were expedient and are the first thing to replace with federation.
  • Storing the commit token inside the script text. Use script properties and a repository-scoped token.
  • Treating a file move as harmless. The archive commit triggers a run via the prefix; mis-scoped prefixes can trigger the wrong workspace.

// Frequently asked questions

How do I create a Terraform Cloud workspace from code?

POST to /organizations/<org>/workspaces with name, working directory, execution mode, auto-apply and vcs-repo attributes, then POST workspace variables. Check for an existing workspace first so the call is idempotent.

How do I make a Google Form trigger a GitHub Actions pipeline?

Use an onFormSubmit Apps Script that writes a file to the repository through the GitHub contents API, and have a workflow pick up new files on a schedule or on a push to that path.

Why auto-apply only in lower?

Lower failures are cheap and fast feedback is valuable; upper changes need a human to read the plan, so keep auto-apply off and notify the approver.

How do I allocate shared VPC subnets without collisions?

Keep a single inventory of pre-created subnets with availability and created flags, allocate the first matching row inside a serialised job, and return it only after a successful destroy.

What should I change before using this in production?

Replace long-lived credentials with federation, add environment approvals in the CI system, guard the subnet release on destroy results, and move to the staged design in the later platform generation.

// The outcome

The prototype that proved the model later rebuilt on Azure with stronger gates.

// Where to take it next

// Keep reading