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