jdamata / terraform-provider-sonarqube

Terraform provider for managing Sonarqube configuration
GNU General Public License v3.0
62 stars 54 forks source link

When deleting a quality gate, only change the default if the one you are deleting is currently default. #160

Closed freeranger closed 1 year ago

freeranger commented 1 year ago

Fixes https://github.com/jdamata/terraform-provider-sonarqube/issues/158

Tested with the following resources:

resource "sonarqube_qualitygate" "way" {
  name       = "My way"
  is_default = true
}

resource "sonarqube_qualitygate" "other" {
  name       = "My Other way"
}

"My way" was set to default

Changed to

resource "sonarqube_qualitygate" "way" {
  name       = "My way"
}

resource "sonarqube_qualitygate" "other" {
  name       = "My Other way"
  is_default = true
}

"My Other way" was set to default

Changed to:

resource "sonarqube_qualitygate" "other" {
  name       = "My Other way"
  is_default = true
}

"My way" was deleted and "My Other way" continued to be the default

Finally removed "My Other way" from the terraform script and ran again. "My Other way" was deleted and "Sonar way" was set as the default

Cesarsk commented 1 year ago

Super! Will test and let you know <3

freeranger commented 1 year ago

@Cesarsk I found a race condition with this when testing https://github.com/jdamata/terraform-provider-sonarqube/pull/163 - the fix is in that which hopefully will be merged in the next few days. Testing on a bigger, better, faster machine, 9.8 seems more susceptible to the problem than 10.0 - in a simple case with 2 gates and nothing else, GO is flip-flopping between the commands for each resource so we can end up with things in a different state between determining the default has changed and setting the new default.