microsoft / terraform-provider-azuredevops

Terraform Azure DevOps provider
https://www.terraform.io/docs/providers/azuredevops/
MIT License
380 stars 271 forks source link

Plugin crash - on using org level access SP to retreive project name #1174

Open mnkll opened 6 days ago

mnkll commented 6 days ago

When using your provider to set a project scoped agent queue, on the latest terraform 1.9.6 and provider version, it explodes in low orbit. The used SP has access rights to Devops on org level.

Stack trace from the terraform-provider-azuredevops_v1.3.0 plugin:

panic: interface conversion: interface {} is nil, not string

goroutine 88 [running]:
github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/taskagent.resourceAgentQueueCreate(0xc000575780, {0xdc2840, 0xc000572820})
github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/taskagent/resource_agent_queue.go:73 +0x2c5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x1136328?, {0x1136328?, 0xc000675860?}, 0xd?, {0xdc2840?, 0xc000572820?})
github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:695 +0x155
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000472700, {0x1136328, 0xc000675860}, 0xc000515e10, 0xc0002c1e80, {0xdc2840, 0xc000572820})
github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:837 +0xa5e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000010018, {0x1136328?, 0xc0006757a0?}, 0xc0002cbd10)
github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/grpc_provider.go:1021 +0xd5c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0000e8000, {0x1136328?, 0xc000674fc0?}, 0xc0002d9500)
github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/tf5server/server.go:818 +0x56f
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xf78fc0, 0xc0000e8000}, {0x1136328, 0xc000674fc0}, 0xc0002d9490, 0x0)
github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002d61e0, {0x113abc0, 0xc0000d0d00}, 0xc00067c120, 0xc0000c7320, 0x1772b20, 0x0)
google.golang.org/grpc@v1.56.3/server.go:1335 +0xdb8
google.golang.org/grpc.(*Server).handleStream(0xc0002d61e0, {0x113abc0, 0xc0000d0d00}, 0xc00067c120, 0x0)
google.golang.org/grpc@v1.56.3/server.go:1712 +0x9da
google.golang.org/grpc.(*Server).serveStreams.func1.1()
google.golang.org/grpc@v1.56.3/server.go:947 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 31
google.golang.org/grpc@v1.56.3/server.go:958 +0x136

Error: The terraform-provider-azuredevops_v1.3.0 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.

The code in question to reproduce:

azuredevops = {
  source  = "microsoft/azuredevops"
  version = "1.3.0"
}
...
provider "azuredevops" {
  client_id       = var.tf_sp_client_id
  client_secret   = var.tf_sp_client_secret
  tenant_id       = var.tenant_id
  org_service_url = "https://dev.azure.com/${var.devops_org_name}"
}

data "azuredevops_project" "project" {
  name = var.devops_project_name
}

resource "azuredevops_agent_queue" "queue" {
  name       = lower("${local.resource_prefix}-mdp")
  project_id = data.azuredevops_project.project.id
}
xuzhang3 commented 4 days ago

@mnkll can you help check if the queue name is set a expected, the error show this the name for the configuration is nil not any string

mnkll commented 3 days ago

@mnkll can you help check if the queue name is set a expected, the error show this the name for the configuration is nil not any string

@xuzhang3 I tried it with a plain string again:

data "azuredevops_project" "project" {
  name = var.devops_project_name
}

resource "azuredevops_agent_queue" "queue" {
  name       = "tf-test-name" # lower("${local.resource_prefix}-mdp")
  project_id = data.azuredevops_project.project.id
}

devops_project_name is akin to "BAAR-1234_FOO" and works for a devops pool created before

same error:

Stack trace from the terraform-provider-azuredevops_v1.3.0 plugin:

...

