crossplane / upjet

A code generation framework and runtime for Crossplane providers
Apache License 2.0
271 stars 78 forks source link

Support multiple reference Types #95

Open donovanmuller opened 1 year ago

donovanmuller commented 1 year ago

What problem are you facing?

Currently, you can add a single, explicit reference, to another resource like this example for google_cloud_scheduler_job:

    p.AddResourceConfigurator("google_cloud_scheduler_job", func(r *config.Resource) {
        r.References["pubsub_target.topic_name"] = config.Reference{
            Type: "github.com/upbound/official-providers/provider-gcp/apis/pubsub/v1beta1.Topic",
        }
    })

However, some resources can accept references for multiple Types. In the example above, Both a Topic and a LiteTopic are supported. Upjet currently does not allow multiple references, of different Types, for a single argument.

How could Terrajet help solve your problem?

Allow specifying multiple supported reference Types for an argument. E.g.

    p.AddResourceConfigurator("google_cloud_scheduler_job", func(r *config.Resource) {
        r.References["pubsub_target.topic_name"] = []config.Reference{
            config.Reference{
                Type: "github.com/upbound/official-providers/provider-gcp/apis/pubsub/v1beta1.Topic",
            },
            config.Reference{
                Type: "github.com/upbound/official-providers/provider-gcp/apis/pubsub/v1beta1.LiteTopic",
            },
        }

Terrajet community example here.

csantanapr commented 1 year ago

I hit this problem today with the SubscriptionFilter

The filter takes a destinationArnRef or destinationArnSelector is based on [destinationArn](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutSubscriptionFilter.html#API_PutSubscriptionFilter_RequestSyntax) The ARN of the destination to deliver matching log events to. Currently, the supported destinations are:

I want to create a subscription for destination to Kinesis Data Firehose but only Amazon Kinesis stream is supported

I tried the following, having a Delivery system with labels

apiVersion: firehose.aws.upbound.io/v1beta1
kind: DeliveryStream
metadata:
  labels:
    crossplane.io/claim-name: test-logs-firehose-s3-lambda
    crossplane.io/claim-namespace: default
    firehoseapps.awsblueprints.io/app: firehose

...

I create a subscription with destinationArnSelector

apiVersion: cloudwatchlogs.aws.upbound.io/v1beta1
kind: SubscriptionFilter
metadata:
  name: dynatrace-aws-logs-test
spec:
  forProvider:
    destinationArnSelector:
      matchLabels:
        crossplane.io/claim-name: test-logs-firehose-s3-lambda
        crossplane.io/claim-namespace: default
        firehoseapps.awsblueprints.io/app: firehose
    filterPattern: ""
    logGroupName: "/aws/eks/crossplane-blueprints/cluster"
    name: "dynatrace-aws-logs-test"
    region: "us-east-1"
...

I get error

    message: 'cannot resolve references: mg.Spec.ForProvider.DestinationArn: no resources
      matched selector'
    reason: ReconcileError
turkenh commented 1 year ago

I am afraid this is a limitation of how Cross Resource References are designed and implemented in Crossplane. Resource references are defined at build time and to only one other type.

Generic Cross-Resource References would be the solution for the problem described here and is one of our top priorities.

If your resources exist in the same composition, you can patch the value as a workaround today.