microsoft / terraform-provider-azuredevops

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

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

Open Pidgegeddon opened 3 months ago

Pidgegeddon commented 3 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