jdamata / terraform-provider-sonarqube

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

Sonar way profile won't associate with projects #184

Closed JacobWeyer closed 11 months ago

JacobWeyer commented 12 months ago

Terraform Version

Terraform v1.3.9 on darwin_arm64

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,

Expected Behavior

quality profile gets associated with the project

Actual Behavior

What actually happened?

  + resource "sonarqube_qualityprofile_project_association" "main" {
      + id              = (known after apply)
      + language        = "ts"
      + project         = "oncall-notifier-lambda"
      + quality_profile = "Sonar way"
    }

module.sonarqube.sonarqube_project.main: Creating...
module.sonarqube.sonarqube_project.main: Creation complete after 1s [id=oncall-notifier-lambda]
module.sonarqube.sonarqube_qualitygate_project_association.main: Creating...
module.sonarqube.sonarqube_qualityprofile_project_association.main["Sonar way"]: Creating...
module.sonarqube.sonarqube_qualitygate_project_association.main: Creation complete after 0s [id=built_default/oncall-notifier-lambda]
╷
│ Error: resourceSonarqubeQualityProfileProjectAssociationRead: Failed to find project association: Sonar way/oncall-notifier-lambda
│
│   with module.sonarqube.sonarqube_qualityprofile_project_association.main["Sonar way"],
│   on .terraform/modules/sonarqube/modules/sonarqube_project_association/main.tf line 8, in resource "sonarqube_qualityprofile_project_association" "main":
│    8: resource "sonarqube_qualityprofile_project_association" "main" {

For non Sonar way profiles it works fine

  + resource "sonarqube_qualityprofile_project_association" "main" {
      + id              = (known after apply)
      + language        = "ts"
      + project         = "oncall-notifier-lambda"
      + quality_profile = "typescript_default"
    }

module.sonarqube.sonarqube_project.main: Creating...
module.sonarqube.sonarqube_project.main: Creation complete after 1s [id=oncall-notifier-lambda]
module.sonarqube.sonarqube_qualitygate_project_association.main: Creating...
module.sonarqube.sonarqube_qualityprofile_project_association.main["typescript_default"]: Creating...
module.sonarqube.sonarqube_qualitygate_project_association.main: Creation complete after 0s [id=typescript_default/oncall-notifier-lambda]
module.sonarqube.sonarqube_qualityprofile_project_association.main["typescript_default"]: Creation complete after 0s [id=typescript_default/oncall-notifier-lambda]

Steps to Reproduce

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

  1. terraform apply

Try to associate a project using the "Sonar way" with a space

References

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

Wondering if this caused a separate problem or curious why it'd keep failing with a name lookup when there's a space

JacobWeyer commented 12 months ago

cc: @imightybigman

jdamata commented 11 months ago

Hopefully fixed here: https://github.com/jdamata/terraform-provider-sonarqube/pull/185

jdamata commented 11 months ago

Try the new released version and please close the issue if it's resolved

JacobWeyer commented 11 months ago

We updated and instead ran into this issue:

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Request cancelled
│
│   with module.sonarqube.sonarqube_qualityprofile_project_association.main["Sonar way"],
│   on modules/sonarqube_project_association/main.tf line 8, in resource "sonarqube_qualityprofile_project_association" "main":
│    8: resource "sonarqube_qualityprofile_project_association" "main" {
│
│ The plugin.(*GRPCProvider).ReadResource request was cancelled.
╵

Stack trace from the terraform-provider-sonarqube_v0.16.3 plugin:

panic: runtime error: index out of range [2] with length 2

goroutine 29 [running]:
github.com/jdamata/terraform-provider-sonarqube/sonarqube.resourceSonarqubeQualityProfileProjectAssociationRead(0x14000097d80, {0x1008a0e60?, 0x14000248540})
    github.com/jdamata/terraform-provider-sonarqube/sonarqube/resource_sonarqube_qualityprofile_project_association.go:133 +0xbd4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x1009d4da0?, {0x1009d4da0?, 0x14000500510?}, 0xd?, {0x1008a0e60?, 0x14000248540?})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:738 +0x138
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x140003190a0, {0x1009d4da0, 0x14000500510}, 0x140002ad1e0, {0x1008a0e60, 0x14000248540})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:1044 +0x494
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x1400031b860, {0x1009d4da0?, 0x140005003f0?}, 0x140004fa900)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/grpc_provider.go:616 +0x40c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x14000317220, {0x1009d4da0?, 0x1400050dc20?}, 0x14000518420)
    github.com/hashicorp/terraform-plugin-go@v0.16.0/tfprotov5/tf5server/server.go:751 +0x3ec
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x10099f6c0?, 0x14000317220}, {0x1009d4da0, 0x1400050dc20}, 0x140000c07e0, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.16.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:386 +0x174
google.golang.org/grpc.(*Server).processUnaryRPC(0x14000452000, {0x1009d7a60, 0x1400042d520}, 0x140002e9d40, 0x1400043def0, 0x100e63610, 0x0)
    google.golang.org/grpc@v1.56.0/server.go:1337 +0xc7c
google.golang.org/grpc.(*Server).handleStream(0x14000452000, {0x1009d7a60, 0x1400042d520}, 0x140002e9d40, 0x0)
    google.golang.org/grpc@v1.56.0/server.go:1714 +0x840
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.56.0/server.go:959 +0x88
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.56.0/server.go:957 +0x170

Error: The terraform-provider-sonarqube_v0.16.3 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
JacobWeyer commented 11 months ago

I think that length only gets to 3 when the quality profile has a space inside of it

jdamata commented 11 months ago

I think that happens because i changed the ID of sonarqube_qualityprofile_project_association: https://github.com/jdamata/terraform-provider-sonarqube/pull/185/files#diff-03d12c8bf13604680c7b2a9575f5c53d88d71659e59de99b84f0593bce0bd1f1R95

can you try to recreate the association or remove it from state and import it

JacobWeyer commented 11 months ago

Will do in the morning. Thanks for being responsive!

JacobWeyer commented 11 months ago

This worked FYI, thank you! Sorry I didn't get back to you