microsoft / terraform-provider-azuredevops

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

`azuredevops_check_exclusive_lock` with `target_resource_type = "repository"` not working as expected #1042

Closed liyaoz closed 1 month ago

liyaoz commented 1 month ago

Community Note

Terraform (and Azure DevOps Provider) Version

Terraform version 18.3 Azure DevOps Provider version 1.0.1

Affected Resource(s)

Terraform Configuration Files

data "azuredevops_project" "test" {
  name = "MY_TEST_PROJECT"
}

data "azuredevops_git_repository" "test_repo" {
  project_id = data.azuredevops_project.test.id
  name       = "my.test.repo"
}

resource "azuredevops_check_exclusive_lock" "azdo_repo_lock" {
  project_id           = data.azuredevops_project.test.id
  target_resource_id   = data.azuredevops_git_repository.test_repo.id
  target_resource_type = "repository"

  timeout = 30
}

Expected Behavior

An exclusive lock created on the repo

Actual Behavior

β•·
β”‚ Error:  failed creating check, project ID: 8d49xxxx-xxxx-xxxx-xxxx-xxxx6745xxxx. Error: Invalid resource id. 5310xxxx-xxxx-xxxx-xxxx-xxxxd0b8xxxx
β”‚ 
β”‚   with azuredevops_check_exclusive_lock.azdo_repo_lock,
β”‚   on main.tf line 1, in resource "azuredevops_check_exclusive_lock" "azdo_repo_lock":
β”‚    1: resource "azuredevops_check_exclusive_lock" "azdo_repo_lock" {
β”‚ 
β•΅
FAIL

Steps to Reproduce

  1. terraform apply

Workaround / RCA

I captured the network communication when creating this lock on the UI. The payload has "id" as "{projectID}.{repoID}" instead of just "{repoID}", i.e.

"resource": {
  "id": "8d49xxxx-xxxx-xxxx-xxxx-xxxx6745xxxx.5310xxxx-xxxx-xxxx-xxxx-xxxxd0b8xxxx",
  "name": "my.test.repo"
  "type" : "repository"
}

So I have this workaround in my Terraform configuration, and it is working for now:

resource "azuredevops_check_exclusive_lock" "azdo_repo_lock" {
  project_id           = data.azuredevops_project.test.id
  target_resource_id   = "${data.azuredevops_project.test.id}.${data.azuredevops_git_repository.test_repo.id}"
  target_resource_type = "repository"

  timeout = 30
}

But I wish I could just use the expected ${data.azuredevops_git_repository.test_repo.id} or have the documentation letting me know that I have to prefix the project ID here.

Thanks!

References

azuredevops/check_exclusive_lock

xuzhang3 commented 1 month ago

@liyaoz the resource ID has changed, add the check exclusive for repo requires the resource ID in projectID.repoId format. The ID format is required by service not this provider.