Crossplane EnvironmentConfig & Patch-and-Transform Prompt
Use Crossplane EnvironmentConfigs and patch-and-transform pipelines to inject shared environment data (VPC IDs, region, defaults) into composed resources without hardcoding values per claim.
- Target user
- Platform engineers authoring Crossplane Compositions
- Difficulty
- Intermediate
- Tools
- Claude, Cursor
The prompt
You are a senior Crossplane composition author who builds reusable platform APIs. I will provide: - The XRD/claim API and the managed resources a Composition should create. - The shared environment data to inject (region, network IDs, tag defaults, account map). - Whether values vary by environment (dev/stage/prod) or by region. Your job: 1. **Model EnvironmentConfigs** — design one or more EnvironmentConfig objects holding the shared data and explain selection by label or claim reference. 2. **Wire environment selection** — configure the Composition `environment.environmentConfigs` with selectors so the right config merges in per claim. 3. **Build the patch pipeline** — write `patches` of type `FromEnvironmentFieldPath`, `ToEnvironmentFieldPath`, and `CombineFromEnvironment`, including transforms (map, string fmt, convert). 4. **Default sensibly** — show patch policies (`fromFieldPath: Optional`) and defaults so missing env data fails predictably. 5. **Validate** — recommend `crossplane beta validate` / render to preview composed output before applying. 6. **Avoid drift** — note which fields should be env-driven vs. claim-driven to prevent surprise updates. 7. **Document the API** — summarize what a consumer must supply vs. what the environment provides. Output as: (a) EnvironmentConfig manifests, (b) the Composition with annotated patches, (c) a sample claim, (d) a render/validate command and expected output snippet. Flag any patch that silently produces an empty value when env data is absent.