Dashboards with templating results in terraform error
kkendzia opened this issue · 1 comments
kkendzia commented
Hi,
so I try to get the provider running with templated dashboards.
apiVersion: oss.grafana.crossplane.io/v1alpha1
kind: Dashboard
metadata:
name: cluster-dashboard
spec:
forProvider:
folderRef:
name: folder
configJson: |
{
"title": "Crossplane Test!",
"uid": "crossplane",
"panels": [
{
"collapsed": false,
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"panels": [],
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"refId": "A"
}
],
"title": "Workloads",
"type": "row"
}
],
"templating": {
"list": [
{
"hide": 2,
"name": "DS_PROMETHEUS",
"query": "prometheus",
"type": "datasource"
}
]
}
}
providerConfigRef:
name: grafana-provider
The provider-grafana pod results in following error:
1.6877711267468488e+09 DEBUG provider-grafana refresh ended {"workspace": "/tmp/2f2cc928-804a-4804-9c52-6d8679d99350", "out": "{\"@level\":\"info\",\"@message\":\"Terraform 1.3.9\",\"@module\":\"terraform.ui\",\"@timestamp\":\"2023-06-26T09:18:46.258756Z\",\"terraform\":\"1.3.9\",\"type\":\"version\
",\"ui\":\"1.0\"}\n{\"@level\":\"error\",\"@message\":\"Error: Invalid reference\",\"@module\":\"terraform.ui\",\"@timestamp\":\"2023-06-26T09:18:46.742140Z\",\"diagnostic\":{\"severity\":\"error\",\"summary\":\"Invalid reference\",\"detail\":\"A reference to a resource type must be followed by at least one att
ribute access, specifying the resource name.\",\"range\":{\"filename\":\"main.tf.json\",\"start\":{\"line\":9,\"column\":19,\"byte\":377},\"end\":{\"line\":9,\"column\":32,\"byte\":390}},\"snippet\":{\"context\":\"resource.grafana_dashboard.cluster-dashboard\",\"code\":\"{\\\"provider\\\":{\\\"grafana\\
\":{\\\"auth\\\":\\\"REDACTED\\\"}},\\\"resource\\\":{\\\"grafana_dashboard\\\":{\\\"cluster-dashboard\\\":{\\\"config_json\\\":\\\"{\\\\n \\\\\\\"title\\\\\\\": \\\\\\\"Crossplane Test!\\\\\\\",\\\\n \\\\\\\"uid\\\\\\\": \\\\\\\"crossplane\\\\\\\",\\\\n \\\\\\\"panels\\\\\\\": [\\\\n {\\\\n
\\\\\\\"collapsed\\\\\\\": false,\\\\n \\\\\\\"datasource\\\\\\\": {\\\\n \\\\\\\"type\\\\\\\": \\\\\\\"prometheus\\\\\\\",\\\\n \\\\\\\"uid\\\\\\\": \\\\\\\"${DS_PROMETHEUS}\\\\\\\"\\\\n },\\\\n \\\\\\\"gridPos\\\\\\\": {\\\\n \\\\\\\"h\\\\\\\": 1,\\\\n \\\\\\\"w\\\\\
\\": 24,\\\\n \\\\\\\"x\\\\\\\": 0,\\\\n \\\\\\\"y\\\\\\\": 0\\\\n },\\\\n \\\\\\\"panels\\\\\\\": [],\\\\n \\\\\\\"targets\\\\\\\": [\\\\n {\\\\n \\\\\\\"datasource\\\\\\\": {\\\\n \\\\\\\"type\\\\\\\": \\\\\\\"prometheus\\\\\\\",\\\\n \\\\\\\"
uid\\\\\\\": \\\\\\\"${DS_PROMETHEUS}\\\\\\\"\\\\n },\\\\n \\\\\\\"refId\\\\\\\": \\\\\\\"A\\\\\\\"\\\\n }\\\\n ],\\\\n \\\\\\\"title\\\\\\\": \\\\\\\"Workloads\\\\\\\",\\\\n \\\\\\\"type\\\\\\\": \\\\\\\"row\\\\\\\"\\\\n }\\\\n ],\\\\n \\\\\\\"templating\\\\\\\": {\
\\\n \\\\\\\"list\\\\\\\": [\\\\n {\\\\n \\\\\\\"hide\\\\\\\": 2,\\\\n \\\\\\\"name\\\\\\\": \\\\\\\"DS_PROMETHEUS\\\\\\\",\\\\n \\\\\\\"query\\\\\\\": \\\\\\\"prometheus\\\\\\\",\\\\n \\\\\\\"type\\\\\\\": \\\\\\\"datasource\\\\\\\"\\\\n }\\\\n ]\\\\n }\\\\n}\\\\n\\
\",\\\"folder\\\":\\\"2\\\",\\\"lifecycle\\\":{\\\"prevent_destroy\\\":true}}}},\\\"terraform\\\":{\\\"required_providers\\\":{\\\"grafana\\\":{\\\"source\\\":\\\"grafana/grafana\\\",\\\"version\\\":\\\"1.39.0\\\"}}}}\",\"start_line\":9,\"highlight_start_offset\":377,\"highlight_end_offset\":390,\"values\":[]}}
,\"type\":\"diagnostic\"}\n{\"@level\":\"error\",\"@message\":\"Error: Invalid reference\",\"@module\":\"terraform.ui\",\"@timestamp\":\"2023-06-26T09:18:46.742812Z\",\"diagnostic\":{\"severity\":\"error\",\"summary\":\"Invalid reference\",\"detail\":\"A reference to a resource type must be followed by at least
one attribute access, specifying the resource name.\",\"range\":{\"filename\":\"main.tf.json\",\"start\":{\"line\":22,\"column\":23,\"byte\":625},\"end\":{\"line\":22,\"column\":36,\"byte\":638}},\"snippet\":{\"context\":\"resource.grafana_dashboard.cluster-dashboard\",\"code\":\"{\\\"provider\\\":{\\\
"grafana\\\":{\\\"auth\\\":\\\"REDACTED\\\"}},\\\"resource\\\":{\\\"grafana_dashboard\\\":{\\\"cluster-dashboard\\\":{\\\"config_json\\\":\\\"{\\\\n \\\\\\\"title\\\\\\\": \\\\\\\"Crossplane Test!\\\\\\\",\\\\n \\\\\\\"uid\\\\\\\": \\\\\\\"crossplane\\\\\\\",\\\\n \\\\\\\"panels\\\\\\\": [\\\\n {\
\\\n \\\\\\\"collapsed\\\\\\\": false,\\\\n \\\\\\\"datasource\\\\\\\": {\\\\n \\\\\\\"type\\\\\\\": \\\\\\\"prometheus\\\\\\\",\\\\n \\\\\\\"uid\\\\\\\": \\\\\\\"${DS_PROMETHEUS}\\\\\\\"\\\\n },\\\\n \\\\\\\"gridPos\\\\\\\": {\\\\n \\\\\\\"h\\\\\\\": 1,\\\\n \\\\
\\\"w\\\\\\\": 24,\\\\n \\\\\\\"x\\\\\\\": 0,\\\\n \\\\\\\"y\\\\\\\": 0\\\\n },\\\\n \\\\\\\"panels\\\\\\\": [],\\\\n \\\\\\\"targets\\\\\\\": [\\\\n {\\\\n \\\\\\\"datasource\\\\\\\": {\\\\n \\\\\\\"type\\\\\\\": \\\\\\\"prometheus\\\\\\\",\\\\n
\\\\\\\"uid\\\\\\\": \\\\\\\"${DS_PROMETHEUS}\\\\\\\"\\\\n },\\\\n \\\\\\\"refId\\\\\\\": \\\\\\\"A\\\\\\\"\\\\n }\\\\n ],\\\\n \\\\\\\"title\\\\\\\": \\\\\\\"Workloads\\\\\\\",\\\\n \\\\\\\"type\\\\\\\": \\\\\\\"row\\\\\\\"\\\\n }\\\\n ],\\\\n \\\\\\\"templating\\
\\\\\": {\\\\n \\\\\\\"list\\\\\\\": [\\\\n {\\\\n \\\\\\\"hide\\\\\\\": 2,\\\\n \\\\\\\"name\\\\\\\": \\\\\\\"DS_PROMETHEUS\\\\\\\",\\\\n \\\\\\\"query\\\\\\\": \\\\\\\"prometheus\\\\\\\",\\\\n \\\\\\\"type\\\\\\\": \\\\\\\"datasource\\\\\\\"\\\\n }\\\\n ]\\\\n }\\\
\n}\\\\n\\\",\\\"folder\\\":\\\"2\\\",\\\"lifecycle\\\":{\\\"prevent_destroy\\\":true}}}},\\\"terraform\\\":{\\\"required_providers\\\":{\\\"grafana\\\":{\\\"source\\\":\\\"grafana/grafana\\\",\\\"version\\\":\\\"1.39.0\\\"}}}}\",\"start_line\":22,\"highlight_start_offset\":625,\"highlight_end_offset\":638,\"va
lues\":[]}},\"type\":\"diagnostic\"}\n"}
1.6877711267482073e+09 DEBUG provider-grafana Cannot observe external resource {"controller": "managed/oss.grafana.crossplane.io/v1alpha1, kind=dashboard", "request": "/cluster-dashboard", "uid": "2f2cc928-804a-4804-9c52-6d8679d99350", "version": "7007848", "external-name": "0:crossplan
e", "error": "cannot run refresh: refresh failed: Invalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name.\nInvalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name.
", "errorVerbose": "refresh failed: Invalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name.\nInvalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name.\ncannot run r
efresh\ngithub.com/upbound/upjet/pkg/controller.(*external).Observe\n\tgithub.com/upbound/upjet@v0.8.0/pkg/controller/external.go:113\ngithub.com/crossplane/crossplane-runtime/pkg/reconciler/managed.(*Reconciler).Reconcile\n\tgithub.com/crossplane/crossplane-runtime@v0.19.0-rc.0.0.20221012013934-bce61005a175/pk
g/reconciler/managed/reconciler.go:780\ngithub.com/crossplane/crossplane-runtime/pkg/ratelimiter.(*Reconciler).Reconcile\n\tgithub.com/crossplane/crossplane-runtime@v0.19.0-rc.0.0.20221012013934-bce61005a175/pkg/ratelimiter/reconciler.go:54\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).R
econcile\n\tsigs.k8s.io/controller-runtime@v0.12.1/pkg/internal/controller/controller.go:121\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\tsigs.k8s.io/controller-runtime@v0.12.1/pkg/internal/controller/controller.go:320\nsigs.k8s.io/controller-runtime/pkg/internal/con
troller.(*Controller).processNextWorkItem\n\tsigs.k8s.io/controller-runtime@v0.12.1/pkg/internal/controller/controller.go:273\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\tsigs.k8s.io/controller-runtime@v0.12.1/pkg/internal/controller/controller.go:234\nruntime.goexit\n\
truntime/asm_amd64.s:1594"}
1.687771126749751e+09 DEBUG events Warning {"object": {"kind":"Dashboard","name":"cluster-dashboard","uid":"2f2cc928-804a-4804-9c52-6d8679d99350","apiVersion":"oss.grafana.crossplane.io/v1alpha1","resourceVersion":"7007848"}, "reason": "CannotObserveExternalResource", "message": "cannot run refresh
: refresh failed: Invalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name.\nInvalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name."}
When I take the Json and use the "Import" function of Grafana it works fine.
kkendzia commented
Using $${DS_PROMETHEUS}
instead of ${DS_PROMETHEUS}
solves the problem - this seems default terraform behaviour. Didn't know :)