grafana / crossplane-provider-grafana

Crossplane provider of https://github.com/grafana/terraform-provider-grafana. Generated by https://github.com/upbound/upjet
Apache License 2.0
26 stars 14 forks source link

Terraform Interpolation inside the Dashboard ConfigJson Field. #59

Closed MasterExecuson closed 7 months ago

MasterExecuson commented 8 months ago

What I'm trying to do:

Create a dashboard, originaly created through UI and exported as JSON, using Crossplane Grafana Provider. The dashboard has 3K lines, multiple variables, including Datasource Variables.

What I'm facing:

The Datasoruce variable created in the UI uses the notation ${env}, which is clashing with Terraform Interpolation variables, generating a very unhelpfull error message:

Invalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name

What I expect to happen:

I expect that any dashboard exported through the UI can be crerated using the Crossplane Provider without modifications. In this case, I expect the provider to bypass the Terraform interpolation by default.

I would propose to make a regex replace function that replaces the ${ with $${. As this change would impact any user that had fixed this issue manually, I also would propose to consider not replacing if there is a $ before ${. The final Regex would look something like this: (?<!\$)\${ or (?P<char>[^$])${ ...

Interim Containment Action

Terraform accepts $${env} as a way to bypass it's interpolation. Meanwhile I had to replace all ${env} with the double $.

MasterExecuson commented 8 months ago

I also posted the Interim solution on Stackoverflow.