grafana / crossplane-provider-grafana

Crossplane provider of https://github.com/grafana/terraform-provider-grafana
https://marketplace.upbound.io/providers/grafana/provider-grafana
Apache License 2.0
27 stars 14 forks source link

fix(cloud_access_policy): extract 'id' field explicitly for reference #186

Closed Duologic closed 3 weeks ago

Duologic commented 3 weeks ago

We are observing that an AccessPolicy using StackRefSelector has realm.identifier match the slug of a stack while the realm.identifier always expects the id to be extracted.

It's not clear why this happens to me as by default the Extractor field should get populated with the 'external-name':

https://github.com/crossplane/upjet/blob/a18bd41b7ac62be1a6058512a13f8a001c8087d9/pkg/config/resource.go#L191-L194

And in this particular case, the external-name on the stack does seem to match the id BUT in the composition/claim we do set the value of external-name to match the slug as that is what Crossplane initially needs to find the matching stack, this depends on the import using stackSlugOrID. This means it works for the stack resource. Now it is crossplane constantly racing to update the external-name field, when it comes from the claim it'll be the slug, if it comes from the Grafana API it will be the id. Depending on order of reconcilation, the realm.identifier flips values too, explaining why it works 'sometimes'.

Big thanks to @julienduchesne for finding this last bit.

The change in this PR makes the extraction of id explicit now.