grafana / terraform-provider-grafana

Terraform Grafana provider
https://www.terraform.io/docs/providers/grafana/
Mozilla Public License 2.0
422 stars 226 forks source link

Error trying to import dashboard - unsupported protocol scheme "" #257

Closed udh-mendix closed 2 years ago

udh-mendix commented 3 years ago

Terraform Version

Terraform: 0.12.9 Terraform Grafana Provider: 1.13.3 Grafana: v8.0.6

Affected Resource(s)

grafana_dashboard

Terraform config

provider "grafana" {
  url  = var.grafana_url
  auth = var.grafana_auth
  version = "~> 1.5.0"
}

resource "grafana_data_source" "xyz" {
  type = "influxdb"
  name = "xyz"

  url            = var.influxdb_url
  database_name = var.influxdb_name
  username      = var.influxdb_username
  password      = var.influxdb_password

  access_mode = "direct"
}

resource "grafana_dashboard" "abc" {
  config_json = var.abc_dashboard_json
  folder      = var.abc_dashboard_folder_id
  depends_on  = [grafana_data_source.xyz]
}

Expected Behavior

Importing grafana dashboard should succeed

Actual Behaviour

Import fails with following error -

Error: Get /api/dashboards/db/abc: unsupported protocol scheme ""

grafana_url is a HTTPS URL, so its unclear why I'm getting this error.

Steps to Reproduce

Import grafana dashboard into terraform terraform import grafana_dashboard.abc abc-slug

justinTM commented 3 years ago

same/similar issue here:

Error: Post "/api/folders": unsupported protocol scheme ""
431  on folders.tf line 9, in resource "grafana_folder" "metrics":
432   9: resource "grafana_folder" "metrics" {

Terraform: 0.13 Terraform Grafana Provider: 1.13.4 Grafana: v8.1.2

justinTM commented 3 years ago

This error is encountered for one environment but not the other. Both environments have the same versions for Terraform, Grafana (both hosted instances of Grafana Cloud, with different domains), and Grafana provider plugin.

The failing instance is a Grafana Cloud trial instance (quotas/limits to number of resources). The successful instance is a Grafana Cloud company-wide domain (i.e., <company-name>.grafana.net).

justinTM commented 3 years ago

The error has miraculously disappeared when upgrading to Terraform 1.0 (same other versions). Not sure if coincidence or cause.

inkel commented 3 years ago

Hi, @justinTM and @udh-mendix, I just wanted to confirm something in order to reprodue: suppose your dashboard URL is http://example.net/d/abc123/some-name, what value are you using for importing the dashboard:

terraform import grafana_dashboard.sample abc123
# or
terraform import grafana_dashboard.samepl some-name

I know the documentation says to use the slug, but I'm afraid that might be wrong.

Thanks!

udh-mendix commented 3 years ago

Hi @inkel, I've tried with both and it fails with the same error.

inkel commented 3 years ago

Thanks. Can you paste me the full error output?

udh-mendix commented 3 years ago

I've tried with both dashboard ID and the slug, and its the same error.

Command for dashboard http://example.net/d/l9ji-5wWz/abc-slug -

terraform import -var-file=abcvarfile.tfvars module.grafana.grafana_dashboard.abc l9ji-5wWz

Relevant TF debug logs -

module.grafana.grafana_dashboard.abc: Importing from ID "l9ji-5wWz"...
module.grafana.grafana_dashboard.abc: Import prepared!
Prepared grafana_dashboard for import
module.grafana.grafana_dashboard.abc: Refreshing state... [id=l9ji-5wWz]
2021/08/31 11:11:06 [ERROR] module.grafana: eval: *terraform.EvalRefresh, err: Get /api/dashboards/db/l9ji-5wWz: unsupported protocol scheme ""
2021/08/31 11:11:06 [ERROR] module.grafana: eval: *terraform.EvalSequence, err: Get /api/dashboards/db/l9ji-5wWz: unsupported protocol scheme ""
2021/08/31 11:11:06 [TRACE] [walkImport] Exiting eval tree: import module.grafana.grafana_dashboard.abc result
2021/08/31 11:11:06 [TRACE] vertex "import module.grafana.grafana_dashboard.abc result": visit complete
udh-mendix commented 2 years ago

@julienduchesne thanks for getting this fixed in #395. When will the release be cut? I'm waiting for that so terraform can pick up the latest tag.

julienduchesne commented 2 years ago

@julienduchesne thanks for getting this fixed in #395. When will the release be cut? I'm waiting for that so terraform can pick up the latest tag.

This was released in v1.20.0