From 194ce80b7b5b885a07265db294268637ac7c2084 Mon Sep 17 00:00:00 2001 From: Rohit Jangid Date: Thu, 18 Apr 2024 11:29:31 +0530 Subject: [PATCH] Replace client bootstrapping with individual resource --- mmv1/products/integrations/AuthConfig.yaml | 22 ++---------- .../integrations_auth_config_advance.tf.erb | 8 ++++- ...integrations_auth_config_auth_token.tf.erb | 8 ++++- .../integrations_auth_config_basic.tf.erb | 6 ++++ ...auth_config_client_certificate_only.tf.erb | 8 ++++- .../integrations_auth_config_jwt.tf.erb | 8 ++++- ...th_config_oauth2_authorization_code.tf.erb | 8 ++++- ...th_config_oauth2_client_credentials.tf.erb | 8 ++++- ...integrations_auth_config_oidc_token.tf.erb | 11 ++++-- ...rations_auth_config_service_account.tf.erb | 9 +++-- ...s_auth_config_username_and_password.tf.erb | 8 ++++- .../terraform/acctest/bootstrap_test_utils.go | 36 ------------------- .../resource_integrations_auth_config_test.go | 17 +++++++-- .../terraform/transport/config.go.erb | 15 -------- 14 files changed, 86 insertions(+), 86 deletions(-) diff --git a/mmv1/products/integrations/AuthConfig.yaml b/mmv1/products/integrations/AuthConfig.yaml index fd12618dbf11..f58f4dd9c8ea 100644 --- a/mmv1/products/integrations/AuthConfig.yaml +++ b/mmv1/products/integrations/AuthConfig.yaml @@ -419,54 +419,42 @@ examples: primary_resource_id: "basic_example" vars: auth_config_name: 'test-authconfig' - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist + skip_test: true # This is already part of other examples. - !ruby/object:Provider::Terraform::Examples name: "integrations_auth_config_advance" primary_resource_id: "advance_example" vars: auth_config_name: 'test-authconfig' - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist + skip_docs: true - !ruby/object:Provider::Terraform::Examples name: "integrations_auth_config_username_and_password" primary_resource_id: "username_and_password_example" vars: auth_config_name: 'test-authconfig-username-and-password' - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist skip_docs: true - !ruby/object:Provider::Terraform::Examples name: "integrations_auth_config_oauth2_authorization_code" primary_resource_id: "oauth2_authotization_code_example" vars: auth_config_name: 'test-authconfig-oauth2-authorization-code' - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist skip_docs: true - !ruby/object:Provider::Terraform::Examples name: "integrations_auth_config_oauth2_client_credentials" primary_resource_id: "oauth2_client_credentials_example" vars: auth_config_name: 'test-authconfig-oauth2-client-credentials' - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist skip_docs: true - !ruby/object:Provider::Terraform::Examples name: "integrations_auth_config_jwt" primary_resource_id: "jwt_example" vars: auth_config_name: 'test-authconfig-jwt' - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist skip_docs: true - !ruby/object:Provider::Terraform::Examples name: "integrations_auth_config_auth_token" primary_resource_id: "auth_token_example" vars: auth_config_name: 'test-authconfig-auth-token' - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist skip_docs: true - !ruby/object:Provider::Terraform::Examples name: "integrations_auth_config_service_account" @@ -474,8 +462,6 @@ examples: vars: auth_config_name: 'test-authconfig-service-account' service_account_id: sa - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist skip_docs: true - !ruby/object:Provider::Terraform::Examples name: "integrations_auth_config_oidc_token" @@ -483,14 +469,10 @@ examples: vars: auth_config_name: 'test-authconfig-oidc-token' service_account_id: sa - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist skip_docs: true - !ruby/object:Provider::Terraform::Examples name: "integrations_auth_config_client_certificate_only" primary_resource_id: "client_certificate_example" vars: auth_config_name: 'test-authconfig-client-certificate' - test_vars_overrides: - client: 'acctest.BootstrapIntegrationsClient(t, "us-west1").Name' # Added to ensure client exist skip_docs: true diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_advance.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_advance.tf.erb index a74067365035..d0aeb4c13158 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_advance.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_advance.tf.erb @@ -1,5 +1,10 @@ +resource "google_integrations_client" "client" { + location = "asia-east2" + provision_gmek = true +} + resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { - location = "us-west1" + location = "asia-east2" display_name = "<%= ctx[:vars]['auth_config_name'] %>" description = "Test auth config created via terraform" visibility = "CLIENT_VISIBLE" @@ -12,4 +17,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { password = "test-password" } } + depends_on = [google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_auth_token.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_auth_token.tf.erb index 64643554ce12..b9f2e7892548 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_auth_token.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_auth_token.tf.erb @@ -1,5 +1,10 @@ +resource "google_integrations_client" "client" { + location = "us-west2" + provision_gmek = true +} + resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { - location = "us-west1" + location = "us-west2" display_name = "<%= ctx[:vars]['auth_config_name'] %>" description = "Test auth config created via terraform" decrypted_credential { @@ -9,4 +14,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" } } + depends_on = [google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_basic.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_basic.tf.erb index b8dca975baec..13b1a5be514a 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_basic.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_basic.tf.erb @@ -1,3 +1,8 @@ +resource "google_integrations_client" "client" { + location = "us-west1" + provision_gmek = true +} + resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { location = "us-west1" display_name = "<%= ctx[:vars]['auth_config_name'] %>" @@ -9,4 +14,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { password = "test-password" } } + depends_on = [google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_client_certificate_only.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_client_certificate_only.tf.erb index 8d79728ac983..95707a3a4a0f 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_client_certificate_only.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_client_certificate_only.tf.erb @@ -1,5 +1,10 @@ +resource "google_integrations_client" "client" { + location = "us-west3" + provision_gmek = true +} + resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { - location = "us-west1" + location = "us-west3" display_name = "<%= ctx[:vars]['auth_config_name'] %>" description = "Test auth config created via terraform" decrypted_credential { @@ -55,4 +60,5 @@ UwKadZbfwbVF5ipu59UxfVE3lipf/mYePDqMkHVWv/8p+OnnJt9uKnyW8VSOu5uk EOT passphrase = "" } + depends_on = [google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_jwt.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_jwt.tf.erb index b02543f896e2..255158776eef 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_jwt.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_jwt.tf.erb @@ -1,5 +1,10 @@ +resource "google_integrations_client" "client" { + location = "us-west4" + provision_gmek = true +} + resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { - location = "us-west1" + location = "us-west4" display_name = "<%= ctx[:vars]['auth_config_name'] %>" description = "Test auth config created via terraform" decrypted_credential { @@ -10,4 +15,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { secret = "secret" } } + depends_on = [google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_oauth2_authorization_code.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_oauth2_authorization_code.tf.erb index a72d3767953c..d51cf5563ac9 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_oauth2_authorization_code.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_oauth2_authorization_code.tf.erb @@ -1,5 +1,10 @@ +resource "google_integrations_client" "client" { + location = "asia-east1" + provision_gmek = true +} + resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { - location = "us-west1" + location = "asia-east1" display_name = "<%= ctx[:vars]['auth_config_name'] %>" description = "Test auth config created via terraform" decrypted_credential { @@ -12,4 +17,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { token_endpoint = "https://authorization-server.com/token" } } + depends_on = [google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_oauth2_client_credentials.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_oauth2_client_credentials.tf.erb index 154462a293a9..8683a5d94413 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_oauth2_client_credentials.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_oauth2_client_credentials.tf.erb @@ -1,5 +1,10 @@ +resource "google_integrations_client" "client" { + location = "southamerica-east1" + provision_gmek = true +} + resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { - location = "us-west1" + location = "southamerica-east1" display_name = "<%= ctx[:vars]['auth_config_name'] %>" description = "Test auth config created via terraform" decrypted_credential { @@ -26,4 +31,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { } } } + depends_on = [google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_oidc_token.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_oidc_token.tf.erb index 6dcfe71dc6ec..c4714366144d 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_oidc_token.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_oidc_token.tf.erb @@ -1,18 +1,23 @@ +resource "google_integrations_client" "client" { + location = "us-south1" + provision_gmek = true +} + resource "google_service_account" "service_account" { account_id = "<%= ctx[:vars]['service_account_id'] %>" display_name = "Service Account" } resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { - location = "us-west1" + location = "us-south1" display_name = "<%= ctx[:vars]['auth_config_name'] %>" description = "Test auth config created via terraform" decrypted_credential { credential_type = "OIDC_TOKEN" oidc_token { service_account_email = google_service_account.service_account.email - audience = "https://us-west1-project.cloudfunctions.net/functionA 1234987819200.apps.googleusercontent.com" + audience = "https://us-south1-project.cloudfunctions.net/functionA 1234987819200.apps.googleusercontent.com" } } - depends_on = [google_service_account.service_account] + depends_on = [google_service_account.service_account, google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_service_account.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_service_account.tf.erb index 3ce06c775f5f..2408065c04a2 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_service_account.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_service_account.tf.erb @@ -1,10 +1,15 @@ +resource "google_integrations_client" "client" { + location = "northamerica-northeast1" + provision_gmek = true +} + resource "google_service_account" "service_account" { account_id = "<%= ctx[:vars]['service_account_id'] %>" display_name = "Service Account" } resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { - location = "us-west1" + location = "northamerica-northeast1" display_name = "<%= ctx[:vars]['auth_config_name'] %>" description = "Test auth config created via terraform" decrypted_credential { @@ -14,5 +19,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { scope = "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/adexchange.buyer https://www.googleapis.com/auth/admob.readonly" } } - depends_on = [google_service_account.service_account] + depends_on = [google_service_account.service_account, google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/integrations_auth_config_username_and_password.tf.erb b/mmv1/templates/terraform/examples/integrations_auth_config_username_and_password.tf.erb index b8dca975baec..d7283675acc4 100644 --- a/mmv1/templates/terraform/examples/integrations_auth_config_username_and_password.tf.erb +++ b/mmv1/templates/terraform/examples/integrations_auth_config_username_and_password.tf.erb @@ -1,5 +1,10 @@ +resource "google_integrations_client" "client" { + location = "northamerica-northeast2" + provision_gmek = true +} + resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { - location = "us-west1" + location = "northamerica-northeast2" display_name = "<%= ctx[:vars]['auth_config_name'] %>" description = "Test auth config created via terraform" decrypted_credential { @@ -9,4 +14,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" { password = "test-password" } } + depends_on = [google_integrations_client.client] } \ No newline at end of file diff --git a/mmv1/third_party/terraform/acctest/bootstrap_test_utils.go b/mmv1/third_party/terraform/acctest/bootstrap_test_utils.go index b3d723d0e40b..330f4bf2b5eb 100644 --- a/mmv1/third_party/terraform/acctest/bootstrap_test_utils.go +++ b/mmv1/third_party/terraform/acctest/bootstrap_test_utils.go @@ -22,10 +22,8 @@ import ( "google.golang.org/api/cloudbilling/v1" cloudkms "google.golang.org/api/cloudkms/v1" cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1" - "google.golang.org/api/googleapi" iam "google.golang.org/api/iam/v1" "google.golang.org/api/iamcredentials/v1" - integrations "google.golang.org/api/integrations/v1" "google.golang.org/api/servicenetworking/v1" "google.golang.org/api/serviceusage/v1" sqladmin "google.golang.org/api/sqladmin/v1beta4" @@ -1306,37 +1304,3 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t return accessToken, nil } - -type BootstrappedIntegrationsClient struct { - Name string -} - -func BootstrapIntegrationsClient(t *testing.T, region string) BootstrappedIntegrationsClient { - config := BootstrapConfig(t) - if config == nil { - return BootstrappedIntegrationsClient{} - } - - integrationsClient := config.NewIntegrationsClient(config.UserAgent) - - project := envvar.GetTestProjectFromEnv() - parent := fmt.Sprintf("projects/%s/locations/%s", project, region) - - _, err := integrationsClient.Projects.GetClientmetadata(parent).Do() - if err != nil { - if transport_tpg.IsGoogleApiErrorWithCode(err, 404) { - request := &integrations.GoogleCloudIntegrationsV1alphaProvisionClientRequest{} - opts := googleapi.QueryParameter("provisionGmek", "true") - _, err = integrationsClient.Projects.Locations.Clients.Provision(parent, request).Do(opts) - if err != nil { - t.Errorf("Unable to bootstrap Integrations client. Cannot provision client: %s", err) - } - } else { - t.Errorf("Unable to bootstrap KMS key. Cannot retrieve client: %s", err) - } - } - - return BootstrappedIntegrationsClient{ - Name: parent, - } -} diff --git a/mmv1/third_party/terraform/services/integrations/resource_integrations_auth_config_test.go b/mmv1/third_party/terraform/services/integrations/resource_integrations_auth_config_test.go index 829bd5a7ca28..f0eff0c1a50e 100644 --- a/mmv1/third_party/terraform/services/integrations/resource_integrations_auth_config_test.go +++ b/mmv1/third_party/terraform/services/integrations/resource_integrations_auth_config_test.go @@ -12,7 +12,6 @@ func TestAccIntegrationsAuthConfig_update(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "client": acctest.BootstrapIntegrationsClient(t, "us-west1").Name, "random_suffix": acctest.RandString(t, 10), } @@ -45,8 +44,13 @@ func TestAccIntegrationsAuthConfig_update(t *testing.T) { func testAccIntegrationsAuthConfig_full(context map[string]interface{}) string { return acctest.Nprintf(` +resource "google_integrations_client" "client" { + location = "southamerica-west1" + provision_gmek = true +} + resource "google_integrations_auth_config" "update_example" { - location = "us-west1" + location = "southamerica-west1" display_name = "tf-test-test-authconfig%{random_suffix}" description = "Test auth config created via terraform" visibility = "CLIENT_VISIBLE" @@ -59,14 +63,20 @@ resource "google_integrations_auth_config" "update_example" { password = "test-password" } } + depends_on = [google_integrations_client.client] } `, context) } func testAccIntegrationsAuthConfig_update(context map[string]interface{}) string { return acctest.Nprintf(` +resource "google_integrations_client" "client" { + location = "southamerica-west1" + provision_gmek = true +} + resource "google_integrations_auth_config" "update_example" { - location = "us-west1" + location = "southamerica-west1" display_name = "tf-test-test-authconfig-update%{random_suffix}" description = "Test auth config updated via terraform" visibility = "CLIENT_VISIBLE" @@ -125,6 +135,7 @@ UwKadZbfwbVF5ipu59UxfVE3lipf/mYePDqMkHVWv/8p+OnnJt9uKnyW8VSOu5uk EOT passphrase = "" } + depends_on = [google_integrations_client.client] } `, context) } diff --git a/mmv1/third_party/terraform/transport/config.go.erb b/mmv1/third_party/terraform/transport/config.go.erb index d1d862238c9c..3bace4f1d380 100644 --- a/mmv1/third_party/terraform/transport/config.go.erb +++ b/mmv1/third_party/terraform/transport/config.go.erb @@ -67,7 +67,6 @@ import ( healthcare "google.golang.org/api/healthcare/v1" "google.golang.org/api/iam/v1" iamcredentials "google.golang.org/api/iamcredentials/v1" - integrations "google.golang.org/api/integrations/v1" cloudlogging "google.golang.org/api/logging/v2" "google.golang.org/api/pubsub/v1" runadminv2 "google.golang.org/api/run/v2" @@ -1128,20 +1127,6 @@ func (c *Config) NewCloudRunV2Client(userAgent string) *runadminv2.Service { return clientRunAdminV2 } -func (c *Config) NewIntegrationsClient(userAgent string) *integrations.Service { - integrationsClientBasePath := RemoveBasePathVersion(RemoveBasePathVersion(c.IntegrationsBasePath)) - log.Printf("[INFO] Instantiating Google Cloud Integrations client for path %s", integrationsClientBasePath) - clientIntegrations, err := integrations.NewService(c.Context, option.WithHTTPClient(c.Client)) - if err != nil { - log.Printf("[WARN] Error creating client integrations: %s", err) - return nil - } - clientIntegrations.UserAgent = userAgent - clientIntegrations.BasePath = integrationsClientBasePath - - return clientIntegrations -} - // StaticTokenSource is used to be able to identify static token sources without reflection. type StaticTokenSource struct { oauth2.TokenSource