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: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 25 (7 by maintainers)

Most upvoted comments

resolution/workaround: one comment (from one of the maintainers) clarifies that the root cause is indeed terraform’s lack of supporting dependencies on providers attributes.

before the issue arose, the team had created a service account, token and a grafana dashboard (Amazon Managed Grafana) without problems. (i guess on the first plan and apply, the grafana provider may behave different/more robust against missing provider dependency since no resource exists?). The issue arose once the token expired after 30 days (as per configuration).

Resolution steps:

  1. upgrade the grafana provider (to v3.15.3) and used FOSS module (terraform-aws-modules/managed-service-grafana/aws to 2.2.0) to lates
  2. remove the relevant stale resources (expired service account/token and downstream dependent resources) (both infrastructure and tf state (direct removal on state)
  3. make two consecutive plan and apply cycles (first to get a new service account and token), second for the provider to use the new credential for creating any arbitrary grafana provider resource.

Likely the issue arises after the configured expiry time of the token associated to the service account. Repeating steps 2 and 3 should help you recover again. Unf. you may have to deal with data loss of your grafana resources or try to integrate your backup/restore procedures into the above steps.

(it’s important to note that in this scenario we had a quite large monolithic root stack that had eks, helm, aws, grafana providers active. Carving out just the grafana resources and modules into an own root stack would have been to invasive to the current design and cicd implantation.

I’m getting this on a brand new, un-applied workspace with no data lookups. I’m not making sense of this.

I create a grafana_team & grafana_folder and then get this error when trying grafana_folder_permissions_item

This is a different one @NickAdolf. Here it is: https://github.com/grafana/terraform-provider-grafana/issues/1485. It will be fixed in next release. Sorry about that!

I’m getting this on a brand new, un-applied workspace with no data lookups. I’m not making sense of this.

I create a grafana_team & grafana_folder and then get this error when trying grafana_folder_permissions_item

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