Closed dawwestk closed 2 months ago
@dawwestk Can you share more details? I know there is a case where the project is not returned, but I can't reproduce it.
Hi @xuzhang3, no problem, here are the steps to reproduce:
resource "azuredevops_serviceendpoint_sonarqube" "sonarqube" {
for_each = local.svc_conns
project_id = each.value.project
service_endpoint_name = "sonarqube"
url = "https://my-sonarqube.com"
token = "token1234"
description = "managed by Terraform"
}
import {
for_each = local.svc_conns
to = azuredevops_serviceendpoint_sonarqube.sonarqube[each.key]
id = "${each.value.project}/${each.value.id}"
}
locals {
svc_conns = {
"projectA" = {
"project" = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"id" = "<svc-conn-ID>"
}
"projectB" = {
"project" = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"id" = "<svc-conn-ID>"
}
}
}
Attempting to apply the code above should fail with the error message in my original comment. With my update it should give a normal terraform error.
Let me know if you need any more info - cheers
Hi @xuzhang3, no problem, here are the steps to reproduce:
- Enable the SonarQube extension in your Azure DevOps org
- Create 2 Azure DevOps Projects
- Manually create a SonarQube service connection in one Project, then share it with the other (the connection will now appear in both Projects with the same ID)
- Use import blocks to bring the existing/legacy connections into terraform state
resource "azuredevops_serviceendpoint_sonarqube" "sonarqube" { for_each = local.svc_conns project_id = each.value.project service_endpoint_name = "sonarqube" url = "https://my-sonarqube.com" token = "token1234" description = "managed by Terraform" } import { for_each = local.svc_conns to = azuredevops_serviceendpoint_sonarqube.sonarqube[each.key] id = "${each.value.project}/${each.value.id}" } locals { svc_conns = { "projectA" = { "project" = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "id" = "<svc-conn-ID>" } "projectB" = { "project" = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", "id" = "<svc-conn-ID>" } } }
Attempting to apply the code above should fail with the error message in my original comment. With my update it should give a normal terraform error.
Let me know if you need any more info - cheers
I know why this happens. The service connection needs to be import was destroyed, but the service does not return a 404, but a 200. We need to handle the response correctly
Thanks @xuzhang3 - updated as per your comment
=== RUN TestAccServiceEndpointSonarQube_basic
=== PAUSE TestAccServiceEndpointSonarQube_basic
=== RUN TestAccServiceEndpointSonarQube_complete
=== PAUSE TestAccServiceEndpointSonarQube_complete
=== RUN TestAccServiceEndpointSonarQube_update
=== PAUSE TestAccServiceEndpointSonarQube_update
=== RUN TestAccServiceEndpointSonarQube_RequiresImportErrorStep
=== PAUSE TestAccServiceEndpointSonarQube_RequiresImportErrorStep
=== CONT TestAccServiceEndpointSonarQube_basic
=== CONT TestAccServiceEndpointSonarQube_update
=== CONT TestAccServiceEndpointSonarQube_complete
=== CONT TestAccServiceEndpointSonarQube_RequiresImportErrorStep
--- PASS: TestAccServiceEndpointSonarQube_complete (84.29s)
--- PASS: TestAccServiceEndpointSonarQube_RequiresImportErrorStep (90.73s)
--- PASS: TestAccServiceEndpointSonarQube_basic (123.55s)
--- PASS: TestAccServiceEndpointSonarQube_update (165.15s)
PASS
ok github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests 165.605s
All Submissions:
What about the current behavior has changed?
The SonarQube service endpoint is now checked for a valid project ID and returns an appropriate error message if one is not found.
This solves the issue shown in the logs below which occurred when trying to import a service endpoint that had been shared between projects. As these resources are imported using their (shared) ID, the error below occurred once the original endpoint had been deleted, thus leaving no associated project ID.
The nil check is the same as for the kubernetes service endpoint.
Does this introduce a change to
go.mod
,go.sum
orvendor/
?Does this introduce a breaking change?
Any relevant logs, error output, etc?