@@ -2,6 +2,7 @@ package gemini_test
2
2
{{- if ne $.TargetVersionName "ga" }}
3
3
4
4
import (
5
+ "fmt"
5
6
"os"
6
7
"testing"
7
8
@@ -44,6 +45,136 @@ func TestAccGeminiCodeRepositoryIndex_update(t *testing.T) {
44
45
})
45
46
}
46
47
48
+ // TestAccGeminiCodeRepositoryIndex_delete checks if there is no error in deleting CRI along with children resource
49
+ // note: this is an example of a bad usage, where RGs refer to the CRI using a string id, not a reference, as they
50
+ // will be force-removed upon CRI deletion, because the CRI provider uses --force option by default
51
+ // The plan after the _delete function should not be empty due to the child resource in plan
52
+ func TestAccGeminiCodeRepositoryIndex_delete(t *testing.T) {
53
+ bootstrappedKMS := acctest.BootstrapKMSKeyInLocation(t, "us-central1")
54
+ randomSuffix := acctest.RandString(t, 10)
55
+ context := map[string]interface{}{
56
+ "random_suffix": randomSuffix,
57
+ "project_id": os.Getenv("GOOGLE_PROJECT"),
58
+ "kms_key": bootstrappedKMS.CryptoKey.Name,
59
+ "cri_id": fmt.Sprintf("tf-test-cri-index-delete-example-%s", randomSuffix),
60
+ }
61
+
62
+ acctest.VcrTest(t, resource.TestCase{
63
+ PreCheck: func() { acctest.AccTestPreCheck(t) },
64
+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
65
+ Steps: []resource.TestStep{
66
+ {
67
+ Config: testAccGeminiCodeRepositoryIndex_withChildren_basic(context),
68
+ },
69
+ {
70
+ ResourceName: "google_gemini_code_repository_index.example",
71
+ ImportState: true,
72
+ ImportStateVerify: true,
73
+ ImportStateVerifyIgnore: []string{"code_repository_index_id", "labels", "location", "terraform_labels", "force_destroy"},
74
+ },
75
+ {
76
+ Config: testAccGeminiCodeRepositoryIndex_withChildren_delete(context),
77
+ ExpectNonEmptyPlan: true,
78
+ PlanOnly: true,
79
+ },
80
+ },
81
+ })
82
+ }
83
+
84
+ func testAccGeminiCodeRepositoryIndex_withChildren_basic(context map[string]interface{}) string {
85
+ return acctest.Nprintf(`
86
+ resource "google_gemini_code_repository_index" "example" {
87
+ provider = google-beta
88
+ labels = {"ccfe_debug_note": "terraform_e2e_should_be_deleted"}
89
+ location = "us-central1"
90
+ code_repository_index_id = "%{cri_id}"
91
+ force_destroy = true
92
+ }
93
+
94
+ resource "google_gemini_repository_group" "example" {
95
+ provider = google-beta
96
+ location = "us-central1"
97
+ code_repository_index = "%{cri_id}"
98
+ repository_group_id = "tf-test-rg-repository-group-id-%{random_suffix}"
99
+ repositories {
100
+ resource = "projects/%{project_id}/locations/us-central1/connections/${google_developer_connect_connection.github_conn.connection_id}/gitRepositoryLinks/${google_developer_connect_git_repository_link.conn.git_repository_link_id}"
101
+ branch_pattern = "main"
102
+ }
103
+ labels = {"label1": "value1"}
104
+ depends_on = [
105
+ google_gemini_code_repository_index.example
106
+ ]
107
+ }
108
+
109
+ resource "google_developer_connect_git_repository_link" "conn" {
110
+ provider = google-beta
111
+ git_repository_link_id = "tf-test-repository-conn-delete"
112
+ parent_connection = google_developer_connect_connection.github_conn.connection_id
113
+ clone_uri = "https://github.com/CC-R-github-robot/tf-test.git"
114
+ location = "us-central1"
115
+ annotations = {}
116
+ }
117
+
118
+ resource "google_developer_connect_connection" "github_conn" {
119
+ provider = google-beta
120
+ location = "us-central1"
121
+ connection_id = "tf-test-cloudaicompanion-delete-%{random_suffix}"
122
+ disabled = false
123
+
124
+ github_config {
125
+ github_app = "DEVELOPER_CONNECT"
126
+ app_installation_id = 54180648
127
+
128
+ authorizer_credential {
129
+ oauth_token_secret_version = "projects/502367051001/secrets/tf-test-cloudaicompanion-github-oauthtoken-c42e5c/versions/1"
130
+ }
131
+ }
132
+ }
133
+ `, context)
134
+ }
135
+
136
+ // Removed depends_on to not break plan test
137
+ func testAccGeminiCodeRepositoryIndex_withChildren_delete(context map[string]interface{}) string {
138
+ return acctest.Nprintf(`
139
+ resource "google_gemini_repository_group" "example" {
140
+ provider = google-beta
141
+ location = "us-central1"
142
+ code_repository_index = "%{cri_id}"
143
+ repository_group_id = "tf-test-rg-repository-group-id-%{random_suffix}"
144
+ repositories {
145
+ resource = "projects/%{project_id}/locations/us-central1/connections/${google_developer_connect_connection.github_conn.connection_id}/gitRepositoryLinks/${google_developer_connect_git_repository_link.conn.git_repository_link_id}"
146
+ branch_pattern = "main"
147
+ }
148
+ labels = {"label1": "value1"}
149
+ }
150
+
151
+ resource "google_developer_connect_git_repository_link" "conn" {
152
+ provider = google-beta
153
+ git_repository_link_id = "tf-test-repository-conn-delete"
154
+ parent_connection = google_developer_connect_connection.github_conn.connection_id
155
+ clone_uri = "https://github.com/CC-R-github-robot/tf-test.git"
156
+ location = "us-central1"
157
+ annotations = {}
158
+ }
159
+
160
+ resource "google_developer_connect_connection" "github_conn" {
161
+ provider = google-beta
162
+ location = "us-central1"
163
+ connection_id = "tf-test-cloudaicompanion-delete-%{random_suffix}"
164
+ disabled = false
165
+
166
+ github_config {
167
+ github_app = "DEVELOPER_CONNECT"
168
+ app_installation_id = 54180648
169
+
170
+ authorizer_credential {
171
+ oauth_token_secret_version = "projects/502367051001/secrets/tf-test-cloudaicompanion-github-oauthtoken-c42e5c/versions/1"
172
+ }
173
+ }
174
+ }
175
+ `, context)
176
+ }
177
+
47
178
func testAccGeminiCodeRepositoryIndex_basic(context map[string]interface{}) string {
48
179
return acctest.Nprintf(`
49
180
resource "google_gemini_code_repository_index" "example" {
0 commit comments