Skip to content
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

[Bug]: Error: id "<folder UID>:<alert name>" does not match expected format. Should be in the format: folderUID:title #1535

Closed
odam06 opened this issue May 6, 2024 · 16 comments
Labels

Comments

@odam06
Copy link

odam06 commented May 6, 2024

Terraform Version

v1.8.2

Terraform Grafana Provider Version

2.15~2.18

Grafana Version

10.4.1

Affected Resource(s)

grafana_rule_group

Terraform Configuration Files

we have created a meta module for alerting which looks like this:

`resource "grafana_rule_group" "rule_group" {
name = var.name
folder_uid = var.folder_uid

interval_seconds = coalesce(var.evaluation_interval_seconds, local.evaluation_interval_seconds_default)

rule {
name = var.name
for = coalesce(var.alert_rule_for_duration, local.alert_rule_for_duration_default)
condition = var.condition_ref_id == null ? var.alert_rule_data[length(var.alert_rule_data) - 1].ref_id : var.condition_ref_id

no_data_state  = coalesce(var.alert_rule_no_data_behavior, local.alert_rule_no_data_behavior_default)
exec_err_state = coalesce(var.alert_rule_exec_error_behavior, local.alert_rule_exec_error_behavior_default)

labels      = merge(var.alert_rule_labels, local.labels_default)
annotations = var.alert_rule_annotations

dynamic "data" {
  for_each = var.alert_rule_data

  content {
    ref_id         = data.value.ref_id
    datasource_uid = data.value.datasource_uid
    query_type     = data.value.query_type

    model = data.value.model

    relative_time_range {
      from = data.value.datasource_uid == "-100" ? 0 : data.value.relative_time_range.from
      to   = data.value.relative_time_range.to
    }
  }
}

}
}`

Expected Behavior

After upgrading terraform provider, we should be able to apply it without changing the whole alerting even when no changes

Actual Behavior

After bump to provider > 2.15, we have this warning during apply:
Warning: rule group with ID "0:<folder uid>;<alert name>" is in Terraform state, but no longer exists in Grafana

which gives us this error:
Error: id "<folder uid>:<alert name>" does not match expected format. Should be in the format: folderUID:title

On our side, no changes happened on the alerting, but from the error, we can see the warning do a separation via a ; between folder uid and alert name when the error do the separation via a :

Steps to Reproduce

Apply the terraform using 2.14.3
Update to > 2.14.3

Important Factoids

No response

References

No response

@odam06 odam06 changed the title Error: id "<folder UID>:<alert name>" does not match expected format. Should be in the format: folderUID:title [Bug]: Error: id "<folder UID>:<alert name>" does not match expected format. Should be in the format: folderUID:title May 6, 2024
@julienduchesne
Copy link
Member

hmm. I'm unable to reproduce this with the given steps. I've applied a rule group with 2.14.3, I upgrade my provider to 2.18.0 and the plan shows "no changes"

@odam06
Copy link
Author

odam06 commented May 7, 2024

Hello @julienduchesne,

I take a deeper look to what is going on, and the issue is related to nested folder.

When the alert is linked to a subfolder like this:
Capture d’écran 2024-05-07 à 15 13 13

The alert will be created but we will have an error at the end of the terraform apply.
For the alerts wich are not in a nested folder, we don't have any issues.

The issue start at v2.15, v2.14.3 was good for this

@julienduchesne
Copy link
Member

julienduchesne commented May 8, 2024

I'm unable to reproduce this 🤔
I apply this with version 2.14.3 and upgrade to 2.18.0 (or any version >=2.15.0) and the plan is empty (as it should be):

resource "grafana_folder" "parent_folder" {
		title = "blabla-parent"
		uid   = "blabla-parent"
	}
	
	resource "grafana_folder" "child_folder" {
		title     = "blabla-child"
		uid       = "blabla-child"
		parent_folder_uid = grafana_folder.parent_folder.uid
	}
	
	resource "grafana_data_source" "test" {
		name = "blabla"
		type = "grafana-testdata-datasource"
		url  = "http://localhost:3333"
	}
	
	resource "grafana_rule_group" "test" {
		name             = "blabla"
		folder_uid       = grafana_folder.child_folder.uid
		interval_seconds = 60
	
		rule {
			name      = "My Random Walk Alert"
			condition = "C"
			for       = "0s"
	
			// Query the datasource.
			data {
				ref_id = "A"
				relative_time_range {
					from = 600
					to   = 0
				}
				datasource_uid = grafana_data_source.test.uid
				model = jsonencode({
					intervalMs    = 1000
					maxDataPoints = 43200
					refId         = "A"
				})
			}
		}
	}

@julienduchesne
Copy link
Member

Closing because I'm unable to reproduce, and this may be resolved with the new major version. I'd recommend you try that one. Feel free to re-open if this is still happening!

@julienduchesne julienduchesne closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2024
@vipulvv
Copy link

vipulvv commented May 17, 2024

We are observing this issue now. Details are:

Terraform Version
v1.8.3

Terraform Grafana Provider Version
v3.0.0

Grafana Version
v11.1.0-70724

Affected Resource(s)
grafana_rule_group

