Skip to content

Commit

Permalink
Make GOOGLE_ORG_DOMAIN a test variable
Browse files Browse the repository at this point in the history
  • Loading branch information
drebes committed Mar 10, 2020
1 parent 770f40d commit 63bfc55
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions products/iap/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions provider/terraform/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]'
Expand Down
4 changes: 3 additions & 1 deletion templates/terraform/env_var_context.go.erb
Original file line number Diff line number Diff line change
@@ -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 -%>
Expand All @@ -16,4 +18,4 @@
<% elsif var_type == :FIRESTORE_PROJECT_NAME -%>
"<%= var_name -%>": getTestFirestoreProjectFromEnv(t),
<% end -%>
<% end -%>
<% end -%>
4 changes: 2 additions & 2 deletions templates/terraform/examples/iap_brand.tf.erb
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions templates/terraform/examples/iap_client.tf.erb
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion third_party/terraform/tests/resource_iap_brand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions third_party/terraform/utils/provider_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ var orgEnvVars = []string{
"GOOGLE_ORG",
}

var orgEnvDomainVars = []string{
"GOOGLE_ORG_DOMAIN",
}

var serviceAccountEnvVars = []string{
"GOOGLE_SERVICE_ACCOUNT",
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 63bfc55

Please sign in to comment.