grafana / terraform-provider-grafana

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

[Bug]: Unable to change provisioned data source which was imported #1682

Closed oliviermichaelis closed 1 month ago

oliviermichaelis commented 1 month ago

Terraform Version

OpenTofu 1.7.0

Terraform Grafana Provider Version

3.4.0

Grafana Version

v11.0.0

Affected Resource(s)

Terraform Configuration Files

This Prometheus data source was initially provisioned by another data source. I then imported it into another state with the following config:

resource "grafana_data_source" "prometheus" {
  name        = "Prometheus"
  type        = "prometheus"
  url         = "http://kube-prometheus-stack-prometheus.kube-prometheus-stack.svc.cluster.local:9090"
  access_mode = "proxy"
}

Expected Behavior

After importing it, I expect to be able to update the data source.

Actual Behavior

When changing the grafana_data_source, for example by changing the is_default argument:

resource "grafana_data_source" "prometheus" {
  name        = "Prometheus"
  type        = "prometheus"
  url         = "http://kube-prometheus-stack-prometheus.kube-prometheus-stack.svc.cluster.local:9090"
  access_mode = "proxy"
  is_default = true
}

and run tofu apply I get

grafana_data_source.prometheus: Modifying... [id=1:ABC123]
╷
│ Error: [PUT /datasources/uid/{uid}][403] updateDataSourceByUidForbidden {"message":"Cannot update read-only data source"}
│
│   with grafana_data_source.prometheus,
│   on datasources.tf line 1, in resource "grafana_data_source" "prometheus":
│    1: resource "grafana_data_source" "prometheus" {
│
╵

Steps to Reproduce

No response

Important Factoids

No response

References

No response

oliviermichaelis commented 1 month ago

changed the read_only field in the database from 1 to 0 with:

UPDATE data_source SET read_only = 0 WHERE uid = ABC123;

I would propose that the provider warns or prevents importing a data source that is set to read_only :)

julienduchesne commented 1 month ago

Yeah, that's a good idea. In that case, a user should use the datasource (data.grafana_data_source) 👍.