-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Grafana Provider Error - "Set the auth and url provider attributes" #960
Comments
If you inspect your state, are both the |
Hi @julienduchesne, I checked the state file and could find the values referenced by those core_infra outputs in the infrastructure. I.e. I could find the Just to be 100% sure, I stored provider "grafana" {
url = terraform_data.workspace_endpoint_url.output
auth = terraform_data.workspace_key.output
} I could clearly see these {
"mode": "managed",
"type": "terraform_data",
"name": "workspace_endpoint_url",
"provider": "provider[\"terraform.io/builtin/terraform\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "62eb70b9-a57a-af7e-67c4-048d26451738",
"input": {
"value": "https://g-28jd182fk9.grafana-workspace.us-east-1.amazonaws.com",
"type": "string"
},
"output": {
"value": "https://g-28jd182fk9.grafana-workspace.us-east-1.amazonaws.com",
"type": "string"
},
"triggers_replace": null
},
"sensitive_attributes": [],
"dependencies": [
"module.core_infra.aws_iam_role.grafana_service_role",
"module.core_infra.module.managed_grafana.aws_grafana_workspace.this",
"module.core_infra.module.managed_grafana.aws_iam_role.this",
"module.core_infra.module.managed_grafana.aws_security_group.this",
"module.core_infra.module.managed_grafana.data.aws_iam_policy_document.assume",
"module.core_infra.module.managed_grafana.data.aws_partition.current",
"module.core_infra.module.managed_grafana.data.aws_subnet.this"
]
}
]
}, Still had the same Provider error. |
Another thing to note is that I also tried an plan & apply using the existing TF (without"usecase_module_three" being added) and the plan fails in the same manner as the original issue comment. If I hardcode a dummy Grafana workspace URL and API Key, provider "grafana" {
url = "https://grafana.example.com"
auth = "somekey"
} Then the plan fails with an error
|
A further note, I retried the plan & apply with existing TF (no changes) and hardcoded different dummy Grafana workspace URL and API key and then the plan passed?! Specifically I used: provider "grafana" {
url = "https://example.com"
auth = "somekey"
} |
A plan of an unapplied resource will not do any remote calls |
Thanks @julienduchesne. If you read the message before that one, then it is making calls during the |
Yes. If it's doing a remote call during a plan, it means it's doing a refresh of a resource that was previously applied |
I'm also having this issue. I have three environments that are managed via the same code using terraform workspaces. 2 of them fail with this same error, and the other one successfully. All three were created at similar times and should have valid states, as they are managed by TF cloud and all had passing runs on their last apply before this issue popped up. The code for our deployments is heavily influenced by the example docs. Here are the relevant resources:
I was originally using version 1.28.0, but after encountering this, I tried upgrading to 1.43.0 and still have the same issue. If I put API keys directly into the "auth" fields of my providers, a plan at least works. |
Update: if I invoke terraform with the So to recap:
|
Getting this too. From 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 |
Also seems to be present when using the |
@julienduchesne hey! let me kn ow if i can help you out with this - causing us a fair amount of hell in CI/CD |
This issue is hard to remediate because in all the cases I've managed to reproduce, it's always that either the auth or URL are missing (as the message says). If I removed the error, you'd instead get a 401 error. Here's an example: Folders and dashboards are managed by a service account token. That token is removed Grafana side. Terraform, on read, removes the token from state and so there's no auth anymore. The error triggers. An ugly fix could be setting a depends_on condition for all resources that depend on previous resources for auth. For example, folders and dashboards would have a depends_on condition on the service account token resource that creates the auth used in their |
Hi @julienduchesne - gave Why would the service account token be removed from inside grafana? (we don't touch them...) i do see that my token is expired one - so maybe that could be the root cause? |
Could this be an issue with API keys migrating to service accounts? I'm using Grafana cloud and can confirm that in some environments the "importer" key we create still shows up under API keys, but in other deployments the API key tab is gone, and there is only a service accounts tab. In environments that only have the "service accounts" tab, it looks like the previous "importer" API key was upgraded. Perhaps the root cause of this issue is provisioning an API key and then later doing the in-browser upgrade to service accounts? Once that latter step has happened, the deployments break since the API keys no longer exist? |
We've only ever used service accounts. (only deployed this infra recently) |
This issue is essentially https://discuss.hashicorp.com/t/depends-on-in-providers/42632. Github issues: Not sure there's anything we can do here. If a resource is being planned by a Users can get around that in a few ways:
|
OK. Is it possible that the token expiring is what takes it out of the state? I can't think of a reason that it'd leave our state otherwise. If it is that, then I would imagine there is a case that in the grafana provider it handles the |
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 |
This is a different one @NickAdolf. Here it is: #1485. It will be fixed in next release. Sorry about that! |
We are also facing this issue. It seems to be blocked by hashicorp/terraform#2430, but are there other workarounds? |
This issue is persisting for me on
|
Was having the same issue until I solved it by adding an alias to the provider and referencing it in the resource:
|
resolution/workaround: 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:
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. |
Terraform Version
Affected Resource(s)
Error raised by Grafana Provider directly
Where core_infra is a module which instantiates an Amazon Managed Grafana instance using terraform-aws-modules/managed-service-grafana
Resources being deployed:
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:
Panic Output
N/A
Expected Behavior
We use "usecase" modules and have the following structure in our Terraform workspace:
Workspace
The Grafana Provider is created using the output of the core_infra module, specifically
module.core_infra.grafana_workspace_endpoint
andmodule.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
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:
We get an error like this for each Grafana resource in "usecase_module_one" and "usecase_module_two"
Steps to Reproduce
terraform plan
&terraform apply
terraform plan
- Will fail as per behaviour in "Actual Behaviour"Important Factoids
N/A
References
None
The text was updated successfully, but these errors were encountered: