microsoft / terraform-provider-azuredevops

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

Support creating `azuredevops_git_repository` with import using signed in account #1076

Open Pidgegeddon opened 5 months ago

Pidgegeddon commented 5 months ago

Community Note

Description

Our team would like to be able to create new repos based on a private template repo we have. We currently need to supply a service connection with PAT to import this repo without creating a fork. Instead of using this service connection, we would like this resource to try creating the repo using the signed-in user/principal that the provider uses for other operations.

New or Affected Resource(s)

Potential Terraform Configuration

Simply omitting the argument initialization.service_connection_id in the resource azuredevops_git_repository should try creating the repo with initialization type import using the logged-in user

data "azuredevops_project" "example" {
  name = "Example Project"
}

data "azuredevops_git_repository" "example_source_repo" {
  project_id = data.azuredevops_project.example.id
  name       = "Source Repository" #private repo
}

resource "azuredevops_git_repository" "example" {
  project_id = data.azuredevops_project.example.id
  name       = "copied git repo"
  initialization {
    init_type   = "Import"
    source_type = "Git"
    source_url  = data.azuredevops_git_repository.example_source_repo.remote_url
  }
}

References

Importing repos like this was added in #0402, but since then this provider has added the support for login with a Service Connection in #0747

xuzhang3 commented 2 weeks ago

@Pidgegeddon Service account/SPN login user cannot be used to import repositories. In fact, the credentials used to import repository are delegated to the service connection