<p>I am working on claim that will be used by about 8 services org wide, how do i pass the array of env variables to the composition. There seems to be no way of doing this</p>
<p>Here is an example of my claim</p>
<pre><code>apiVersion: app.org.io/v1
kind: XClaim
metadata:
  name: test-app
spec:
  parameters:
    name: test-app
    envVariables:
    - variables:
        foo: bar
        name: precious
        age: 15
</code></pre>
<p>Here is an example of my CRD</p>
<pre><code>apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
  name: applambdas.app.org.io
  namespace: crossplane-system
spec:
    group: app.org.io
    names:
        kind: AppLambda
        plural: applambdas
    versions:
        - name: v1
          served: true
          referenceable: true
          schema:
            openAPIV3Schema:
              type: object
              properties:
                spec:
                  type: object
                  properties:
                    parameters:
                      type: object
                      properties:
                        env:
                          type: string
                        envVariables:
                          type: array
                        name:
                          type: string

    claimNames:
      kind: XClaim
      plural: xclaims
</code></pre>
<p>Here is an example of my composition</p>
<pre><code>apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: lambda
spec:
  compositeTypeRef:
    apiVersion: app.org.io/v1
    kind: AppLambda
  resources:
    - name: lambda-function
      base:
        apiVersion: lambda.aws.upbound.io/v1beta1
        kind: Function
        metadata:
          annotations:
            uptest.upbound.io/timeout: &quot;3600&quot;
          name: lambda
        spec:
          providerConfigRef:
            name: aws-config
          forProvider:
            handler: index.lambda_handler
            packageType: Zip
            region: eu-west-1
            role: arn:aws:iam::xxxxxx:role/crossplane-lambda-test-role
            runtime: python3.9
            s3Bucket: testappbucket-upbound-provider-test-data
            s3Key: function.zip
            timeout: 60
            environment: []
      patches:
        - fromFieldPath: spec.parameters.envVariables[variables]
          toFieldPath: spec.forProvider.environment[variables]
</code></pre>
<p>The <code>spec.forProvider.environment</code> dosen't seem to get patched, I have been on this all week, please i need help</p>

Precious Okwu
<p>In this case, the environment variables are not actually an array. You can see from the <a href="https://doc.crds.dev/github.com/upbound/provider-aws/lambda.aws.upbound.io/Function/v1beta1@v0.37.0#spec-forProvider-environment-variables" rel="nofollow noreferrer">crd</a> that <code>variables</code> should be the key to an object, stored underneath a single value <code>environment</code> array.</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  forProvider:
    environment:
    - variables:
        key: value
</code></pre>
<p>So with some small tweaks to your definition and composition, this should be possible:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition

...
    envVariables:
      type: object
      additionalProperties:
        type: string
...
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apiextensions.crossplane.io/v1
kind: Composition
...
    patches:
      - fromFieldPath: spec.parameters.envVariables
        toFieldPath: spec.forProvider.environment[0].variables
...
</code></pre>
<p>This will let you create a claim like this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: app.org.io/v1
kind: XClaim
metadata:
  name: test-app
spec:
  parameters:
    name: test-app
    envVariables:
      foo: bar
      name: precious
      age: &quot;15&quot;
</code></pre>
<p>Resulting in a function with the appropriate environment variables set.
<a href="https://i.stack.imgur.com/gctlb.png" rel="nofollow noreferrer">AWS Console Showing Environment Variables</a></p>
<p>Note: Environment Variable values must be strings, which is the reason for the validation in the schema and the quotes in the claim.</p>
