crossplane-runtime icon indicating copy to clipboard operation
crossplane-runtime copied to clipboard

Cross-resource references to handle multiple types

Open muvaf opened this issue 3 years ago • 4 comments

What problem are you facing?

There are fields in some resources that could be fulfilled by different types, i.e. ARN of Instance or NetworkInterface or LoadBalancer could be given. However, cross-resource resolver always works with a singe hard-coded type so you have to use composition to patch those fields.

How could Crossplane help solve your problem?

We could either solve this via generic patching or implement https://github.com/crossplane/crossplane-runtime/issues/341 and have per-type resolver logic in the code so that we don't have to ask for fieldpaths, transforms etc.

muvaf avatar Aug 30 '22 06:08 muvaf

When creating an Opsgenie Escalation the recipient type can be either user, team or schedule, but Crossplane only supports a single cross-resource reference per "block", in this case rules.recipient.

Below is an example on how it could look like with multi cross-resource reference.

...
spec:
  forProvider:
    name: Escalation Name
    rules:
      - recipient:
          - type: user
            userIdRef:
              name: user-name

          - type: team
            teamIdRef:
              name: team-name

          - type: schedule
            scheduleIdRef:
              name: schedule-name

Terraform example.

resource "opsgenie_escalation" "test" {
  name          = "genieescalation-%s"
  description   = "test"
  owner_team_id = "${opsgenie_team.test.id}"

  rules {
    condition   = "if-not-acked"
    notify_type = "default"
    delay       = 1

    recipient {
      type = "user"
      id   = "${opsgenie_user.test.id}"
    }

    recipient {
      type = "team"
      id   = "${opsgenie_team.test.id}"
    }

    recipient {
      type = "schedule"
      id   = "${opsgenie_schedule.test.id}"
    }
  }

https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs/resources/escalation

Kerwood avatar Sep 05 '22 12:09 Kerwood

the same we have in provider-pagerduty

    rule:
    - escalationDelayInMinutes: 10
      target:
      - id: ${pagerduty_user.example.id}
        type: user_reference
      - id: ${pagerduty_user.example2.id}
        type: user_reference

haarchri avatar Apr 11 '23 21:04 haarchri

in official-provider upbound/provider-aws we can see the same

https://marketplace.upbound.io/providers/upbound/provider-aws-directconnect/v0.36.0/resources/directconnect.aws.upbound.io/GatewayAssociation/v1beta1#doc:spec-forProvider-associatedGatewayId

associatedGatewayId is possible to match multiple resource types

today its only possible to select / reference one resource type https://marketplace.upbound.io/providers/upbound/provider-aws-directconnect/v0.36.0/resources/directconnect.aws.upbound.io/GatewayAssociation/v1beta1#doc:spec-forProvider-associatedGatewayIdRef

haarchri avatar Jun 21 '23 11:06 haarchri

Crossplane does not currently have enough maintainers to address every issue and pull request. This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 14 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

github-actions[bot] avatar Sep 03 '24 09:09 github-actions[bot]