How do I reference resources across compositions in Crossplane?
Last updated: November 18, 2025
Context
When working with multiple Crossplane compositions, you may need to reference resources created by one composition in another composition. For example, you might create an S3 bucket using one composition and then need to reference that bucket's ARN when creating a Flink application using a different composition.
Answer
You can reference resources across compositions using Extra Resources functionality in Crossplane. There are two main approaches:
Option 1: Using function-extra-resources
The function-extra-resources allows you to bring any Crossplane resource on the cluster into the function pipeline's context. You can fetch either the target resource directly (like the S3 bucket) or the Composition that created it if the values are available in the composition's status.
With function-extra-resources, you can only match resources by labels using the matchLabels field.
Option 2: Using function-go-templating with built-in resource fetching
The function-go-templating supports calling extra resources directly and provides more flexibility for matching resources.
Here's an example of how to use variables in resource matching with go-templating:
apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1
kind: ExtraResources
requirements:
some-foo-by-name:
# Resources can be requested either by name
apiVersion: example.com/v1beta1
kind: Foo
matchName: "some-extra-foo"
some-foo-by-labels:
# Or by label
apiVersion: example.com/v1beta1
kind: Foo
matchLabels:
app: my-app
some-bar-by-a-computed-label:
# You can also generate them dynamically using the template
apiVersion: example.com/v1beta1
kind: Bar
matchLabels:
foo: {{ .observed.composite.resource.name }}The key advantage of function-go-templating is that you can use variables and dynamic values in the match criteria, unlike function-extra-resources which only supports static label matching.
Sources: function-extra-resources GitHub repository, function-go-templating GitHub repository