{"@level":"info","@message":"azuredevops_agent_queue.queue: Creating...","@module":"terraform.ui","@timestamp":"2024-09-30T09:01:36.233600Z","hook":{"resource":{"addr":"azuredevops_agent_queue.queue","module":"","resource":"azuredevops_agent_queue.queue","implied_provider":"azuredevops","resource_type":"azuredevops_agent_queue","resource_name":"queue","resource_key":null},"action":"create"},"type":"apply_start"}
{"@level":"info","@message":"azuredevops_agent_queue.queue: Creation errored after 0s","@module":"terraform.ui","@timestamp":"2024-09-30T09:01:36.247044Z","hook":{"resource":{"addr":"azuredevops_agent_queue.queue","module":"","resource":"azuredevops_agent_queue.queue","implied_provider":"azuredevops","resource_type":"azuredevops_agent_queue","resource_name":"queue","resource_key":null},"action":"create","elapsed_seconds":0},"type":"apply_errored"}

...

{"@level":"info","@message":"module.managed_devops_pool.azapi_resource.managed_devops_pool: Still modifying... [10s elapsed]","@module":"terraform.ui","@timestamp":"2024-09-30T09:01:47.240664Z","hook":{"resource":{"addr":"module.managed_devops_pool.azapi_resource.managed_devops_pool","module":"module.managed_devops_pool","resource":"azapi_resource.managed_devops_pool","implied_provider":"azapi","resource_type":"azapi_resource","resource_name":"managed_devops_pool","resource_key":null},"action":"update","elapsed_seconds":10},"type":"apply_progress"}

...

panic: interface conversion: interface {} is nil, not string

goroutine 90 [running]:
github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/taskagent.resourceAgentQueueCreate(0xc000056680, {0xdc2840, 0xc0005609c0})
    github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/taskagent/resource_agent_queue.go:73 +0x2c5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x1136328?, {0x1136328?, 0xc00053d950?}, 0xd?, {0xdc2840?, 0xc0005609c0?})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:695 +0x155
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000472700, {0x1136328, 0xc00053d950}, 0xc0004ed380, 0xc000056500, {0xdc2840, 0xc0005609c0})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:837 +0xa5e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000416000, {0x1136328?, 0xc00053d890?}, 0xc0006e1bd0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/grpc_provider.go:1021 +0xd5c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0002da820, {0x1136328?, 0xc00053d0b0?}, 0xc00070b1f0)
    github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/tf5server/server.go:818 +0x56f
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xf78fc0, 0xc0002da820}, {0x1136328, 0xc00053d0b0}, 0xc00070b180, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002d61e0, {0x113abc0, 0xc0000d6d00}, 0xc000347d40, 0xc00049a630, 0x1772b20, 0x0)
    google.golang.org/grpc@v1.56.3/server.go:1335 +0xdb8
google.golang.org/grpc.(*Server).handleStream(0xc0002d61e0, {0x113abc0, 0xc0000d6d00}, 0xc000347d40, 0x0)
    google.golang.org/grpc@v1.56.3/server.go:1712 +0x9da
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.56.3/server.go:947 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 15
    google.golang.org/grpc@v1.56.3/server.go:958 +0x136

Error: The terraform-provider-azuredevops_v1.3.0 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.

Operation failed: failed running terraform apply (exit 1)

Perhaps the fact that it seems to create the queue before the managed devops pool is created, leads to some value being zero when it attempts to assign from existing pools? Also, I don't think this is of any relevance but this is running via Terraform Cloud on 1.9.6, it also occured on previous versions down to 1.9 though.

mnkll commented 1 day ago

@xuzhang3 We tried multiple things. It is not an auth issue as pat or sp do not make a difference and it manages to correctly pull the project id anyway. On the subject of the latter we also tried hardcoding that one but as it was pulled correctly before this resulted in no change. We also tried making the project depending on the pool, no difference here.

Any further help is appreciated, until then we will resort to curling the ADO api.

mnkll commented 1 day ago

@xuzhang3 Further testing narrows this down to creating a queue with the name property, while using the agent_pool_id works fine (though it is optional), when using the name property it explodes with this error everytime