terraform-provider-azuredevops icon indicating copy to clipboard operation
terraform-provider-azuredevops copied to clipboard

Cannot add team to another team

Open themaroqa opened this issue 2 years ago • 3 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and Azure DevOps Provider) Version

Terraform v1.2.7 provider registry.terraform.io/microsoft/azuredevops v0.2.2

Affected Resource(s)

  • azuredevops_team_members (https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs/resources/team_members)

Terraform Configuration Files

# Configure the Azure provider
terraform {
  required_providers {
    azuredevops = {
      source = "microsoft/azuredevops"
      version = "0.2.2"
    }
  }
}

resource "azuredevops_project" "example" {
  name               = "Example Project"
  work_item_template = "Agile"
  version_control    = "Git"
  visibility         = "private"
  description        = "Managed by Terraform"
}

data "azuredevops_team" "default_team" {
  project_id = azuredevops_project.example.id
  name = "${azuredevops_project.example.name} Team"
}

data "azuredevops_group" "example-project-contributors" {
  project_id = azuredevops_project.example.id
  name       = "Contributors"
}

data "azuredevops_group" "example-project-readers" {
  project_id = azuredevops_project.example.id
  name       = "Readers"
}

resource "azuredevops_team" "example" {
  project_id = azuredevops_project.example.id
  name       = "${azuredevops_project.example.name} Team 2"
  administrators = [
    data.azuredevops_group.example-project-contributors.descriptor
  ]
  members = [
    data.azuredevops_group.example-project-readers.descriptor
  ]
}

resource "azuredevops_team_members" "default-team-members" {
  project_id = azuredevops_team.example.project_id
  team_id    = data.azuredevops_team.default_team.id
  mode       = "add"
  members = [
    azuredevops_team.example.name
  ]
}

Debug Output

Panic Output

Expected Behavior

It should have added the "example Team 2" team to the "example Team" default team.

Actual Behavior

module.example.azuredevops_team_members.default-team-members: Creating...
╷
│ Error: The string must have at least one character.
│ Parameter name: descriptors element.IdentityType
│ 
│   with module.example.azuredevops_team_members.default-team-members,
│   on example/main.tf line 45, in resource "azuredevops_team_members" "default-team-members":
│   45: resource "azuredevops_team_members" "default-team-members" {
│ 
╵

Steps to Reproduce

  1. terraform apply

Important Factoids

References

themaroqa avatar Oct 05 '22 12:10 themaroqa

@themaroqa to ref another team member as the member, you should use the members not the name:

resource "azuredevops_team" "example" {
  project_id = data.azuredevops_project.example.id
  name       = "${data.azuredevops_project.example.name} Team 2"
  administrators = [
    data.azuredevops_group.example-project-contributors.descriptor
  ]
  members = [
    data.azuredevops_group.example-project-readers.descriptor
  ]
}

resource "azuredevops_team_members" "default-team-members" {
  project_id = azuredevops_team.example.project_id
  team_id    = data.azuredevops_team.default_team.id
  mode       = "add"
  members = azuredevops_team.example.members
}

xuzhang3 avatar Oct 09 '22 07:10 xuzhang3

@xuzhang3 I am not sure your modification is right. Firstly because I'd like to have the team added and not the members (doing so if I add a new member directly from Azure DevOps it'll inherite the permission of the first team). Besides that I tried your solution but it doesn't work for me:

╷
│ Error: Incorrect attribute value type
│ 
│   on example/main.tf line 49, in resource "azuredevops_team_members" "default-team-members":
│   49:   members = [
│   50:     azuredevops_team.example.members
│   51:   ]
│     ├────────────────
│     │ azuredevops_team.example.members is set of string with 1 element
│ 
│ Inappropriate value for attribute "members": element 0: string required.
╵

themaroqa avatar Oct 10 '22 15:10 themaroqa

@themaroqa To add the team as the members, you need to convert the team ID to descriptor then you can use the descriptor as the members(API: https://learn.microsoft.com/en-us/rest/api/azure/devops/graph/descriptors/get?view=azure-devops-rest-6.0&tabs=HTTP). This is a new feature not supported, #528 is tracking on this feature.

azuredevops_team.example.members is type Set. Change

members = [
      azuredevops_team.example.members
]

to

    members = azuredevops_team.example.members

xuzhang3 avatar Oct 11 '22 03:10 xuzhang3