azure-devopsterraformterraform-provider-azure

"Default" project-named Repo deletion by terraform in code


I would like to have only my "defined" repository with resource "azuredevops_git_repository" [MyRepo] and not have the system generated one uninitalized with project name [MyProject], is it possible somehow on code level ?

Provider : Terraform-azuredevops https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs/resources/git_repository

resource "azuredevops_git_repository" "repo" {
  project_id = azuredevops_project.project.id
  name       = "MyRepo"
  default_branch = "refs/heads/develop"
  initialization {
    init_type = "Clean"
}
  lifecycle {
    ignore_changes = [
      initialization,
      ]
    }
  }

resource "azuredevops_project" "project" {
  name               = "MyProject"
  description        = "MyDescription"
  visibility         = "private"
  version_control    = "Git"
  work_item_template = "Agile"
}

Could you please help me to find and elaborate on this answer ?

Thank you in advance,

After I deleted the default repository from the Web UI of Azure DevOps, Terraform did not indicated any change on the code level, So I can not understand how can I prevent the "default" repository creation on code level e.g. by the resource "azuredevops_git_repository" or the project definition


Solution

  • as my knowledge, the Terraform-Azure DevOps provider can be used to configure Azure DevOps project in Microsoft Azure using Azure DevOps Service REST API.

    For the create project rest api, there isn't a parameter to change the default repo name.

    Thus here are two ways for your reference: 1.After creating a new project->do your shown 'create defined name repo' step, you could call corresponding delete repo rest api to delete the default repo (since a project needs at least one repo exists). 2.After creating a new project, you could directly rename the default repo by calling the rest api update repo.

    I hope it could do some help.