Skip to content

Latest commit

 

History

History

basic

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Basic Terraform

This is a sample that shows how to use Terraform's eventarc_trigger resource to create Eventarc triggers.

More specifically, this sample:

  1. Enables Cloud Run and Eventarc APIs.
  2. Deploys a private Cloud Run service.
  3. Creates an Eventarc Pub/Sub trigger for that service.
  4. Creates an Eventarc AuditLog trigger for Cloud Storage events for that service.

Terraform

Run the following commands inside terraform folder.

  1. Initialize terraform:

    terraform init
  2. See the planned changes:

    terraform plan -var="project_id=YOUR-PROJECT-ID" -var="region=YOUR-GCP-REGION"
  3. 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 apply again.

  4. Once resources are created, you can see the list of triggers:

    gcloud eventarc triggers list --location YOUR-GCP-REGION
  5. 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"
  6. Cleanup:

    terraform destroy -var="project_id=YOUR-PROJECT-ID" -var="region=YOUR-GCP-REGION"