jdamata / terraform-provider-sonarqube

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

Bug: The sonarqube_qualitygate resource does not populate the conditions array #156

Closed freeranger closed 1 year ago

freeranger commented 1 year ago

Hi

The sonarqube_qualitygate resource looks like it should populate conditions when the resource is read - see here: https://github.com/jdamata/terraform-provider-sonarqube/blob/e230cdf842cf6a0beaf46419903d8d0ed8e8ef52/sonarqube/resource_sonarqube_qualitygate.go#L182-L186

The problem is that by the time it hits this code, we have already read the resp.Body so this is alway empty.

In versions of Sonar prior to 9.9 this was not an issue because no conditions are added when the quality gate is created. In 9.9 and above however, six conditions are automatically added and so they should be returned here.

Terraform Version

Terraform v1.3.9

Affected Resource(s)

Please list the resources as a list, for example: sonarqube_qualitygate`

Expected Behavior

< 9.9 - no conditions are populated - e.g.

resource "sonarqube_qualitygate" "default" {
    conditions = []
    id         = "My way"
    is_default = true
    name       = "My way"
}

9.9+ - 6 conditions populated - e.g.

resource "sonarqube_qualitygate" "default" {
    conditions = [
        <snip>
        {
            error  = "80"
            id     = "AYe40uWkpq_IgwDfAktH"
            metric = "new_coverage"
            op     = "LT"
        },
    ]
    id         = "My way"
    is_default = true
    name       = "My way"
}

Actual Behavior

In all cases we get

resource "sonarqube_qualitygate" "default" {
    conditions = []
    id         = "My way"
    is_default = true
    name       = "My way"
}

Steps to Reproduce

With a terraform script like this:

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

apply it to a Sonar instance 9.9 or above

References

https://github.com/jdamata/terraform-provider-sonarqube/issues/154 refers to the problem but I think fixing the problem does not depend on that and may well form part of the solution to same