Skip to content

Commit

Permalink
Replace client bootstrapping with individual resource
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitjangid committed Apr 18, 2024
1 parent aaa8984 commit 194ce80
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 86 deletions.
22 changes: 2 additions & 20 deletions mmv1/products/integrations/AuthConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,78 +419,60 @@ 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"
primary_resource_id: "service_account_example"
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"
primary_resource_id: "oidc_token_example"
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
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -12,4 +17,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" {
password = "test-password"
}
}
depends_on = [google_integrations_client.client]
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -9,4 +14,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" {
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
}
}
depends_on = [google_integrations_client.client]
}
Original file line number Diff line number Diff line change
@@ -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'] %>"
Expand All @@ -9,4 +14,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" {
password = "test-password"
}
}
depends_on = [google_integrations_client.client]
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -55,4 +60,5 @@ UwKadZbfwbVF5ipu59UxfVE3lipf/mYePDqMkHVWv/8p+OnnJt9uKnyW8VSOu5uk
EOT
passphrase = ""
}
depends_on = [google_integrations_client.client]
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,4 +15,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" {
secret = "secret"
}
}
depends_on = [google_integrations_client.client]
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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]
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -26,4 +31,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" {
}
}
}
depends_on = [google_integrations_client.client]
}
Original file line number Diff line number Diff line change
@@ -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]
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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]
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -9,4 +14,5 @@ resource "google_integrations_auth_config" "<%= ctx[:primary_resource_id] %>" {
password = "test-password"
}
}
depends_on = [google_integrations_client.client]
}
36 changes: 0 additions & 36 deletions mmv1/third_party/terraform/acctest/bootstrap_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -125,6 +135,7 @@ UwKadZbfwbVF5ipu59UxfVE3lipf/mYePDqMkHVWv/8p+OnnJt9uKnyW8VSOu5uk
EOT
passphrase = ""
}
depends_on = [google_integrations_client.client]
}
`, context)
}
Loading

0 comments on commit 194ce80

Please sign in to comment.