jdamata / terraform-provider-sonarqube

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

Provider initialization failing #226

Open buddhamangler-cbre opened 7 months ago

buddhamangler-cbre commented 7 months ago

This provider (0.16.9) is not initializing correctly during the version and edition check...

We are using SonarQube 9.9.2.77730 with DataCenter edition deployed in K8s as a cluster of 3 nodes.

https://github.com/jdamata/terraform-provider-sonarqube/blob/c8754edb9fc08f0b9ec3e96fa0d9e79c433ccd83/sonarqube/provider.go#L164

The issue is the code is checking the system information here...

https://github.com/jdamata/terraform-provider-sonarqube/blob/c8754edb9fc08f0b9ec3e96fa0d9e79c433ccd83/sonarqube/provider.go#L204

It expects two properties out of the system information call it makes...

    sonarqubeVersion := gjson.GetBytes(responseData, "System.Version").String()
    sonarqubeEdition := gjson.GetBytes(responseData, "System.Edition").String()

The problem is that our SQ instance is returning this for that section in the json (with redactions)...

    "System": {
        "Server ID": "redacted",
        "Edition": "Data Center",
        "Lines of Code": 17105284,
        "Docker": false,
        "High Availability": true,
        "Accepted external identity providers": "Azure AD",
        "External identity providers whose users are allowed to sign themselves up": "Azure AD",
        "Force authentication": true
    },

As you can see, System.Version is not present. It is however present in another section of the returned json in each of the objects of an array with key "Application Nodes"...

{
   ...
    "Application Nodes": [
        {
            "Name": "redacted",
            "Host": "",
            "Health": "GREEN",
            "Health Causes": [],
            "System": {
                "Version": "9.9.2.77730",
                "Official Distribution": true,
                "Home Dir": "/opt/sonarqube",
                "Data Dir": "/opt/sonarqube/data",
                "Temp Dir": "/opt/sonarqube/temp",
                "Processors": 1
            },
            ...
      },
      ...
   ]
}

Perhaps the system information is returned this way in clusters? The system information check should account for this.

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

N/A

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,

N/A

Expected Behavior

What should have happened?

The provider initialization should have worked.

Actual Behavior

What actually happened?

 Error: -11T17:23:23.849Z [ERROR] provider.terraform-provider-sonarqube_v0.16.9: Response contains error diagnostic: tf_provider_addr=registry.terraform.io/jdamata/sonarqube tf_req_id=a0c0a2a2-f1e9-0a52-b79a-3cbf9a1fe066 @caller=github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/internal/diag/diagnostics.go:58 @module=sdk.proto diagnostic_summary="failed to convert sonarqube version to a version: Malformed version: " tf_proto_version=5.3 tf_rpc=Configure diagnostic_detail="" diagnostic_severity=ERROR timestamp=2023-12-11T17:23:23.849Z
Error: -11T17:23:23.850Z [ERROR] vertex "provider[\"registry.terraform.io/jdamata/sonarqube\"]" error: failed to convert sonarqube version to a version: Malformed version:

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

Lucatronlk commented 6 months ago

I have the same problem.

On Community or Enterprise, it works fine, just with the DataCenter edition it happens.

You can add installed_version and installed_edition to the provider as a quick fix.

image
jdamata commented 6 months ago

Thank you for the detailed write up! This looks like something that should definitely be fixed.