Skip to content

Commit 82152a0

Browse files
BENY4M1Nniharika-98
authored andcommitted
Add tags and workflow_tags fields to google_workflows_workflow resource. Fixes b/374990996 (GoogleCloudPlatform#12085)
1 parent 5dae42a commit 82152a0

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

mmv1/products/workflows/Workflow.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ examples:
5757
exclude_import_test: true
5858
ignore_read_extra:
5959
- 'deletion_protection'
60+
- name: 'workflow_tags'
61+
primary_resource_id: 'example'
62+
vars:
63+
name: 'workflow'
64+
account_id: 'my-account'
65+
tag_key: 'tag_key'
66+
tag_value: 'tag_value'
67+
exclude_import_test: true
68+
ignore_read_extra:
69+
- 'deletion_protection'
6070
virtual_fields:
6171
- name: 'deletion_protection'
6272
description: |
@@ -146,3 +156,11 @@ properties:
146156
type: KeyValuePairs
147157
description: |
148158
User-defined environment variables associated with this workflow revision. This map has a maximum length of 20. Each string can take up to 4KiB. Keys cannot be empty strings and cannot start with “GOOGLE” or “WORKFLOWS".
159+
- name: 'tags'
160+
type: KeyValuePairs
161+
description: |
162+
A map of resource manager tags. Resource manager tag keys and values have the same definition
163+
as resource manager tags. Keys must be in the format tagKeys/{tag_key_id}, and values are in
164+
the format tagValues/456. The field is ignored (both PUT & PATCH) when empty.
165+
immutable: true
166+
ignore_read: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_tags_tag_key" "tag_key" {
5+
parent = "projects/${data.google_project.project.number}"
6+
short_name = "{{index $.Vars "tag_key"}}"
7+
}
8+
9+
resource "google_tags_tag_value" "tag_value" {
10+
parent = "tagKeys/${google_tags_tag_key.tag_key.name}"
11+
short_name = "{{index $.Vars "tag_value"}}"
12+
}
13+
14+
resource "google_service_account" "test_account" {
15+
account_id = "{{index $.Vars "account_id"}}"
16+
display_name = "Test Service Account"
17+
}
18+
19+
resource "google_workflows_workflow" "{{$.PrimaryResourceId}}" {
20+
name = "{{index $.Vars "name"}}"
21+
region = "us-central1"
22+
description = "Magic"
23+
service_account = google_service_account.test_account.id
24+
deletion_protection = false
25+
tags = {
26+
"${data.google_project.project.project_id}/${google_tags_tag_key.tag_key.short_name}" = "${google_tags_tag_value.tag_value.short_name}"
27+
}
28+
source_contents = <<-EOF
29+
# This is a sample workflow. You can replace it with your source code.
30+
#
31+
# This workflow does the following:
32+
# - reads current time and date information from an external API and stores
33+
# the response in currentTime variable
34+
# - retrieves a list of Wikipedia articles related to the day of the week
35+
# from currentTime
36+
# - returns the list of articles as an output of the workflow
37+
#
38+
# Note: In Terraform you need to escape the $$ or it will cause errors.
39+
40+
- getCurrentTime:
41+
call: http.get
42+
args:
43+
url: $${sys.get_env("url")}
44+
result: currentTime
45+
- readWikipedia:
46+
call: http.get
47+
args:
48+
url: https://en.wikipedia.org/w/api.php
49+
query:
50+
action: opensearch
51+
search: $${currentTime.body.dayOfWeek}
52+
result: wikiResult
53+
- returnOutput:
54+
return: $${wikiResult.body[1]}
55+
EOF
56+
}

mmv1/third_party/terraform/services/workflows/resource_workflows_workflow_test.go.tmpl

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ resource "google_workflows_workflow" "example" {
4444
url = "https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam"
4545
}
4646
deletion_protection = false
47+
tags = {
48+
env = "test"
49+
}
4750
source_contents = <<-EOF
4851
# This is a sample workflow, feel free to replace it with your source code
4952
#
@@ -86,6 +89,9 @@ resource "google_workflows_workflow" "example" {
8689
url = "https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam"
8790
}
8891
deletion_protection = false
92+
tags = {
93+
env = "test"
94+
}
8995
source_contents = <<-EOF
9096
# This is a sample workflow, feel free to replace it with your source code
9197
#

0 commit comments

Comments
 (0)