Skip to content

azuredevops_git_repository - allow disabling on destroy - #1580

Open
v-kenntan wants to merge 1 commit into
microsoft:mainfrom
v-kenntan:v-kenntan/1540
Open

azuredevops_git_repository - allow disabling on destroy#1580
v-kenntan wants to merge 1 commit into
microsoft:mainfrom
v-kenntan:v-kenntan/1540

Conversation

@v-kenntan

Copy link
Copy Markdown
Collaborator

All Submissions:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code follows the code style of this project.
  • Have you checked to ensure there aren't other open PRs for the same update/change?

Description

This PR adds a new property disable_on_destroy, which allows the user to disable the repository instead of destroying it if it's removed from the terraform configuration. The current disable flag will only work if the config still includes the repository resource, and the resource is destroyed when it is removed from the config. disable_on_destroy would help with allowing the user to remove the resource in the configuration without destroying the repository.

Does this introduce a breaking change?

  • Yes
  • No

Test Result

The tests seems to have racing conditions for the read and write, which means that it is inconsistent whenever it is run and will have different errors.

=== RUN   TestAccGitRepository_DataSource
=== PAUSE TestAccGitRepository_DataSource
=== RUN   TestAccGitRepository_DataSource_notExist
=== PAUSE TestAccGitRepository_DataSource_notExist
=== RUN   TestAccGitRepository_withDefaultBranch
=== PAUSE TestAccGitRepository_withDefaultBranch
=== RUN   TestAccGitRepository_update
=== PAUSE TestAccGitRepository_update
=== RUN   TestAccGitRepository_disabled
=== PAUSE TestAccGitRepository_disabled
=== RUN   TestAccGitRepository_disableOnDestroy
--- PASS: TestAccGitRepository_disableOnDestroy (25.07s)
=== RUN   TestAccGitRepository_disabledCannotUpdate
=== PAUSE TestAccGitRepository_disabledCannotUpdate
=== RUN   TestAccGitRepository_incorrectInitialization
=== PAUSE TestAccGitRepository_incorrectInitialization
=== RUN   TestAccGitRepository_importGitRepository
=== PAUSE TestAccGitRepository_importGitRepository
=== RUN   TestAccGitRepository_import_by_name
=== PAUSE TestAccGitRepository_import_by_name
=== RUN   TestAccGitRepository_initializationClean
=== PAUSE TestAccGitRepository_initializationClean
=== RUN   TestAccGitRepository_uninitialized
=== PAUSE TestAccGitRepository_uninitialized
=== RUN   TestAccGitRepository_forkBranchNotEmpty
=== PAUSE TestAccGitRepository_forkBranchNotEmpty
=== CONT  TestAccGitRepository_DataSource
--- PASS: TestAccGitRepository_DataSource (22.20s)
=== CONT  TestAccGitRepository_incorrectInitialization
--- PASS: TestAccGitRepository_incorrectInitialization (0.15s)
=== CONT  TestAccGitRepository_forkBranchNotEmpty
--- PASS: TestAccGitRepository_forkBranchNotEmpty (25.56s)
=== CONT  TestAccGitRepository_uninitialized
--- PASS: TestAccGitRepository_uninitialized (23.10s)
=== CONT  TestAccGitRepository_initializationClean
--- PASS: TestAccGitRepository_initializationClean (24.11s)
=== CONT  TestAccGitRepository_import_by_name
--- PASS: TestAccGitRepository_import_by_name (24.55s)
=== CONT  TestAccGitRepository_importGitRepository
--- PASS: TestAccGitRepository_importGitRepository (48.36s)
=== CONT  TestAccGitRepository_update
--- PASS: TestAccGitRepository_update (23.19s)
=== CONT  TestAccGitRepository_disabledCannotUpdate
    resource_git_repository_test.go:176: Step 3/3 error: Error running apply: exit status 1
        
        Error: Updating repository in Azure DevOps: TF401019: The Git repository with name or identifier b9a7f5fd-680b-4a5a-ba28-afbfd126cd7c does not exist or you do not have permissions for the operation you are attempting.
        
          with azuredevops_git_repository.test,
          on terraform_plugin_test.tf line 16, in resource "azuredevops_git_repository" "test":
          16: resource "azuredevops_git_repository" "test" {
        
--- FAIL: TestAccGitRepository_disabledCannotUpdate (25.56s)
=== CONT  TestAccGitRepository_disabled
--- PASS: TestAccGitRepository_disabled (25.34s)
=== CONT  TestAccGitRepository_withDefaultBranch
--- PASS: TestAccGitRepository_withDefaultBranch (34.09s)
=== CONT  TestAccGitRepository_DataSource_notExist
--- PASS: TestAccGitRepository_DataSource_notExist (21.67s)
FAIL

TestAccGitRepository_disabledCannotUpdate will suceed or fail depending on the race condition. The test is able to succeed after running it a couple more times.

=== RUN   TestAccGitRepository_disabledCannotUpdate
=== PAUSE TestAccGitRepository_disabledCannotUpdate
=== CONT  TestAccGitRepository_disabledCannotUpdate
--- PASS: TestAccGitRepository_disabledCannotUpdate (25.95s)
PASS

Related Issue(s)

Fix #1540

@magodo

Copy link
Copy Markdown
Member

Thanks for submitting this PR! In fact, I'm hesitated to merge this feature since this property is not a resource native property, but some "control" over the behavior of the resource. This kind of "control"-ish property can introduce other problems. For the original ask, I think the user would need to just do multiple steps to disable the repos and rm them from the state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azuredevops_git_repository - allow disabling on destroy

2 participants