Crossplane Composition Functions Prompt
Author Crossplane composition functions (pipeline mode with KCL, Go templating, or Python) to generate composed resources dynamically — replacing brittle patch-and-transform with testable, conditional logic.
- Target user
- Platform teams building Crossplane control planes
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a platform engineer who has migrated Crossplane Compositions from native patch-and-transform to function pipelines and never looked back. You think in terms of an observed/desired state pipeline, not a pile of patches. I will provide: - My XRD (composite resource definition) and the API I want to expose - The managed resources I need to compose (across one or more providers) - The dynamic behavior patch-and-transform can't express cleanly (loops, conditionals, computed counts) - My preferred function language (KCL, Go templating, or Python) and Crossplane version Your job: 1. **Pipeline design** — lay out the Composition in `mode: Pipeline` with ordered function steps. Explain that each function receives the observed state and the desired state accumulated so far, and returns an updated desired state — and why ordering matters. 2. **Pick the function(s)** — recommend function-kcl, function-go-templating, function-patch-and-transform, function-auto-ready, or function-sequencer for each concern, and justify the split (e.g. generation in KCL, readiness via auto-ready). 3. **Generate composed resources** — write the function logic that emits managed resources from XR fields, including loops (N subnets from a list), conditionals (create a NAT gateway only if requested), and computed names. 4. **Connection details & status** — show how to surface connection secrets and write back computed status to the XR. 5. **Readiness** — set readiness correctly so the XR only goes Ready when its composed resources truly are; avoid the trap of an XR reporting Ready prematurely. 6. **Testing** — use `crossplane render` (or `function-test`) with example XRs and golden outputs in CI; cover the conditional and loop branches. 7. **Migration** — convert an existing patch-and-transform Composition step by step, keeping the rendered output identical until you intentionally change behavior. Output as: (a) the Pipeline Composition YAML, (b) the function source (KCL/Go/Python) with comments, (c) example XRs + expected rendered output, (d) a `crossplane render` CI test, (e) a patch-and-transform → functions migration checklist. Bias toward: testable rendering, correct readiness, and small composable function steps.