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

uid is always updated in previously created dashboards #152

Closed
ghmeier opened this issue Dec 23, 2020 · 1 comment · Fixed by #153
Closed

uid is always updated in previously created dashboards #152

ghmeier opened this issue Dec 23, 2020 · 1 comment · Fixed by #153

Comments

@ghmeier
Copy link

ghmeier commented Dec 23, 2020

Terraform Version

Terraform v0.12.29
+ provider.grafana v1.8.0 

### Affected Resource(s)
`grafana_dashboard`

### Terraform Configuration Files
```hcl
data "template_file" "grafana-dashboard" {
  template = file("${path.module}/dashboard.json")

  vars = {
    name = var.dashbaord_name
  }
}

resource "grafana_dashboard" "job-queue-dashboard" {
  # "Job queues" folder retrieved from metrics{,-staging}.mixmax.com/api/folders
  folder = "1"

  config_json = data.template_file.grafana-dashboard.rendered
}

Using a dashboard.json file like this:

{
  "annotations": {
    "list": [
      {"builtIn": 1,"datasource": "-- Grafana --","enable": true,"hide": true,"iconColor": "rgba(0, 211, 255, 1)","name": "Annotations and Alerts","type": "dashboard"}
    ]
  },
  "editable": true,
  "gnetId": null,
  "graphTooltip": 0,
  "links": [],
  "panels": [],
  "schemaVersion": 16,
  "style": "dark",
  "tags": [],
  "templating": {"list": []},
  "time": {"from": "now-1h","to": "now"},
  "timepicker": {
    "refresh_intervals": ["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],
    "time_options": ["5m","15m","1h","6h","12h","24h","2d","7d","30d"]
  },
  "timezone": "",
  "title": "$name",
  "uid": "$name",
}

Expected Behavior

The dashboard should not reflect changes after the first successful terraform apply

Actual Behavior

The dashboard reflects changes to the uid any time terraform plan is run.

For example (ignoring the whole output of the dashboard file):

      (
           {
                timezone      = ""                                                                                                                                                                                  
                title         = "test"                                                                                                                                             
              ~ uid           = "QiQNwyCik" -> "test"                                                                                                                                     
            }                                                                                                                                                                                                
        )                                                                                                                                                                                                 
        dashboard_id = 27                                                                                                                                                                       
        folder       = 23                                                                                                                                                                       
        id           = "test"                                                                                                                                            
        slug         = "test"                                                                                                                                                         
    }                                                                                                                                                
                                                                                                                                                                                                                             
Plan: 0 to add, 1 to change, 0 to destroy. 

In this case, because uid was set automatically by a version prior to 1.7 we attempt to overwrite the new name, "test", in the updated plan. Even though this plan can be successfully run, it doesn't actually update the uid property on the dashboard.

Steps to Reproduce

  1. Set your grafana provider version to 1.7
  2. Create a new dashboard with JSON configuration input
  3. Upgrade your grafana provider version to 1.8
  4. Add the static uid field to your dashboard JSON.
  5. Run terraform plan and terraform apply
  6. Run terraform plan again and notice changes have been detected.

Important Factoids

This happens with Grafana v5.4.3. I haven't tested newer versions at the moment.

References

I think this PR #136 should probably have detected previous UID state rather than always accepting what's in the dashboard config.

@trotttrotttrott
Copy link
Member

@ghmeier thanks for reporting this. I believe this is a duplicate of #151 (which was opened seconds before this). 1.8.1 was just released with a fix.

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

Successfully merging a pull request may close this issue.

2 participants