From 9ee5c19ca83c1a8c81b2300874f275959d6501e1 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Mon, 10 Feb 2025 18:10:16 +0000 Subject: [PATCH] Migrate google_eventarc_trigger resource from DCL to MMv1 (#12832) [upstream:80eaa7b5dd063e9975f9b70af355367990f83420] Signed-off-by: Modular Magician --- .../backing_file.tf | 15 ++++ .../main.tf | 49 ++++++++++++ .../motd | 7 ++ .../tutorial.md | 79 +++++++++++++++++++ .../backing_file.tf | 15 ++++ .../main.tf | 58 ++++++++++++++ .../motd | 7 ++ .../tutorial.md | 79 +++++++++++++++++++ 8 files changed, 309 insertions(+) create mode 100644 eventarc_trigger_with_cloud_run_destination/backing_file.tf create mode 100644 eventarc_trigger_with_cloud_run_destination/main.tf create mode 100644 eventarc_trigger_with_cloud_run_destination/motd create mode 100644 eventarc_trigger_with_cloud_run_destination/tutorial.md create mode 100644 eventarc_trigger_with_path_pattern_filter/backing_file.tf create mode 100644 eventarc_trigger_with_path_pattern_filter/main.tf create mode 100644 eventarc_trigger_with_path_pattern_filter/motd create mode 100644 eventarc_trigger_with_path_pattern_filter/tutorial.md diff --git a/eventarc_trigger_with_cloud_run_destination/backing_file.tf b/eventarc_trigger_with_cloud_run_destination/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/eventarc_trigger_with_cloud_run_destination/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/eventarc_trigger_with_cloud_run_destination/main.tf b/eventarc_trigger_with_cloud_run_destination/main.tf new file mode 100644 index 00000000..af92aa31 --- /dev/null +++ b/eventarc_trigger_with_cloud_run_destination/main.tf @@ -0,0 +1,49 @@ +resource "google_eventarc_trigger" "primary" { + name = "some-trigger-${local.name_suffix}" + location = "us-central1" + matching_criteria { + attribute = "type" + value = "google.cloud.pubsub.topic.v1.messagePublished" + } + destination { + cloud_run_service { + service = google_cloud_run_service.default.name + region = "us-central1" + } + } + labels = { + foo = "bar" + } + transport { + pubsub { + topic = google_pubsub_topic.foo.id + } + } +} + +resource "google_pubsub_topic" "foo" { + name = "some-topic-${local.name_suffix}" +} + +resource "google_cloud_run_service" "default" { + name = "some-service-${local.name_suffix}" + location = "us-central1" + + template { + spec { + containers { + image = "gcr.io/cloudrun/hello" + ports { + container_port = 8080 + } + } + container_concurrency = 50 + timeout_seconds = 100 + } + } + + traffic { + percent = 100 + latest_revision = true + } +} diff --git a/eventarc_trigger_with_cloud_run_destination/motd b/eventarc_trigger_with_cloud_run_destination/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/eventarc_trigger_with_cloud_run_destination/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/eventarc_trigger_with_cloud_run_destination/tutorial.md b/eventarc_trigger_with_cloud_run_destination/tutorial.md new file mode 100644 index 00000000..cf1edab3 --- /dev/null +++ b/eventarc_trigger_with_cloud_run_destination/tutorial.md @@ -0,0 +1,79 @@ +# Eventarc Trigger With Cloud Run Destination - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/eventarc_trigger_with_path_pattern_filter/backing_file.tf b/eventarc_trigger_with_path_pattern_filter/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/eventarc_trigger_with_path_pattern_filter/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/eventarc_trigger_with_path_pattern_filter/main.tf b/eventarc_trigger_with_path_pattern_filter/main.tf new file mode 100644 index 00000000..9189b7b0 --- /dev/null +++ b/eventarc_trigger_with_path_pattern_filter/main.tf @@ -0,0 +1,58 @@ +resource "google_eventarc_trigger" "primary" { + name = "some-trigger-${local.name_suffix}" + location = "us-central1" + matching_criteria { + attribute = "type" + value = "google.cloud.eventarc.trigger.v1.created" + } + matching_criteria { + attribute = "trigger" + operator = "match-path-pattern" + value = "trigger-with-wildcard-*" + } + destination { + cloud_run_service { + service = google_cloud_run_service.default.name + region = "us-central1" + } + } + labels = { + foo = "bar" + } + event_data_content_type = "application/protobuf" + service_account = google_service_account.trigger_service_account.email + depends_on = [google_project_iam_member.event_receiver] +} + +resource "google_service_account" "trigger_service_account" { + account_id = "trigger-sa-${local.name_suffix}" +} + +resource "google_project_iam_member" "event_receiver" { + project = google_service_account.trigger_service_account.project + role = "roles/eventarc.eventReceiver" + member = "serviceAccount:${google_service_account.trigger_service_account.email}" +} + +resource "google_cloud_run_service" "default" { + name = "some-service-${local.name_suffix}" + location = "us-central1" + + template { + spec { + containers { + image = "gcr.io/cloudrun/hello" + ports { + container_port = 8080 + } + } + container_concurrency = 50 + timeout_seconds = 100 + } + } + + traffic { + percent = 100 + latest_revision = true + } +} diff --git a/eventarc_trigger_with_path_pattern_filter/motd b/eventarc_trigger_with_path_pattern_filter/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/eventarc_trigger_with_path_pattern_filter/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/eventarc_trigger_with_path_pattern_filter/tutorial.md b/eventarc_trigger_with_path_pattern_filter/tutorial.md new file mode 100644 index 00000000..d3d69bdd --- /dev/null +++ b/eventarc_trigger_with_path_pattern_filter/tutorial.md @@ -0,0 +1,79 @@ +# Eventarc Trigger With Path Pattern Filter - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +```