Platform · Freelance

Kubernetes-Native Self-Service Infrastructure with Crossplane

Crossplane compositions let teams request S3, RDS and EKS through custom claims backed by Terraform modules and GitOps.

  • Crossplane
  • provider-terraform
  • provider-aws
  • Terraform
  • Argo CD
  • EKS
  • RDS
  • S3

// Why this matters

Crossplane self-service infrastructure answers a question most platform teams hit within a year: how do we let developers get a bucket or a database without giving them cloud consoles or teaching them Terraform, and without us becoming a ticket queue? Crossplane makes the answer a Kubernetes API you design, with guardrails baked in.

The pragmatic twist in this article is using Crossplane as a facade over Terraform you already have. Rewriting a library of working, reviewed modules into native managed resources is a large and risky project. The Terraform provider lets a composition run those modules as workspaces, so you keep your investment and still present developers with a clean claim.

Add GitOps on top and you get what most people actually want: a pull request that adds a small YAML file, a reviewer who sees exactly what is being requested, and a controller loop that makes it true and keeps it true.

// The problem

Without a platform layer, infrastructure requests go one of two ways. Either developers run Terraform themselves, with broad credentials, inconsistent module versions and state files in odd places, or they file tickets and wait. Both fail at scale: the first loses control, the second loses speed.

A native Kubernetes experience was the ask. The constraints: parameters had to be few and validated (a bucket request should not expose forty options), cloud credentials must stay with the platform and never reach developers, outputs such as connection details should come back as Kubernetes secrets in the requesting namespace, and the existing Terraform modules had to be reused.

There is also a trap in the Terraform provider model: a workspace is long-lived state. If state backends and workspace names are not planned, two claims can collide, and deleting a claim might orphan or destroy the wrong thing.

// The solution

The design has four pieces. Providers: the AWS provider for native managed resources, and the Terraform provider for running modules, each with a ProviderConfig that references credentials stored as Kubernetes secrets in the Crossplane namespace. XRD: a CompositeResourceDefinition that declares the composite type, the namespaced claim kind and an OpenAPI schema with required parameters. Composition: maps claim fields to the inputs of a Terraform Workspace. Claim: the thing developers write.

A workspace sources its module from a git reference (remote) or inline HCL. Remote modules are the right default because they are versioned and reviewed in their own repository. State lives in a remote backend with a workspace key prefix, so each composite gets its own state object and a deleted claim removes only its own resources. Outputs written by the module flow to a connection secret that lands in the claim namespace.

Selection is by label. The composition carries labels such as provider and team, and the claim picks with a compositionSelector. That is how you offer several implementations of the same claim (a team-specific bucket with its own tags and policies, or a different cloud) without changing the developer-facing contract.

On top of this, Argo CD applications watch a directory of claims and apply them with automated sync, pruning and self-healing. Alternatives we weighed: native managed resources only (cleanest, but a rewrite), and a Terraform controller outside Crossplane (works, but loses the claim and composition abstractions). Note that newer Crossplane versions prefer composition functions (pipeline mode) over the resource-array patch style shown here; the XRD and claim layers do not change, and the patch logic moves into a function.

How it flows flow1. Provider setup → 2. XRD → 3. Composition → 4. Claim → 5. Terraform workspace → 6. Connection secret → 7. Argo CD01Provider setup02XRD03Composition04Claim05Terraform workspace06Connection secret07 · GATEArgo CD
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. Provider setupAWS and Terraform provider configs
  2. XRDcomposite type, claim kind and validated parameter schema
  3. Compositionpatches map claim fields to a Terraform workspace
  4. Claimnamespaced request
  5. Terraform workspaceremote git module or inline HCL, state in S3
  6. Connection secretoutputs written back to a Kubernetes secret
  7. Argo CD gateautomated sync, prune and self-heal
DeveloperClaimCrossplaneTerraform workspaceCloudapply namespaced claim (via git)validated against XRD schemacomposition renders a workspace with patched varsterraform apply of the module, state in remote backendoutputs written to a connection secretReady condition true
From claim to cloud resource. The developer only touches the first and last arrows.
Developer APINamespaced claimFew validated fieldsPlatform contractXRD schemaComposition labelsImplementationComposition and patchesTerraform workspaceReused assetsReviewed Terraform moduleRemote state backendDeliveryArgo CD syncPrune and self-heal
Abstraction layers. Each layer hides the one below it.

// Before you start

  • A Kubernetes cluster (kind is fine to start) with Helm and kubectl, and cluster-admin for the install.
  • Crossplane installed from its Helm chart, plus the AWS and Terraform provider packages at pinned versions.
  • A Terraform module in git that creates what you want to offer (a bucket in this article) with a remote backend block.
  • A cloud identity for the providers. Use a role with a narrow policy; the credential is stored as a Kubernetes secret by your own secure process, never committed.
  • Argo CD installed if you want the GitOps layer.

