Update git_repository.html.markdown
Added additional information about supporting future configuration of Git repositories imported into Terraform state
@@ -30,6 +30,34 @@ resource "azuredevops_git_repository" "repo" {
}
```
+### Configure existing Git repository imported into Terraform state
+
+```hcl
+resource "azuredevops_project" "project" {
+ name = "Sample Project"
+ visibility = "private"
+ version_control = "Git"
+ work_item_template = "Agile"
+}
+
+resource "azuredevops_git_repository" "repo" {
+ project_id = azuredevops_project.project.id
+ name = "Existing 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,
+ ]
+ }
+}
+```
+
### Create Fork of another Azure DevOps Git repository
```hcl
@@ -128,3 +156,23 @@ or
```sh
$ terraform import azuredevops_git_repository.repository projectName/00000000-0000-0000-0000-000000000000
```
+**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 delete the repository and recreate it so that the configuration matches. The initialization block must be ignored from the plan in order to support configuring existing repositories imported into Terraform state.
+
+```hcl
+resource "azuredevops_git_repository" "repo" {
+ project_id = azuredevops_project.project.id
+ name = "Existing 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,
+ ]
+ }
+}
+```
