-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Adding Eventarc-Workflows example for cgc docs #6279
Changes from 1 commit
73a19d6
6da5562
d6f682b
cf7aedd
2908a53
b452d0c
b944440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,22 @@ overrides: !ruby/object:Overrides::ResourceOverrides | |
primary_resource_id: "instance_virtual_display" | ||
vars: | ||
instance_virtual_display: "instance-virtual-display" | ||
|
||
# Eventarc | ||
### Eventarc Workflows quickstart | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: "eventarc-workflows" | ||
primary_resource_type: "google_eventarc_trigger" | ||
primary_resource_id: "trigger_pubsub_tf" | ||
vars: | ||
pubsub_workflow_tf: "pubsub-workflow-tf" | ||
trigger_pubsub_workflow_tf: "trigger-pubsub-workflow-tf" | ||
min_version: beta | ||
# ignore_read_extra: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: these commented out lines can be removed i believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thank you! |
||
# - "port_range" | ||
# - "target" | ||
# - "ip_address" | ||
|
||
# SQL | ||
### When including separate samples for each DB type, add `skip_test: true` | ||
### for Postgres and MySQL, but not for SQL Server | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# [START eventarc_terraform_enableapis] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this file can be removed in place of the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thank you Megan. |
||
# Used to retrieve project_number later | ||
data "google_project" "project" { | ||
provider = google-beta | ||
} | ||
|
||
# Enable Eventarc API | ||
resource "google_project_service" "eventarc" { | ||
provider = google-beta | ||
service = "eventarc.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
|
||
# Enable Pub/Sub API | ||
resource "google_project_service" "pubsub" { | ||
provider = google-beta | ||
service = "pubsub.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
|
||
# Enable Workflows API | ||
resource "google_project_service" "workflows" { | ||
provider = google-beta | ||
service = "workflows.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
|
||
# [END eventarc_terraform_enableapis] | ||
|
||
# [START eventarc_workflows_create_serviceaccount] | ||
|
||
# Create a service account for Eventarc trigger and Workflows | ||
resource "google_service_account" "eventarc_workflows_service_account" { | ||
provider = google-beta | ||
account_id = "eventarc-workflows-sa" | ||
display_name = "Eventarc Workflows Service Account" | ||
} | ||
|
||
# Grant the logWriter role to the service account | ||
resource "google_project_iam_binding" "project_binding_eventarc" { | ||
provider = google-beta | ||
project = data.google_project.project.id | ||
role = "roles/logging.logWriter" | ||
|
||
members = [ | ||
|
||
"serviceAccount:${google_service_account.eventarc_workflows_service_account.email}" | ||
] | ||
|
||
depends_on = [google_service_account.eventarc_workflows_service_account] | ||
} | ||
|
||
# Grant the workflows.invoker role to the service account | ||
resource "google_project_iam_binding" "project_binding_workflows" { | ||
provider = google-beta | ||
project = data.google_project.project.id | ||
role = "roles/workflows.invoker" | ||
|
||
members = [ | ||
|
||
"serviceAccount:${google_service_account.eventarc_workflows_service_account.email}" | ||
] | ||
|
||
depends_on = [google_service_account.eventarc_workflows_service_account] | ||
} | ||
|
||
# [END eventarc_workflows_create_serviceaccount] | ||
|
||
# [START eventarc_workflows_deploy] | ||
# Define and deploy a workflow | ||
resource "google_workflows_workflow" "workflows_example" { | ||
name = "<%= ctx[:vars]['pubsub_workflow_tf'] %>" | ||
provider = google-beta | ||
region = "us-central1" | ||
description = "A sample workflow" | ||
service_account = google_service_account.eventarc_workflows_service_account.id | ||
# Imported main workflow YAML file | ||
source_contents = templatefile("${path.module}/workflow.yaml",{}) | ||
|
||
depends_on = [google_project_service.workflows, | ||
google_service_account.eventarc_workflows_service_account] | ||
} | ||
|
||
# [END eventarc_workflows_deploy] | ||
|
||
# [START eventarc_create_pubsub_trigger] | ||
# Create an Eventarc trigger routing Pub/Sub events to Workflows | ||
resource "google_eventarc_trigger" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['trigger_pubsub_workflow_tf'] %>" | ||
provider = google-beta | ||
location = "us-central1" | ||
matching_criteria { | ||
attribute = "type" | ||
value = "google.cloud.pubsub.topic.v1.messagePublished" | ||
} | ||
destination { | ||
workflow = google_workflows_workflow.workflows_example.id | ||
} | ||
|
||
|
||
service_account = google_service_account.eventarc_workflows_service_account.id | ||
|
||
depends_on = [google_project_service.pubsub, google_project_service.eventarc, | ||
google_service_account.eventarc_workflows_service_account] | ||
} | ||
|
||
# [END eventarc_create_pubsub_trigger] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will want to use an underscore instead of the dash here, and we'll need to update the associated filename as well. Thanks!