| // 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 iap_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/envvar" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| ) |
| |
| func TestAccIapClient_iapClientExample(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "org_id": envvar.GetTestOrgFromEnv(t), |
| "org_domain": envvar.GetTestOrgDomainFromEnv(t), |
| "random_suffix": acctest.RandString(t, 10), |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| CheckDestroy: testAccCheckIapClientDestroyProducer(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccIapClient_iapClientExample(context), |
| }, |
| { |
| ResourceName: "google_iap_client.project_client", |
| ImportState: true, |
| ImportStateVerify: true, |
| ImportStateVerifyIgnore: []string{"brand"}, |
| }, |
| }, |
| }) |
| } |
| |
| func testAccIapClient_iapClientExample(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_project" "project" { |
| project_id = "tf-test-my-project%{random_suffix}" |
| name = "tf-test-my-project%{random_suffix}" |
| org_id = "%{org_id}" |
| } |
| |
| resource "google_project_service" "project_service" { |
| project = google_project.project.project_id |
| service = "iap.googleapis.com" |
| } |
| |
| resource "google_iap_brand" "project_brand" { |
| support_email = "support@%{org_domain}" |
| application_title = "Cloud IAP protected Application" |
| project = google_project_service.project_service.project |
| } |
| |
| resource "google_iap_client" "project_client" { |
| display_name = "Test Client" |
| brand = google_iap_brand.project_brand.name |
| } |
| `, context) |
| } |
| |
| func testAccCheckIapClientDestroyProducer(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_iap_client" { |
| continue |
| } |
| if strings.HasPrefix(name, "data.") { |
| continue |
| } |
| |
| config := acctest.GoogleProviderConfig(t) |
| |
| url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{IapBasePath}}{{brand}}/identityAwareProxyClients/{{client_id}}") |
| 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, |
| ErrorRetryPredicates: []transport_tpg.RetryErrorPredicateFunc{transport_tpg.IapClient409Operation}, |
| }) |
| if err == nil { |
| return fmt.Errorf("IapClient still exists at %s", url) |
| } |
| } |
| |
| return nil |
| } |
| } |