terraformgrafanacrossplane

Grafana IAC - Dashboard Creation Error - A reference to a resource type must be followed by at least one attribute access specifying the resource name


I'm using Crossplane Grafana provider to create Grafana Dashboards through IAC on my Grafana Cloud instance. I created the Dashboard through the UI, exported the JSON and tried to feed it into the Grafana Dashboard Resource.

Despite I didn't changed anything, I receive the following error message on Kubernetes:

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

This message is repeated several times each retry. No more information.

Couldn't find the .lock file on the Crossplane Grafana Provider Resource through kubectl exec to check if there was any other meaningful message...

I figured out this message is actually a Terraform message, as Crossplane uses Upbound/upjet as a translation layer to Terraform. Not a very helpful one though...


Solution

  • After researching a bit, I figured out that the Terraform error message comes from it trying to interpolate a variable, such as ${resource.field}.

    With this information, looking the 3K line Json I found out that Datasource Variables from Grafana can be pointed at with the following notation: ${env} or $env. When the first happens, it is triggering the Terraform API to force the interpolation.

    To bypass that, Terraform accepts $${env}, which will be interpolated as ${env}, finally being accepted by the Grafana API.

    So, quick fix, add a second $.