Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workflows): add user_env_vars field + tests #9342

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mmv1/products/workflows/Workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ 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 @@ -108,3 +116,8 @@ properties:
The KMS key used to encrypt workflow and execution data.
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".
47 changes: 47 additions & 0 deletions mmv1/templates/terraform/examples/workflow_beta.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
resource "google_service_account" "test_account" {
provider = google-beta
account_id = "<%= ctx[:vars]['account_id'] %>"
display_name = "Test Service Account"
}

resource "google_workflows_workflow" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['name'] %>"
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
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% autogen_exception -%>
package workflows_test

import (
Expand Down Expand Up @@ -211,3 +212,133 @@ 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 -%>