Terraform Configuration Files

resource "grafana_rule_group" "rule_group_billing_and_healthchecks" {
  name               = "billing-and-healthchecks"
  folder_uid         = var.folder_uid
  interval_seconds   = var.interval_seconds_60
  disable_provenance = true
  ...
  ...
  • While running plan, I see:
Planning failed. Terraform encountered an error while generating this plan.
╷
│ Error: id "xxxxxx-xxxx-xxxx-xxxx-xxxxx;billing-and-healthchecks" does not match expected format. Should be in the format: folderUID:title
│ 
│   with grafana_rule_group.rule_group_billing_and_healthchecks,
│   on alerts.tf line 1, in resource "grafana_rule_group" "rule_group_billing_and_healthchecks":
│    1: resource "grafana_rule_group" "rule_group_billing_and_healthchecks" {
│ 
╵

@NadhemHamila
Copy link

Facing pretty much the same issue.

Terraform Version

v1.4.6

Terraform Grafana Provider Version

3.0.0

Using AWS Managed Grafana

Affected Resource(s)

grafana_rule_group

Terraform Configuration Files

I have created a terraform module for alerting to create rule groups with a folder
resource "grafana_folder" "rule_folder" { title = var.grafana_rule_folder_title }
and a rule group

resource "grafana_rule_group" "my_alert_rule" {
  name             = var.grafana_rule_group_name
  folder_uid       = grafana_folder.rule_folder.uid
...

This was working weeks ago and I was using Terraform Grafana Provider version = ">= 1.28.2" at the time, then I wanted to delete one rule from the rule group so I just omitted the rule from the code that's when I faced this warning first:

Warning: contact point with ID "xxxxxxxx" is in Terraform state, but no longer exists in Grafana

and then this error:

Error: id "xxxxx;rule_group_name" does not match expected format. Should be in the format: folderUID:title not sure why it is a ; instead of : in there (odam06 mentioned he had the same, also in my case I don't have nested folders)

I changed the terraform grafana version to version = ">= 3.0.0 but still faced the same issue. I also tried to go back to the old code when this worked for me (the exact same without changing anything) but still had the same issue

@julienduchesne
Copy link
Member

To upgrade to v2, you have to upgrade to the latest v1 version, and then upgrade to v2.

To upgrade to v3, you have upgrade to the latest v2 version, apply and then upgrade to v3 (see the v2 and v3 release notes, for more info)

There is a year of continuous development, hundreds of commits, between the last v1 and v3.0.0

@NadhemHamila
Copy link

It's already failing without changing the version (I changed the version in an attempt to fix the issue). Also this failing at the plan level so before a tf apply.

@InGaardWeTrust
Copy link

This issue should be reopened. We are also facing the same issue in our grafana cloud instance.

Terraform version
v1.3.6

Terraform Grafana Provider Version
3.0.0

Using AWS Managed Grafana
Affected Resource(s)

grafana_rule_group

Terraform Configuration Files:

We just migrated from v2.6.1 to version 3.0.0. This was to resolve other issues we were having with creating rule resources. After upgrading, despite not updating any other TF, we also saw this error:

Error: id "xxxx;rule_group_name" does not match expected format. Should be in the format: folderUID:title

Looking at the resources in the state I can see that the id attribute is set to
id = "org_id:xxxx;rule_group_name"

It seems like some update set the state value for id incorrectly and renders it unusable when making the API call. I suspect that if we delete the alert rules via the UI, remove them from the state, and then recreate via TF it might resolve the issue. Unfortunately I cant find a way to disable deletion protection for provisioned resources in grafana cloud ...

@julienduchesne
Copy link
Member

See the upgrade procedure here: https://github.com/grafana/terraform-provider-grafana/releases/tag/v3.0.0

The upgrade process from v2 to v3 only works from the latest v2 version (v2.19.0, not v2.6.1). There were gradual changes of ID formats in v2 in order to standardize them, and all of the upgrade/compatibility code was removed in v3.

@NadhemHamila
Copy link

As I said this is happening at the plan level for me and I think for all of us actually. So the upgrade process you’re mentioning is actually not possible.

@julienduchesne
Copy link
Member

At the plan level with which version? Applying on the latest v2 version will update the ID format even if Terraform says there will be no changes

@NadhemHamila
Copy link

I can't apply, the terraform plan starts creating the plan and then it fails with that error. This happened with my current version v1.28.21 I've tried upgrading the version the way you described but that does not solve it, as it still fails at the plan level and I can't apply. I think this issue should be reopened as it seems many of us are facing the same problem here.
Screenshot from 2024-05-22 11-20-26

@julienduchesne
Copy link
Member

I'm not able to reproduce this 🤔. I applied a contact point with 1.28.1 and then I applied it with 2.19.0 (no changes) and then I had no changes on a plan with 3.0.0

@NadhemHamila
Copy link

I’m not just creating a contact but also alert rules

@julienduchesne
Copy link
Member

I'm also unable to reproduce this with rule groups. Applied both a contact point and rule group with 1.28.1, then I applied it with 2.19.0 (no changes) and then I had no changes on a plan with 3.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants