microsoft / terraform-provider-azuredevops

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

Fix to support project creation on Azure Devops "Server" #104

Open altinoren opened 3 years ago

altinoren commented 3 years ago

Community Note

Description

Hi, I'm investigating the possibility of using Azure DevOps provider on an on-premises installation of Azure DevOps Server for a client. Documentation does not mention supporting Server edition anywhere, but API's are almost identical I thought it might work. It doesn't, but the fix might be simple.

The configuration mentioned at the end gives the following error when applied against Azure DevOps Server 2019 and Server 2020 RC1:

Error: Error flattening project: Error parsing Work Item Template ID, got : invalid UUID length: 0

At this state, the project is already created but the provider fails when trying to retrieve data for process_template_id attribute. The error is caused by the differences between AzDO Services and AzDO Server when returning project capabilities (Url is _apis/projects/{guid}?api-version=5.1&includeCapabilities=true for both).

Server
    "capabilities": {
        "processTemplate": {
            "templateName": "Scrum"
        },
        "versioncontrol": {
            "sourceControlType": "Git",
            "gitEnabled": "True",
            "tfvcEnabled": "False"
        }
    }
Services
    "capabilities": {
        "processTemplate": {
            "templateName": "Scrum",
            "templateTypeId": "6b724908-ef14-45cf-84f8-768b5384da45"
        },
        "versioncontrol": {
            "sourceControlType": "Git",
            "gitEnabled": "True",
            "tfvcEnabled": "False"
        }
    },

templateTypeId is not returned by Azure DevOps Server for API versions 1.0 to 5.1 (and 6.0 in RC1). Hence, this line can't get it and faults in the subsequent use of it: https://github.com/terraform-providers/terraform-provider-azuredevops/blob/24d9cf048fa6baacb4eb416c726b7db4678490d5/azuredevops/internal/service/core/resource_project.go#L390-L391

Line 391 is redundant since template name is already known through capabilities returned by the API call. On Line 390, templateTypeId might be available (Services) or not (Server).

To fix the error when it's not available, there's already a method to call to get template id when template name is known: https://github.com/terraform-providers/terraform-provider-azuredevops/blob/24d9cf048fa6baacb4eb416c726b7db4678490d5/azuredevops/internal/service/core/resource_project.go#L421

Is Azure DevOps Server is supported? If so, would you fix this? If not, would you accept a PR to fix this?

Thanks.

(Tests against Server edition performed on DevOps VM)

New or Affected Resource(s)

Potential Terraform Configuration

provider "azuredevops" {
  version = ">= 0.0.1"
  org_service_url  = "http://vsalm:8080/tfs/DefaultCollection"
  personal_access_token = "removed"
}

resource "azuredevops_project" "p" {
  project_name  = "First Project"
  description   = "First Project Description"
  version_control   = "Git"
  work_item_template    = "Scrum"
}

resource "azuredevops_git_repository" "p_repo" {
  project_id = azuredevops_project.p.id
  name       = "Framework"
  initialization {
    init_type = "Clean"
  }
}

References

none

xuzhang3 commented 3 years ago

Hi @altinoren Currently, we have no plan to support Azure DevOps Server. You can submit PR to fix this as you have mentioned in this issues, templateTypeId has been returned in capabilities. But I cannot guarantee that other resource can work correct with Azure DevOps Server.