I just had a similar issue. I tried the suggested methods, but I found another solution. In the grafana provisioning tutorial, I noticed the following two things:
# definition of the data sources:
datasources:
- name: TestData
type: testdata
Then in the json, they suggest to refer to the name by string, not an object containing type and UID:
"panels": [
{
...
"datasource": "TestData",
...
I hope that helps.