From 63bfc55f8e7a001ca9748caf8ae90190a45dd39f Mon Sep 17 00:00:00 2001 From: Roberto Jung Drebes Date: Mon, 9 Mar 2020 23:42:47 +0100 Subject: [PATCH] Make GOOGLE_ORG_DOMAIN a test variable --- products/iap/terraform.yaml | 2 ++ provider/terraform/examples.rb | 1 + templates/terraform/env_var_context.go.erb | 4 +++- templates/terraform/examples/iap_brand.tf.erb | 4 ++-- templates/terraform/examples/iap_client.tf.erb | 4 ++-- third_party/terraform/tests/resource_iap_brand_test.go | 3 ++- third_party/terraform/utils/provider_test.go.erb | 9 +++++++++ 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/products/iap/terraform.yaml b/products/iap/terraform.yaml index f3d26a38dd41..0c6e5a7df61a 100644 --- a/products/iap/terraform.yaml +++ b/products/iap/terraform.yaml @@ -167,6 +167,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides project_id: 'brand-proj-' test_env_vars: org_id: :ORG_ID + org_domain: :ORG_DOMAIN skip_test: true custom_code: !ruby/object:Provider::Terraform::CustomCode custom_delete: templates/terraform/custom_delete/skip_delete.go.erb @@ -184,6 +185,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides project_id: 'brand-proj-' test_env_vars: org_id: :ORG_ID + org_domain: :ORG_DOMAIN docs: !ruby/object:Provider::Terraform::Docs attributes: | * `client_id`: The OAuth2 ID of the client. diff --git a/provider/terraform/examples.rb b/provider/terraform/examples.rb index d038871b6781..2d37aabeac04 100644 --- a/provider/terraform/examples.rb +++ b/provider/terraform/examples.rb @@ -122,6 +122,7 @@ def config_documentation CREDENTIALS: 'my/credentials/filename.json', REGION: 'us-west1', ORG_ID: '123456789', + ORG_DOMAIN: 'example.com', ORG_TARGET: '123456789', BILLING_ACCT: '000000-0000000-0000000-000000', SERVICE_ACCT: 'emailAddress:my@service-account.com' diff --git a/templates/terraform/env_var_context.go.erb b/templates/terraform/env_var_context.go.erb index 35f6ab8610a2..d0809f7520be 100644 --- a/templates/terraform/env_var_context.go.erb +++ b/templates/terraform/env_var_context.go.erb @@ -1,6 +1,8 @@ <% example.test_env_vars&.each do |var_name, var_type| -%> <% if var_type == :ORG_ID -%> "<%= var_name -%>": getTestOrgFromEnv(t), + <% elsif var_type == :ORG_DOMAIN -%> + "<%= var_name -%>": getTestOrgDomainFromEnv(t), <% elsif var_type == :CREDENTIALS -%> "<%= var_name -%>": getTestCredsFromEnv(t), <% elsif var_type == :REGION -%> @@ -16,4 +18,4 @@ <% elsif var_type == :FIRESTORE_PROJECT_NAME -%> "<%= var_name -%>": getTestFirestoreProjectFromEnv(t), <% end -%> -<% end -%> \ No newline at end of file +<% end -%> diff --git a/templates/terraform/examples/iap_brand.tf.erb b/templates/terraform/examples/iap_brand.tf.erb index fc44ffc64f19..1767b33c0f41 100644 --- a/templates/terraform/examples/iap_brand.tf.erb +++ b/templates/terraform/examples/iap_brand.tf.erb @@ -1,7 +1,7 @@ resource "google_project" "project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" + org_id = "<%= ctx[:test_env_vars]['org_id'] %>" } resource "google_project_service" "project_service" { @@ -10,7 +10,7 @@ resource "google_project_service" "project_service" { } resource "google_iap_brand" "project_brand" { - support_email = "support@example.com" + support_email = "support@<%= ctx[:test_env_vars]['org_domain'] %>" application_title = "Cloud IAP protected Application" project = google_project_service.project_service.project } diff --git a/templates/terraform/examples/iap_client.tf.erb b/templates/terraform/examples/iap_client.tf.erb index 9f24e72c7119..e06015f6118b 100644 --- a/templates/terraform/examples/iap_client.tf.erb +++ b/templates/terraform/examples/iap_client.tf.erb @@ -1,7 +1,7 @@ resource "google_project" "project" { project_id = "tf-test%{random_suffix}" name = "tf-test%{random_suffix}" - org_id = "%{org_id}" + org_id = "<%= ctx[:test_env_vars]['org_id'] %>" } resource "google_project_service" "project_service" { @@ -10,7 +10,7 @@ resource "google_project_service" "project_service" { } resource "google_iap_brand" "project_brand" { - support_email = "support@example.com" + support_email = "support@<%= ctx[:test_env_vars]['org_domain'] %>" application_title = "Cloud IAP protected Application" project = google_project_service.project_service.project } diff --git a/third_party/terraform/tests/resource_iap_brand_test.go b/third_party/terraform/tests/resource_iap_brand_test.go index 251299e03e90..2a35fe4133ad 100644 --- a/third_party/terraform/tests/resource_iap_brand_test.go +++ b/third_party/terraform/tests/resource_iap_brand_test.go @@ -12,6 +12,7 @@ func TestAccIapBrand_iapBrandExample(t *testing.T) { context := map[string]interface{}{ "org_id": getTestOrgFromEnv(t), + "org_domain": getTestOrgDomainFromEnv(t), "random_suffix": acctest.RandString(10), } @@ -46,7 +47,7 @@ resource "google_project_service" "project_service" { } resource "google_iap_brand" "project_brand" { - support_email = "support@example.com" + support_email = "support@%{org_domain}" application_title = "Cloud IAP protected Application" project = google_project_service.project_service.project } diff --git a/third_party/terraform/utils/provider_test.go.erb b/third_party/terraform/utils/provider_test.go.erb index a5082bd29e7b..5970333929ba 100644 --- a/third_party/terraform/utils/provider_test.go.erb +++ b/third_party/terraform/utils/provider_test.go.erb @@ -63,6 +63,10 @@ var orgEnvVars = []string{ "GOOGLE_ORG", } +var orgEnvDomainVars = []string{ + "GOOGLE_ORG_DOMAIN", +} + var serviceAccountEnvVars = []string{ "GOOGLE_SERVICE_ACCOUNT", } @@ -669,6 +673,11 @@ func getTestOrgFromEnv(t *testing.T) string { return multiEnvSearch(orgEnvVars) } +func getTestOrgDomainFromEnv(t *testing.T) string { + skipIfEnvNotSet(t, orgEnvDomainVars...) + return multiEnvSearch(orgEnvDomainVars) +} + func getTestOrgTargetFromEnv(t *testing.T) string { skipIfEnvNotSet(t, orgTargetEnvVars...) return multiEnvSearch(orgTargetEnvVars)