| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: MPL-2.0 |
| |
| // ---------------------------------------------------------------------------- |
| // |
| // *** AUTO GENERATED CODE *** Type: MMv1 *** |
| // |
| // ---------------------------------------------------------------------------- |
| // |
| // This file is automatically generated by Magic Modules and manual |
| // changes will be clobbered when the file is regenerated. |
| // |
| // Please read more about how to change this file in |
| // .github/CONTRIBUTING.md. |
| // |
| // ---------------------------------------------------------------------------- |
| |
| package cloudbuildv2_test |
| |
| import ( |
| "fmt" |
| "strings" |
| "testing" |
| |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| ) |
| |
| func TestAccCloudbuildv2Connection_cloudbuildv2ConnectionExample(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "random_suffix": acctest.RandString(t, 10), |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccCloudbuildv2Connection_cloudbuildv2ConnectionExample(context), |
| }, |
| { |
| ResourceName: "google_cloudbuildv2_connection.my-connection", |
| ImportState: true, |
| ImportStateVerify: true, |
| ImportStateVerifyIgnore: []string{"name", "location", "annotations"}, |
| }, |
| }, |
| }) |
| } |
| |
| func testAccCloudbuildv2Connection_cloudbuildv2ConnectionExample(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_cloudbuildv2_connection" "my-connection" { |
| location = "us-central1" |
| name = "tf-test-tf-test-connection%{random_suffix}" |
| |
| github_config { |
| app_installation_id = 0 |
| |
| authorizer_credential { |
| oauth_token_secret_version = "projects/gcb-terraform-creds/secrets/github-pat/versions/1" |
| } |
| } |
| } |
| `, context) |
| } |
| |
| func testAccCheckCloudbuildv2ConnectionDestroyProducer(t *testing.T) func(s *terraform.State) error { |
| return func(s *terraform.State) error { |
| for name, rs := range s.RootModule().Resources { |
| if rs.Type != "google_cloudbuildv2_connection" { |
| continue |
| } |
| if strings.HasPrefix(name, "data.") { |
| continue |
| } |
| |
| config := acctest.GoogleProviderConfig(t) |
| |
| url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{Cloudbuildv2BasePath}}projects/{{project}}/locations/{{location}}/connections/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| if config.BillingProject != "" { |
| billingProject = config.BillingProject |
| } |
| |
| _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "GET", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: config.UserAgent, |
| }) |
| if err == nil { |
| return fmt.Errorf("Cloudbuildv2Connection still exists at %s", url) |
| } |
| } |
| |
| return nil |
| } |
| } |