From b83073fa0dfc486984e9bd62595dc2c462af06fe Mon Sep 17 00:00:00 2001 From: Julia Matuszewska Date: Thu, 9 Jan 2025 21:46:42 +0000 Subject: [PATCH] Add force_destroy flag to CodeRepositoryIndex --- mmv1/products/gemini/CodeRepositoryIndex.yaml | 6 ++++++ .../pre_delete/code_repository_index_force_delete.go.tmpl | 8 ++++++-- .../resource_gemini_code_repository_index_test.go.tmpl | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mmv1/products/gemini/CodeRepositoryIndex.yaml b/mmv1/products/gemini/CodeRepositoryIndex.yaml index 9a397e041745..681db84a501e 100644 --- a/mmv1/products/gemini/CodeRepositoryIndex.yaml +++ b/mmv1/products/gemini/CodeRepositoryIndex.yaml @@ -56,6 +56,12 @@ custom_code: error_retry_predicates: - 'transport_tpg.IsCodeRepositoryIndexUnreadyError' - 'transport_tpg.IsRepositoryGroupQueueError' +virtual_fields: + - name: 'force_destroy' + description: + If set to true, any RepositoryGroups for this CodeRepositoryIndex will also be deleted. + type: Boolean + default_value: false parameters: - name: location type: String diff --git a/mmv1/templates/terraform/pre_delete/code_repository_index_force_delete.go.tmpl b/mmv1/templates/terraform/pre_delete/code_repository_index_force_delete.go.tmpl index dcd492c9d0f6..a451d1ece932 100644 --- a/mmv1/templates/terraform/pre_delete/code_repository_index_force_delete.go.tmpl +++ b/mmv1/templates/terraform/pre_delete/code_repository_index_force_delete.go.tmpl @@ -1,4 +1,8 @@ {{- if ne $.TargetVersionName "ga" -}} obj = make(map[string]interface{}) -obj["force"] = true -{{- end }} \ No newline at end of file +if v, ok := d.GetOk("force_destroy"); ok { + if v == true { + obj["force"] = true + } +} +{{- end }} diff --git a/mmv1/third_party/terraform/services/gemini/resource_gemini_code_repository_index_test.go.tmpl b/mmv1/third_party/terraform/services/gemini/resource_gemini_code_repository_index_test.go.tmpl index bc90b006b3b8..ddbd7c17168f 100644 --- a/mmv1/third_party/terraform/services/gemini/resource_gemini_code_repository_index_test.go.tmpl +++ b/mmv1/third_party/terraform/services/gemini/resource_gemini_code_repository_index_test.go.tmpl @@ -70,7 +70,7 @@ func TestAccGeminiCodeRepositoryIndex_delete(t *testing.T) { ResourceName: "google_gemini_code_repository_index.example", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"code_repository_index_id", "labels", "location", "terraform_labels"}, + ImportStateVerifyIgnore: []string{"code_repository_index_id", "labels", "location", "terraform_labels", "force_destroy"}, }, { Config: testAccGeminiCodeRepositoryIndex_withChildren_delete(context), @@ -88,6 +88,7 @@ resource "google_gemini_code_repository_index" "example" { labels = {"ccfe_debug_note": "terraform_e2e_should_be_deleted"} location = "us-central1" code_repository_index_id = "%{cri_id}" + force_destroy = true } resource "google_gemini_repository_group" "example" { @@ -100,6 +101,9 @@ resource "google_gemini_repository_group" "example" { branch_pattern = "main" } labels = {"label1": "value1"} + depends_on = [ + google_gemini_code_repository_index.example + ] } resource "google_developer_connect_git_repository_link" "conn" { @@ -129,6 +133,7 @@ resource "google_developer_connect_connection" "github_conn" { `, context) } +// Removed depends_on to not break plan test func testAccGeminiCodeRepositoryIndex_withChildren_delete(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_gemini_repository_group" "example" {