terraform-provider-grafana: Grafana Provider Error - "Set the auth and url provider attributes"

Terraform Version

  • Terraform: 1.5.2
  • Terraform Grafana Provider: 1.42.0
  • Grafana: 9.4

Affected Resource(s)

Error raised by Grafana Provider directly

provider "grafana" {
  url  = "https://${module.core_infra.grafana_workspace_endpoint}"
  auth = module.core_infra.grafana_api_key
}

Where core_infra is a module which instantiates an Amazon Managed Grafana instance using terraform-aws-modules/managed-service-grafana

Resources being deployed:

  • grafana_data_source
  • grafana_folder
  • grafana_dashboard

Terraform Configuration Files

Working on an example I can share.

Debug Output

Working on an example I can share the full output from. An example error is as below:

{
  "@level": "error",
  "@message": "Error: the Grafana client is required for `grafana_folder`. Set the auth and url provider attributes",
  "@module": "terraform.ui",
  "@timestamp": "2023-06-29T13:23:12.126952Z",
  "diagnostic": {
    "severity": "error",
    "summary": "the Grafana client is required for `grafana_folder`. Set the auth and url provider attributes",
    "detail": "",
    "address": "module.usecase_module_one.module.generic_grafana_module.grafana_folder.usecase_folder",
    "range": {
      "filename": ".terraform/modules/usecase_module_one.generic_grafana_module/grafana.tf",
      "start": { "line": 25, "column": 44, "byte": 917 },
      "end": { "line": 25, "column": 45, "byte": 918 }
    },
    "snippet": {
      "context": "resource \"grafana_folder\" \"usecase_folder\"",
      "code": "resource \"grafana_folder\" \"usecase_folder\" {",
      "start_line": 25,
      "highlight_start_offset": 43,
      "highlight_end_offset": 44,
      "values": []
    }
  },
  "type": "diagnostic"
}

Panic Output

N/A

Expected Behavior

We use “usecase” modules and have the following structure in our Terraform workspace: Workspace

  • core_infra module (contains Amazon Managed Grafana)
  • Grafana Provider (using output from core_infra)
  • usecase_module_one
    • generic_grafana_module (contains Grafana resources grafana_data_source & grafana_folder, grafana_dashboard)
  • usecase_module_two
    • generic_grafana_module (contains Grafana resources grafana_data_source & grafana_folder, grafana_dashboard)

The Grafana Provider is created using the output of the core_infra module, specifically module.core_infra.grafana_workspace_endpoint and module.core_infra.grafana_api_key to configure the Provider with the “url” and “auth” parameters.

We then add a new “usecase_module” using the same underlying “generic_grafana_module” as follows:

Current Workspace

  • core_infra module
  • grafana provider
  • usecase_module_one
    • generic_grafana_module
  • usecase_module_two
    • generic_grafana_module
  • usecase_module_three
    • generic_grafana_module

This should update existing infra as required and add the grafana resources for “usecase_module_three”

Actual Behavior

When running the plan and apply to add “usecase_module_three” to our environment we get a Grafana Provider error only on resources related to “usecase_module_one” and “usecase_module_two”. It successfully plans for the “usecase_module_three” deployment.

An example error is as below:

{
  "@level": "error",
  "@message": "Error: the Grafana client is required for `grafana_folder`. Set the auth and url provider attributes",
  "@module": "terraform.ui",
  "@timestamp": "2023-06-29T13:23:12.126952Z",
  "diagnostic": {
    "severity": "error",
    "summary": "the Grafana client is required for `grafana_folder`. Set the auth and url provider attributes",
    "detail": "",
    "address": "module.usecase_module_one.module.generic_grafana_module.grafana_folder.usecase_folder",
    "range": {
      "filename": ".terraform/modules/usecase_module_one.generic_grafana_module/grafana.tf",
      "start": { "line": 25, "column": 44, "byte": 917 },
      "end": { "line": 25, "column": 45, "byte": 918 }
    },
    "snippet": {
      "context": "resource \"grafana_folder\" \"usecase_folder\"",
      "code": "resource \"grafana_folder\" \"usecase_folder\" {",
      "start_line": 25,
      "highlight_start_offset": 43,
      "highlight_end_offset": 44,
      "values": []
    }
  },
  "type": "diagnostic"
}

We get an error like this for each Grafana resource in “usecase_module_one” and “usecase_module_two”

Steps to Reproduce

  1. Define modules as per the structure in “Expected Behaviour” with only “core_infra”, “usecase_module_one”, “usecase_module_two”
  2. Deploy this with terraform plan & terraform apply
  3. Add “usecase_module_three” to the terraform code
  4. terraform plan - Will fail as per behaviour in “Actual Behaviour”

Important Factoids

N/A

References

None

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 3
  • Comments: 18

Most upvoted comments

Getting this too. From grafana_folder

Need to test whether you can use the provider fine as long as you don’t create any folders.

the refresh=false workaround won’t work long term for us as we can’t use that in CI