Skip to content

Commit dc66fdd

Browse files
feat: Adding Submodule for Standalone Workflow for ADC (#54)
Co-authored-by: Bharath KKB <bharathkrishnakb@gmail.com>
1 parent ef12d10 commit dc66fdd

32 files changed

Lines changed: 1695 additions & 302 deletions

File tree

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Make will use bash instead of sh
1919
SHELL := /usr/bin/env bash
2020

21-
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1
21+
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.25
2222
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
2323
REGISTRY_URL := gcr.io/cloud-foundation-cicd
2424

@@ -62,7 +62,7 @@ docker_test_integration:
6262
-e SERVICE_ACCOUNT_JSON \
6363
-v "$(CURDIR)":/workspace \
6464
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
65-
/usr/local/bin/test_integration.sh
65+
cft test run all
6666

6767
# Execute lint tests within the docker container
6868
.PHONY: docker_test_lint
@@ -77,9 +77,10 @@ docker_test_lint:
7777
.PHONY: docker_generate_docs
7878
docker_generate_docs:
7979
docker run --rm -it \
80+
-e ENABLE_BPMETADATA=1 \
8081
-v "$(CURDIR)":/workspace \
8182
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
82-
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate_docs'
83+
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate_docs display --per-module-requirements'
8384

8485
# Alias for backwards compatibility
8586
.PHONY: generate_docs

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ module "cloud_workflow" {
3232
- getCurrentTime:
3333
call: http.get
3434
args:
35-
url: https://us-central1-workflowsample.cloudfunctions.net/datetime
35+
url: https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam
3636
result: CurrentDateTime
3737
- readWikipedia:
3838
call: http.get
3939
args:
4040
url: https://en.wikipedia.org/w/api.php
4141
query:
4242
action: opensearch
43-
search: $${CurrentDateTime.body.dayOfTheWeek}
43+
search: $${CurrentDateTime.body.dayOfWeek}
4444
result: WikiResult
4545
- returnOutput:
4646
return: $${WikiResult.body[1]}
@@ -72,15 +72,15 @@ module "cloud_workflow" {
7272
- getCurrentTime:
7373
call: http.get
7474
args:
75-
url: https://us-central1-workflowsample.cloudfunctions.net/datetime
75+
url: https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam
7676
result: CurrentDateTime
7777
- readWikipedia:
7878
call: http.get
7979
args:
8080
url: https://en.wikipedia.org/w/api.php
8181
query:
8282
action: opensearch
83-
search: $${CurrentDateTime.body.dayOfTheWeek}
83+
search: $${CurrentDateTime.body.dayOfWeek}
8484
result: WikiResult
8585
- returnOutput:
8686
return: $${WikiResult.body[1]}

build/int.cloudbuild.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ steps:
3030
- id: simple-example-apply
3131
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
3232
args: ['/bin/bash', '-c', 'cft test run all --stage apply --verbose']
33+
waitFor:
34+
- simple-example-init
3335
- id: simple-example-verify
3436
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
3537
args: ['/bin/bash', '-c', 'cft test run all --stage verify --verbose']
38+
waitFor:
39+
- simple-example-apply
3640
- id: simple-example-teardown
3741
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
3842
args: ['/bin/bash', '-c', 'cft test run all --stage teardown --verbose']
43+
waitFor:
44+
- simple-example-verify
3945
tags:
4046
- 'ci'
4147
- 'integration'

examples/gcs_event_arc_trigger_workflow/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ resource "google_project_iam_binding" "project" {
5555
}
5656

5757
resource "random_string" "string" {
58-
length = 8
58+
length = 4
5959
lower = true
6060
upper = false
6161
special = false
@@ -66,9 +66,10 @@ module "service_account" {
6666
source = "terraform-google-modules/service-accounts/google"
6767
version = "~> 4.1.1"
6868
project_id = var.project_id
69-
prefix = "gcs-eventarc-workflow"
69+
prefix = "eventarc-wf-${random_string.string.result}"
7070
names = ["simple"]
7171
project_roles = ["${var.project_id}=>roles/workflows.invoker",
72+
"${var.project_id}=>roles/eventarc.serviceAgent",
7273
"${var.project_id}=>roles/eventarc.eventReceiver"]
7374
}
7475

examples/pubsub_event_arc_trigger_workflow/main.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ resource "google_pubsub_topic" "event_arc" {
2222
project = var.project_id
2323
}
2424

25+
resource "random_string" "string" {
26+
length = 4
27+
lower = true
28+
upper = false
29+
special = false
30+
numeric = false
31+
}
32+
2533
module "service_account" {
2634
source = "terraform-google-modules/service-accounts/google"
2735
version = "~> 4.1.1"
2836
project_id = var.project_id
29-
prefix = "eventarc-workflow"
37+
prefix = "eventarc-wf-${random_string.string.result}"
3038
names = ["simple"]
3139
project_roles = ["${var.project_id}=>roles/workflows.invoker"]
3240
}

examples/schedule_workflow/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ module "cloud_workflow" {
5757
- getCurrentTime:
5858
call: http.get
5959
args:
60-
url: https://us-central1-workflowsample.cloudfunctions.net/datetime
60+
url: https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam
6161
result: CurrentDateTime
6262
- readWikipedia:
6363
call: http.get
6464
args:
6565
url: https://en.wikipedia.org/w/api.php
6666
query:
6767
action: opensearch
68-
search: $${CurrentDateTime.body.dayOfTheWeek}
68+
search: $${CurrentDateTime.body.dayOfWeek}
6969
result: WikiResult
7070
- returnOutput:
7171
return: $${WikiResult.body[1]}

examples/schedule_workflow_autocreate_sa/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ module "cloud_workflow" {
4848
- getCurrentTime:
4949
call: http.get
5050
args:
51-
url: https://us-central1-workflowsample.cloudfunctions.net/datetime
51+
url: https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam
5252
result: CurrentDateTime
5353
- readWikipedia:
5454
call: http.get
5555
args:
5656
url: https://en.wikipedia.org/w/api.php
5757
query:
5858
action: opensearch
59-
search: $${CurrentDateTime.body.dayOfTheWeek}
59+
search: $${CurrentDateTime.body.dayOfWeek}
6060
result: WikiResult
6161
- returnOutput:
6262
return: $${WikiResult.body[1]}

examples/simple_workflow/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
## Inputs
3+
4+
| Name | Description | Type | Default | Required |
5+
|------|-------------|------|---------|:--------:|
6+
| project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes |
7+
8+
## Outputs
9+
10+
| Name | Description |
11+
|------|-------------|
12+
| revision\_id | The revision\_id of the workflow. |
13+
| workflow\_id | The id of the workflow. |
14+
15+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/simple_workflow/main.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module "service_account" {
18+
source = "terraform-google-modules/service-accounts/google"
19+
version = "~> 4.1.1"
20+
project_id = var.project_id
21+
prefix = "simple-workflow"
22+
names = ["simple"]
23+
project_roles = ["${var.project_id}=>roles/workflows.invoker"]
24+
}
25+
26+
module "standalone_workflow" {
27+
source = "../../modules/simple_workflow"
28+
29+
project_id = var.project_id
30+
workflow_name = "standalone-workflow"
31+
location = "us-central1"
32+
service_account_email = module.service_account.email
33+
workflow_source = <<-EOF
34+
# This is a sample workflow that simply reads wikipedia
35+
# Note that $$ is needed for Terraform
36+
37+
main:
38+
steps:
39+
- readWikipedia:
40+
call: http.get
41+
args:
42+
url: https://en.wikipedia.org/w/api.php
43+
query:
44+
action: opensearch
45+
search: GoogleCloudPlatform
46+
result: wikiResult
47+
- returnOutput:
48+
return: $${wikiResult.body[1]}
49+
EOF
50+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "workflow_id" {
18+
description = "The id of the workflow."
19+
value = module.standalone_workflow.workflow_id
20+
}
21+
22+
output "revision_id" {
23+
description = "The revision_id of the workflow."
24+
value = module.standalone_workflow.revision_id
25+
}

0 commit comments

Comments
 (0)