This is a sample that shows how to use Terraform's eventarc_trigger resource to create Eventarc triggers.
More specifically, this sample:
- Enables Cloud Run and Eventarc APIs.
- Deploys a private Cloud Run service.
- Creates an Eventarc Pub/Sub trigger for that service.
- Creates an Eventarc AuditLog trigger for Cloud Storage events for that service.
Run the following commands inside terraform folder.
-
Initialize terraform:
terraform init
-
See the planned changes:
terraform plan -var="project_id=YOUR-PROJECT-ID" -var="region=YOUR-GCP-REGION"
-
Create resources:
terraform apply -var="project_id=YOUR-PROJECT-ID" -var="region=YOUR-GCP-REGION"
Note: The AuditLog trigger might fail on the first try, if you just enabled Eventarc. In that case,
terraform applyagain. -
Once resources are created, you can see the list of triggers:
gcloud eventarc triggers list --location YOUR-GCP-REGION
-
Generate an event and check the logs to confirm that the Pub/Sub Eventarc trigger is working as expected:
TOPIC_ID=$(gcloud eventarc triggers describe trigger-pubsub-tf --location=us-central1 --format='value(transport.pubsub.topic)') gcloud pubsub topics publish $TOPIC_ID --message "Hello there"
-
Cleanup:
terraform destroy -var="project_id=YOUR-PROJECT-ID" -var="region=YOUR-GCP-REGION"