platform engineering
The button in Port and the service it makes

The mission for the year was easy to state and slow to finish. Any team should be able to spawn a new service without us in the room. We had spent the previous stretch pulling shared pieces out of a monolith and moving the estate off EC2, and by the time that was working the bottleneck had moved. Writing the Terraform for a new service wasn't hard. What was hard was knowing which repository it went in, which account it deployed to, which module version was current, who to ask for the ECR repository, and which Slack channel to announce it in, and all of that lived in people.
So we put a catalog in front of it. Port held the entities and the forms, GitHub Actions held the work, and AWS Proton held the infrastructure templates. This post is about the first two thirds, the button and what pressing it starts.
One form, one dispatch
A Port self-service action is a JSON schema and a backend. The schema draws the form, and the backend is what happens when someone submits it. For us the backend was always the same, dispatch a workflow in one repository, because the moment there are three ways to launch platform work there are three ways for it to be wrong.
{
"identifier": "create_service",
"title": "Create a service",
"trigger": {
"type": "self-service",
"operation": "CREATE",
"blueprintIdentifier": "service",
"userInputs": {
"properties": {
"name": {
"type": "string",
"title": "Service name",
"pattern": "^[a-z][a-z0-9-]{2,29}$"
},
"template": {
"type": "string",
"title": "Template",
"enum": ["nestjs-http", "worker-sqs", "library"]
},
"needs_infrastructure": { "type": "boolean", "default": true },
"team": { "type": "string", "blueprint": "team", "format": "entity" }
},
"required": ["name", "template", "team"]
}
},
"invocationMethod": {
"type": "GITHUB",
"org": "our-org",
"repo": "platform-actions",
"workflow": "create-service.yml",
"reportWorkflowStatus": true,
"workflowInputs": {
"name": "{{ .inputs.name }}",
"template": "{{ .inputs.template }}",
"needs_infrastructure": "{{ .inputs.needs_infrastructure }}",
"team": "{{ .inputs.team.identifier }}",
"run_id": "{{ .run.id }}",
"requested_by": "{{ .trigger.by.user.email }}"
}
}
}
Two things in there matter more than they look.
pattern on the name is the only validation that happens before anything
exists. That string becomes a repository name, an ECS service name, a Terraform
state key and a DNS label, and every one of those has an opinion about what
characters are legal. Rejecting it in the form costs a person four seconds.
Rejecting it in terraform apply costs a person twenty minutes and leaves a
repository behind.
run_id is how the workflow talks back. Port opens a run when the form is
submitted, and that run is all the requester can see. A workflow that doesn't
write to it gets triggered twice, because from the other side an empty run and
a broken run look identical.
The two things behind it
Every action we shipped fell into one of two buckets, and keeping the buckets apart mattered more than anything else in the design.
Orchestration. Create the repository from a
Cookiecutter template, push the initial
commit, set branch protection and CODEOWNERS, add the repository to the right
teams, register the entity in the catalog, post to Slack. It's all API calls,
it finishes in under a minute and it's cheap to undo.
Infrastructure. An ECS service, a queue, a bucket, a database user, the DNS record, the alarms. These exist in an AWS account, they take minutes instead of seconds, and you can't undo them by deleting a row.
The workflow is one file with that split in the middle of it:
name: create-service
on:
workflow_dispatch:
inputs:
name: { required: true, type: string }
template: { required: true, type: string }
needs_infrastructure: { required: true, type: string }
team: { required: true, type: string }
run_id: { required: true, type: string }
requested_by: { required: true, type: string }
jobs:
scaffold:
runs-on: ubuntu-latest
steps:
- uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
operation: PATCH_RUN
runId: ${{ inputs.run_id }}
logMessage: 'Creating repository ${{ inputs.name }}'
- name: Render the template
run: |
pipx run cookiecutter --no-input \
gh:our-org/service-templates --directory "${{ inputs.template }}" \
service_name="${{ inputs.name }}" owning_team="${{ inputs.team }}"
- name: Create and seed the repository
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: ./scripts/create-repo.sh "${{ inputs.name }}"
provision:
needs: scaffold
if: inputs.needs_infrastructure == 'true'
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.PROTON_CALLER_ROLE }}
aws-region: eu-west-1
- name: Ask Proton for a service
run: |
aws proton create-service \
--name "${{ inputs.name }}" \
--template-name "${{ inputs.template }}" \
--template-major-version 1 \
--spec file://spec.yaml \
--repository-connection-arn "$CONNECTION_ARN" \
--repository-id "our-org/${{ inputs.name }}" \
--branch-name main
The if on the second job is the important line. A shared library needs a
repository, a CI workflow and a place in the catalog, and that's it. A
frontend for an internal tool needs a repository and a Vercel project. Roughly
a third of what people asked the catalog for didn't need an AWS account touched
at all, and if those requests had to wait behind a provisioning path they did
not use, everyone would have learned very quickly that the button is slow.
When it is set, the second job hands the request to Proton and stops without building anything. What happens next (a rendered Terraform pull request, a validation run, an automatic merge, an apply) is the subject of the next two posts. From the workflow's point of view it's fire and forget. That was a design decision and it has a cost, which I will come back to.
Writing back, or the button gets pressed twice
Port updates the run status when the workflow finishes. That's enough for a workflow that takes forty seconds and not nearly enough for one that takes twelve minutes.
We wrote progress into the run at every step boundary: repository created, here is the link; template rendered; Proton service requested, here is the service instance. It reads like logging, but it's the only feedback the requester gets, and what it prevents is duplication. Someone who can't tell whether the thing is working will press the button again, and the second press arrives while the first is half-finished.
Pressing it twice anyway
Someone will press it twice regardless. A double-click, a timeout on Port's side, a person who wasn't sure the first one took. So every action had to survive being run twice with the same inputs, and we got there by making each step check before it acted. We didn't build one clever lock.
Creating the repository is the easy one. GitHub returns 422 if the name is
taken, so the script treats "already exists, and it was created by this
template" as success and anything else as failure. Registering the catalog
entity is an upsert by identifier. Asking Proton for a service that already
exists gives a ConflictException, which we caught and turned into a link to
the existing one.
It isn't elegant. It is a pile of special cases, one per API. It's also the only version of this I have seen work, because the alternative (a lock in the platform's own store, released when the workflow finishes) fails with a stuck lock at 6pm on a Friday.
The name is the one input you cannot take back
Everything else in the form is editable later. The team can change, and so can the instance size and the alarm thresholds. The name can't, because by the time anyone wants to change it the name is in a repository URL, an ECR path, a Terraform state key, a log group, three dashboards and a runbook.
We put the regex in the form, and we should also have put a reserved-word list
next to it. api, service, test, new - the names that are fine in
isolation and useless in a list of sixty. It's a five-line change and I didn't
make it, and I noticed every time I read the catalog.
The form and the schema are the same schema, twice
The Port action carries a JSON schema describing the inputs. The Proton service
template carries a schema.yaml describing the same inputs, in another
repository and another format, and both are maintained by hand.
They drift. Someone adds a parameter to the Proton template, bumps the minor version, and the catalog form doesn't know it exists, so the parameter takes its default forever and the person who added it wonders why nothing changed. Or the form offers a value the template does not accept, and the request dies several minutes later inside a rendered Terraform plan, about the worst place there is to discover a typo.
There should be one source. Proton's schema.yaml is already the
authoritative description of what the template takes, and Port's action can be
created and updated over its API. A small job that reads the registered
template versions and writes the corresponding actions would have removed this
class of problem. We sketched it but never shipped it. The drift was always
slow enough to patch by hand, however much it annoyed us.
Two backends behind every button
Port is a good portal and the forms are pleasant, but the portal is the surface. What made the difference was that there were only two backends behind every button, and one of them was "call Proton and stop".
Before this, spawning a service meant knowing things. Afterwards it meant filling in a form whose fields were the only things you needed to know, and everything behind the the form was either an API call or somebody else's provisioning engine. The number of ways to get it wrong went from "however many people are on the platform team" to two.
The provisioning side was more involved than I expected, and that's where the next post starts. Proton does not apply your Terraform. It opens a pull request and waits for you.


