layout | page_title | description |
---|---|---|
azuredevops |
AzureDevops: azuredevops_git_repository |
Manages a git repository within Azure DevOps organization. |
Manages a git repository within Azure DevOps.
~>NOTE Importing an existing repository and running terraform plan
will detect a difference on the initialization
block. The plan
and apply
will then attempt to update the repository based on the initialization
configurations. It may be necessary to ignore the initialization
block from plan
and apply
to support configuring existing repositories imported into Terraform state.
~>NOTE 1. initialization.init_type
is Uninitialized
: Changing source_type
or source_url
will not recreate the repository, but initialize the repository.
2. initialization.init_type
is not Uninitialized
:
1) Updating init_type
will recreate the repository
2) Updating source_type
or source_url
will recreate the repository
resource "azuredevops_project" "example" {
name = "Example Project"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "example" {
project_id = azuredevops_project.example.id
name = "Example Git Repository"
default_branch = "refs/heads/main"
initialization {
init_type = "Clean"
}
lifecycle {
ignore_changes = [
# Ignore changes to initialization to support importing existing repositories
# Given that a repo now exists, either imported into terraform state or created by terraform,
# we don't care for the configuration of initialization against the existing resource
initialization,
]
}
}
resource "azuredevops_project" "example" {
name = "Example Project"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "example" {
project_id = azuredevops_project.example.id
name = "Example Empty Git Repository"
initialization {
init_type = "Clean"
}
}
resource "azuredevops_project" "example" {
name = "Example Project"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "example" {
project_id = azuredevops_project.example.id
name = "Example Git Repository"
default_branch = "refs/heads/main"
initialization {
init_type = "Clean"
}
lifecycle {
ignore_changes = [
# Ignore changes to initialization to support importing existing repositories
# Given that a repo now exists, either imported into terraform state or created by terraform,
# we don't care for the configuration of initialization against the existing resource
initialization,
]
}
}
resource "azuredevops_project" "example" {
name = "Example Project"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "example" {
project_id = azuredevops_project.example.id
name = "Example Git Repository"
default_branch = "refs/heads/main"
initialization {
init_type = "Clean"
}
}
resource "azuredevops_git_repository" "example-fork" {
project_id = azuredevops_project.example.id
name = "Example Fork Repository"
parent_repository_id = azuredevops_git_repository.example.id
initialization {
init_type = "Fork"
}
}
resource "azuredevops_project" "example" {
name = "Example Project"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "example" {
project_id = azuredevops_project.example.id
name = "Example Git Repository"
default_branch = "refs/heads/main"
initialization {
init_type = "Clean"
}
}
resource "azuredevops_git_repository" "example-import" {
project_id = azuredevops_project.example.id
name = "Example Import Repository"
initialization {
init_type = "Import"
source_type = "Git"
source_url = "https://github.com/microsoft/terraform-provider-azuredevops.git"
}
}
resource "azuredevops_project" "example" {
name = "Example Project"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "example" {
project_id = azuredevops_project.example.id
name = "Example Git Repository"
default_branch = "refs/heads/main"
initialization {
init_type = "Clean"
}
}
resource "azuredevops_serviceendpoint_generic_git" "example-serviceendpoint" {
project_id = azuredevops_project.example.id
repository_url = "https://dev.azure.com/org/project/_git/repository"
username = "username"
password = "<password>/<PAT>"
service_endpoint_name = "Example Generic Git"
description = "Managed by Terraform"
}
# with service connection
resource "azuredevops_git_repository" "example-import" {
project_id = azuredevops_project.example.id
name = "Example Import Existing Repository"
initialization {
init_type = "Import"
source_type = "Git"
source_url = "https://dev.azure.com/example-org/private-repository.git"
service_connection_id = azuredevops_serviceendpoint_generic_git.example-serviceendpoint.id
}
}
# with username/password
resource "azuredevops_git_repository" "example-import2" {
project_id = azuredevops_project.example.id
name = "Example Import Existing Repository"
initialization {
init_type = "Import"
source_type = "Git"
source_url = "https://dev.azure.com/example-org/private-repository.git"
username = "username"
password = "password"
}
}
resource "azuredevops_project" "example" {
name = "Example Project"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "example" {
project_id = azuredevops_project.example.id
name = "Example Empty Git Repository"
disabled = true
initialization {
init_type = "Clean"
}
}
The following arguments are supported:
-
project_id
- (Required) The project ID or project name. -
name
- (Required) The name of the git repository. -
initialization
- (Required) Ainitialization
block as documented below.
-
parent_repository_id
- (Optional) The ID of a Git project from which a fork is to be created. -
disabled
- (Optional) The ability to disable or enable the repository. Defaults tofalse
.
A initialization
- block supports the following:
-
init_type
- (Required) The type of repository to create. Valid values:Uninitialized
,Clean
orImport
. -
source_type
- (Optional) Type of the source repository. Used if theinit_type
isImport
. Valid values:Git
. -
source_url
- (Optional) The URL of the source repository. Used if theinit_type
isImport
. -
service_connection_id
(Optional) The ID of service connection used to authenticate to a private repository for import initialization. Conflicts withusername
andpassword
. -
username
(Optional) The username used to authenticate to a private repository for import initialization. Conflicts withservice_connection_id
. -
password
(Optional) The password used to authenticate to a private repository for import initialization. Conflicts withservice_connection_id
.~>Note At least
service_connection_id
orusername/password
needs to be set to import private repository.
In addition to all arguments above, except initialization
, the following attributes are exported:
id
- The ID of the Git repository.default_branch
- The ref of the default branch. Will be used as the branch name for initialized repositories.is_fork
- True if the repository was created as a fork.remote_url
- Git HTTPS URL of the repositorysize
- Size in bytes.ssh_url
- Git SSH URL of the repository.url
- REST API URL of the repository.web_url
- Web link to the repository.
The timeouts
block allows you to specify timeouts for certain actions:
create
- (Defaults to 10 minutes) Used when creating the Git Repository.read
- (Defaults to 5 minute) Used when retrieving the Git Repository.update
- (Defaults to 10 minutes) Used when updating the Git Repository.delete
- (Defaults to 10 minutes) Used when deleting the Git Repository.
Azure DevOps Repositories can be imported using the repo name or by the repo Guid e.g.
terraform import azuredevops_git_repository.example projectName/repoName
or
terraform import azuredevops_git_repository.example projectName/00000000-0000-0000-0000-000000000000
- Code: Read, Create, & Manage.