// Step-by-step implementation

  1. 01 Install Crossplane and the two providers

    Install the core with Helm, then declare providers as packages. Pin versions: the alpha and master tags that tutorials often use will change under you. Wait for the providers to report Healthy before creating any config, otherwise the CRDs you reference do not exist yet.

  2. 02 Configure the Terraform provider with credentials from secrets

    The ProviderConfig tells the Terraform provider how to authenticate to the cloud and, if modules come from private git, how to clone. Both come from secrets that you create out of band. The configuration block is plain Terraform provider config, so it can also pin the region and default tags for everything the workspaces create.

    Create the secrets with your normal secret tooling (an external secrets operator is ideal). Do not template credentials into git.

  3. 03 Define the claim contract with an XRD

    The XRD is the API you are publishing. Keep it small and typed. Required fields are enforced by the API server, so a missing parameter fails at kubectl apply with a clear message rather than inside a Terraform run ten minutes later. Use enums for fields with a closed set of values, which is also free documentation.

  4. 04 Write the Terraform module the composition will run

    The module is ordinary Terraform with input variables matching what the composition passes and outputs matching the connection secret keys. Keep the policy opinions here: public access blocked, versioning configurable, encryption on. Because the developer cannot reach these settings through the claim, the guardrails are structural.

    Note the ACL resource pattern from older tutorials is discouraged on new buckets; block public access and use bucket policies instead.

  5. 05 Compose: patch claim fields into a workspace

    The composition declares one resource, a Workspace, whose module source is a pinned git reference. Patches copy fields from the composite onto the workspace variables. Matching by index (vars[0]) is brittle: reorder the list and the patches silently point at the wrong variable. Where you can, give each var a stable position and comment it, or move to a function that builds the list by name.

    The labels on the composition are what claims select on. Add team or environment labels when you want different implementations.

  6. 06 Submit a claim and read the connection secret

    The claim lives in the developer namespace. It references a composition by label and writes its connection secret into the same namespace, which is how the application finds the bucket name without anyone copying values around.

  7. 07 Deliver claims through Argo CD with prune and self-heal

    Point an Argo CD Application at a directory of claims. Automated sync applies new files, prune deletes claims whose files are removed (and Crossplane then tears down the cloud resource), and self-heal reverts manual edits. Prune on cloud resources is powerful, so protect anything stateful with a deletion policy and by keeping force-destroy off.

    Use one Application per team namespace so permissions and sync blast radius match your ownership boundaries.

// How to verify it works

  • kubectl get providers shows both providers Installed and Healthy; kubectl get xrd shows the XRD Established.
  • Submitting a claim without bucketName is rejected by the API server with a schema validation error.
  • kubectl -n team-a get storagebucket reports Ready True and the cloud console shows the bucket with public access blocked and versioning on.
  • Check the remote state bucket: a state object exists under the workspace key prefix for this composite only.
  • Delete the claim file from git: Argo prunes the claim, the workspace destroys the bucket (empty buckets only), and the state object is cleaned up.

// Design decisions and trade-offs

  • The claim hides Terraform details and fixes labels used for composition selection.
  • Existing Terraform modules are reused rather than rewritten.
  • Remote state per workspace; GitOps reconciliation.

// Pitfalls and lessons learned

  • Patching workspace variables by list index silently breaks when the list is reordered. Comment indices or use a function.
  • Tutorials pin provider packages to moving tags such as master or alpha; pin exact versions.
  • Credentials in a ProviderConfig secret are long-lived. Prefer workload identity and rotate whatever remains.
  • A shared backend key without a workspace prefix lets two composites fight over one state file.
  • force_destroy true plus Argo prune means a deleted file can delete data. Default it to false and keep it out of the claim for stateful types.
  • Workspaces run terraform in a pod; a slow module or large provider download makes claims sit in Creating for minutes. This is normal, but set expectations.
  • Remote modules from private git need a credentials file in the provider config, or the workspace fails with a clone error that is easy to misread as a network problem.

// Frequently asked questions

What is Crossplane self-service infrastructure?

A platform pattern in which developers request cloud resources through custom Kubernetes resources (claims) that platform-owned compositions turn into real infrastructure with guardrails.

Can Crossplane run my existing Terraform modules?

Yes, through provider-terraform. A composition renders a Workspace that points at a module and passes variables from the claim.

What is the difference between an XRD, a composition and a claim?

The XRD defines the API schema, the composition defines how an instance of it is built, and the claim is a developer-facing request for one instance.

Do I need Argo CD?

No, but GitOps gives review, history and drift correction. See Who Deploys the Deployer? Terraform-Bootstrapped FluxCD for the Flux equivalent.

How does this compare with form-driven provisioning?

A claim is the declarative cousin of a form. Compare Five-Minute Customer Onboarding: Forms, Workspaces and a Subnet Allocator and From Form to Running Cluster: Self-Service Team Onboarding.

// The outcome

A developer-facing API for infrastructure with platform-owned guardrails.

// Where to take it next

// Keep reading