Skip to content

Commit

Permalink
Workflows: Add user defined environment variables feature to ga and u…
Browse files Browse the repository at this point in the history
…pdate tests (GoogleCloudPlatform#9406)
  • Loading branch information
pikapower authored and swamitagupta committed Nov 14, 2023
1 parent c36c5b0 commit 1b0e9b9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 188 deletions.
9 changes: 0 additions & 9 deletions mmv1/products/workflows/Workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ examples:
name: 'workflow'
account_id: 'my-account'
skip_import_test: true
- !ruby/object:Provider::Terraform::Examples
name: 'workflow_beta'
primary_resource_id: 'example_beta'
vars:
name: 'workflow_beta'
account_id: 'my-account'
skip_import_test: true
min_version: 'beta'
custom_code: !ruby/object:Provider::Terraform::CustomCode
extra_schema_entry: templates/terraform/extra_schema_entry/workflow.erb
encoder: templates/terraform/encoders/workflow.go.erb
Expand Down Expand Up @@ -118,6 +110,5 @@ properties:
Format: projects/{project}/locations/{location}/keyRings/{keyRing}/cryptoKeys/{cryptoKey}
- !ruby/object:Api::Type::KeyValuePairs
name: 'userEnvVars'
min_version: beta
description: |
User-defined environment variables associated with this workflow revision. This map has a maximum length of 20. Each string can take up to 40KiB. Keys cannot be empty strings and cannot start with “GOOGLE” or “WORKFLOWS".
5 changes: 4 additions & 1 deletion mmv1/templates/terraform/examples/workflow_basic.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ resource "google_workflows_workflow" "<%= ctx[:primary_resource_id] %>" {
labels = {
env = "test"
}
user_env_vars = {
url = "https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam"
}
source_contents = <<-EOF
# This is a sample workflow. You can replace it with your source code.
#
Expand All @@ -26,7 +29,7 @@ resource "google_workflows_workflow" "<%= ctx[:primary_resource_id] %>" {
- getCurrentTime:
call: http.get
args:
url: https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam
url: $${sys.get_env("url")}
result: currentTime
- readWikipedia:
call: http.get
Expand Down
47 changes: 0 additions & 47 deletions mmv1/templates/terraform/examples/workflow_beta.tf.erb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ resource "google_workflows_workflow" "example" {
name = "%s"
region = "us-central1"
description = "Magic"
user_env_vars = {
url = "https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam"
}
source_contents = <<-EOF
# This is a sample workflow, feel free to replace it with your source code
#
Expand All @@ -54,7 +57,7 @@ resource "google_workflows_workflow" "example" {
- getCurrentTime:
call: http.get
args:
url: https://us-central1-workflowsample.cloudfunctions.net/datetime
url: $${sys.get_env("url")}
result: CurrentDateTime
- readWikipedia:
call: http.get
Expand All @@ -77,6 +80,9 @@ resource "google_workflows_workflow" "example" {
name = "%s"
region = "us-central1"
description = "Magic"
user_env_vars = {
url = "https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam"
}
source_contents = <<-EOF
# This is a sample workflow, feel free to replace it with your source code
#
Expand All @@ -91,7 +97,7 @@ resource "google_workflows_workflow" "example" {
- getCurrentTime:
call: http.get
args:
url: https://us-central1-workflowsample.cloudfunctions.net/datetime
url: $${sys.get_env("url")}
result: CurrentDateTime
- readWikipedia:
call: http.get
Expand Down Expand Up @@ -213,132 +219,3 @@ EOF
`, workflowName, kmsKeyName)
}

<% unless version == 'ga' -%>
func TestAccWorkflowsWorkflowBeta_update(t *testing.T) {
// custom test to test updating
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckWorkflowsWorkflowDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccWorkflowsWorkflowBeta_full(context),
},
{
Config: testAccWorkflowsWorkflowBeta_update(context),
},
},
})
}


func testAccWorkflowsWorkflowBeta_full(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_service_account" "test_account" {
provider = google-beta
account_id = "tf-test-my-account%{random_suffix}"
display_name = "Test Service Account"
}

resource "google_workflows_workflow" "example_beta" {
provider = google-beta
name = "tf_test_workflow_beta%{random_suffix}"
region = "us-central1"
description = "Magic"
service_account = google_service_account.test_account.id
labels = {
env = "test"
}
user_env_vars = {
foo = "BAR"
}
source_contents = <<-EOF
# This is a sample workflow. You can replace it with your source code.
#
# This workflow does the following:
# - reads current time and date information from an external API and stores
# the response in currentTime variable
# - retrieves a list of Wikipedia articles related to the day of the week
# from currentTime
# - returns the list of articles as an output of the workflow
#
# Note: In Terraform you need to escape the $$ or it will cause errors.

- getCurrentTime:
call: http.get
args:
url: https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam
result: currentTime
- readWikipedia:
call: http.get
args:
url: https://en.wikipedia.org/w/api.php
query:
action: opensearch
search: $${currentTime.body.dayOfWeek}
result: wikiResult
- returnOutput:
return: $${wikiResult.body[1]}
EOF
}
`, context)
}

func testAccWorkflowsWorkflowBeta_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_service_account" "test_account" {
provider = google-beta
account_id = "tf-test-my-account%{random_suffix}"
display_name = "Test Service Account"
}

resource "google_workflows_workflow" "example_beta" {
provider = google-beta
name = "tf_test_workflow_beta%{random_suffix}"
region = "us-central1"
description = "Magic"
service_account = google_service_account.test_account.id
labels = {
env = "dev"
}
user_env_vars = {
bar = "FOO"
}
source_contents = <<-EOF
# This is a sample workflow. You can replace it with your source code.
#
# This workflow does the following:
# - reads current time and date information from an external API and stores
# the response in currentTime variable
# - retrieves a list of Wikipedia articles related to the day of the week
# from currentTime
# - returns the list of articles as an output of the workflow
#
# Note: In Terraform you need to escape the $$ or it will cause errors.

- getCurrentTime:
call: http.get
args:
url: https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam
result: currentTime
- readWikipedia:
call: http.get
args:
url: https://en.wikipedia.org/w/api.php
query:
action: opensearch
search: $${currentTime.body.dayOfWeek}
result: wikiResult
- returnOutput:
return: $${wikiResult.body[1]}
EOF
}
`, context)
}
<% end -%>

0 comments on commit 1b0e9b9

Please sign in to comment.