Trigger class

The Eventarc Trigger resource

To get more information about Trigger, see:

Example Usage

Eventarc Trigger With Cloud Run Destination

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const foo = new gcp.pubsub.Topic("foo", {name: "some-topic"});
const _default = new gcp.cloudrun.Service("default", {
    name: "some-service",
    location: "us-central1",
    template: {
        spec: {
            containers: [{
                image: "gcr.io/cloudrun/hello",
                ports: [{
                    containerPort: 8080,
                }],
            }],
            containerConcurrency: 50,
            timeoutSeconds: 100,
        },
    },
    traffics: [{
        percent: 100,
        latestRevision: true,
    }],
});
const primary = new gcp.eventarc.Trigger("primary", {
    name: "some-trigger",
    location: "us-central1",
    matchingCriterias: [{
        attribute: "type",
        value: "google.cloud.pubsub.topic.v1.messagePublished",
    }],
    destination: {
        cloudRunService: {
            service: _default.name,
            region: "us-central1",
        },
    },
    labels: {
        foo: "bar",
    },
    transport: {
        pubsub: {
            topic: foo.id,
        },
    },
    retryPolicy: {
        maxAttempts: 1,
    },
});
import pulumi
import pulumi_gcp as gcp

foo = gcp.pubsub.Topic("foo", name="some-topic")
default = gcp.cloudrun.Service("default",
    name="some-service",
    location="us-central1",
    template={
        "spec": {
            "containers": [{
                "image": "gcr.io/cloudrun/hello",
                "ports": [{
                    "container_port": 8080,
                }],
            }],
            "container_concurrency": 50,
            "timeout_seconds": 100,
        },
    },
    traffics=[{
        "percent": 100,
        "latest_revision": True,
    }])
primary = gcp.eventarc.Trigger("primary",
    name="some-trigger",
    location="us-central1",
    matching_criterias=[{
        "attribute": "type",
        "value": "google.cloud.pubsub.topic.v1.messagePublished",
    }],
    destination={
        "cloud_run_service": {
            "service": default.name,
            "region": "us-central1",
        },
    },
    labels={
        "foo": "bar",
    },
    transport={
        "pubsub": {
            "topic": foo.id,
        },
    },
    retry_policy={
        "max_attempts": 1,
    })
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() =>
{
    var foo = new Gcp.PubSub.Topic("foo", new()
    {
        Name = "some-topic",
    });

    var @default = new Gcp.CloudRun.Service("default", new()
    {
        Name = "some-service",
        Location = "us-central1",
        Template = new Gcp.CloudRun.Inputs.ServiceTemplateArgs
        {
            Spec = new Gcp.CloudRun.Inputs.ServiceTemplateSpecArgs
            {
                Containers = new[]
                {
                    new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerArgs
                    {
                        Image = "gcr.io/cloudrun/hello",
                        Ports = new[]
                        {
                            new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerPortArgs
                            {
                                ContainerPort = 8080,
                            },
                        },
                    },
                },
                ContainerConcurrency = 50,
                TimeoutSeconds = 100,
            },
        },
        Traffics = new[]
        {
            new Gcp.CloudRun.Inputs.ServiceTrafficArgs
            {
                Percent = 100,
                LatestRevision = true,
            },
        },
    });

    var primary = new Gcp.Eventarc.Trigger("primary", new()
    {
        Name = "some-trigger",
        Location = "us-central1",
        MatchingCriterias = new[]
        {
            new Gcp.Eventarc.Inputs.TriggerMatchingCriteriaArgs
            {
                Attribute = "type",
                Value = "google.cloud.pubsub.topic.v1.messagePublished",
            },
        },
        Destination = new Gcp.Eventarc.Inputs.TriggerDestinationArgs
        {
            CloudRunService = new Gcp.Eventarc.Inputs.TriggerDestinationCloudRunServiceArgs
            {
                Service = @default.Name,
                Region = "us-central1",
            },
        },
        Labels =
        {
            { "foo", "bar" },
        },
        Transport = new Gcp.Eventarc.Inputs.TriggerTransportArgs
        {
            Pubsub = new Gcp.Eventarc.Inputs.TriggerTransportPubsubArgs
            {
                Topic = foo.Id,
            },
        },
        RetryPolicy = new Gcp.Eventarc.Inputs.TriggerRetryPolicyArgs
        {
            MaxAttempts = 1,
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/cloudrun"
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/eventarc"
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/pubsub"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		foo, err := pubsub.NewTopic(ctx, "foo", &pubsub.TopicArgs{
			Name: pulumi.String("some-topic"),
		})
		if err != nil {
			return err
		}
		_default, err := cloudrun.NewService(ctx, "default", &cloudrun.ServiceArgs{
			Name:     pulumi.String("some-service"),
			Location: pulumi.String("us-central1"),
			Template: &cloudrun.ServiceTemplateArgs{
				Spec: &cloudrun.ServiceTemplateSpecArgs{
					Containers: cloudrun.ServiceTemplateSpecContainerArray{
						&cloudrun.ServiceTemplateSpecContainerArgs{
							Image: pulumi.String("gcr.io/cloudrun/hello"),
							Ports: cloudrun.ServiceTemplateSpecContainerPortArray{
								&cloudrun.ServiceTemplateSpecContainerPortArgs{
									ContainerPort: pulumi.Int(8080),
								},
							},
						},
					},
					ContainerConcurrency: pulumi.Int(50),
					TimeoutSeconds:       pulumi.Int(100),
				},
			},
			Traffics: cloudrun.ServiceTrafficArray{
				&cloudrun.ServiceTrafficArgs{
					Percent:        pulumi.Int(100),
					LatestRevision: pulumi.Bool(true),
				},
			},
		})
		if err != nil {
			return err
		}
		_, err = eventarc.NewTrigger(ctx, "primary", &eventarc.TriggerArgs{
			Name:     pulumi.String("some-trigger"),
			Location: pulumi.String("us-central1"),
			MatchingCriterias: eventarc.TriggerMatchingCriteriaArray{
				&eventarc.TriggerMatchingCriteriaArgs{
					Attribute: pulumi.String("type"),
					Value:     pulumi.String("google.cloud.pubsub.topic.v1.messagePublished"),
				},
			},
			Destination: &eventarc.TriggerDestinationArgs{
				CloudRunService: &eventarc.TriggerDestinationCloudRunServiceArgs{
					Service: _default.Name,
					Region:  pulumi.String("us-central1"),
				},
			},
			Labels: pulumi.StringMap{
				"foo": pulumi.String("bar"),
			},
			Transport: &eventarc.TriggerTransportArgs{
				Pubsub: &eventarc.TriggerTransportPubsubArgs{
					Topic: foo.ID().ToIDOutput().ToStringOutput(),
				},
			},
			RetryPolicy: &eventarc.TriggerRetryPolicyArgs{
				MaxAttempts: pulumi.Int(1),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    gcp = {
      source = "pulumi/gcp"
    }
  }
}

resource "gcp_eventarc_trigger" "primary" {
  name     = "some-trigger"
  location = "us-central1"
  matching_criterias {
    attribute = "type"
    value     = "google.cloud.pubsub.topic.v1.messagePublished"
  }
  destination = {
    cloud_run_service = {
      service = gcp_cloudrun_service.default.name
      region  = "us-central1"
    }
  }
  labels = {
    "foo" = "bar"
  }
  transport = {
    pubsub = {
      topic = gcp_pubsub_topic.foo.id
    }
  }
  retry_policy = {
    max_attempts = 1
  }
}
resource "gcp_pubsub_topic" "foo" {
  name = "some-topic"
}
resource "gcp_cloudrun_service" "default" {
  name     = "some-service"
  location = "us-central1"
  template = {
    spec = {
      containers = [{
        "image" = "gcr.io/cloudrun/hello"
        "ports" = [{
          "containerPort" = 8080
        }]
      }]
      container_concurrency = 50
      timeout_seconds       = 100
    }
  }
  traffics {
    percent         = 100
    latest_revision = true
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.pubsub.Topic;
import com.pulumi.gcp.pubsub.TopicArgs;
import com.pulumi.gcp.cloudrun.Service;
import com.pulumi.gcp.cloudrun.ServiceArgs;
import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateArgs;
import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateSpecArgs;
import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateSpecContainerArgs;
import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateSpecContainerPortArgs;
import com.pulumi.gcp.cloudrun.inputs.ServiceTrafficArgs;
import com.pulumi.gcp.eventarc.Trigger;
import com.pulumi.gcp.eventarc.TriggerArgs;
import com.pulumi.gcp.eventarc.inputs.TriggerMatchingCriteriaArgs;
import com.pulumi.gcp.eventarc.inputs.TriggerDestinationArgs;
import com.pulumi.gcp.eventarc.inputs.TriggerDestinationCloudRunServiceArgs;
import com.pulumi.gcp.eventarc.inputs.TriggerTransportArgs;
import com.pulumi.gcp.eventarc.inputs.TriggerTransportPubsubArgs;
import com.pulumi.gcp.eventarc.inputs.TriggerRetryPolicyArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var foo = new Topic("foo", TopicArgs.builder()
            .name("some-topic")
            .build());

        var default_ = new Service("default", ServiceArgs.builder()
            .name("some-service")
            .location("us-central1")
            .template(ServiceTemplateArgs.builder()
                .spec(ServiceTemplateSpecArgs.builder()
                    .containers(ServiceTemplateSpecContainerArgs.builder()
                        .image("gcr.io/cloudrun/hello")
                        .ports(ServiceTemplateSpecContainerPortArgs.builder()
                            .containerPort(8080)
                            .build())
                        .build())
                    .containerConcurrency(50)
                    .timeoutSeconds(100)
                    .build())
                .build())
            .traffics(ServiceTrafficArgs.builder()
                .percent(100)
                .latestRevision(true)
                .build())
            .build());

        var primary = new Trigger("primary", TriggerArgs.builder()
            .name("some-trigger")
            .location("us-central1")
            .matchingCriterias(TriggerMatchingCriteriaArgs.builder()
                .attribute("type")
                .value("google.cloud.pubsub.topic.v1.messagePublished")
                .build())
            .destination(TriggerDestinationArgs.builder()
                .cloudRunService(TriggerDestinationCloudRunServiceArgs.builder()
                    .service(default_.name())
                    .region("us-central1")
                    .build())
                .build())
            .labels(Map.of("foo", "bar"))
            .transport(TriggerTransportArgs.builder()
                .pubsub(TriggerTransportPubsubArgs.builder()
                    .topic(foo.id())
                    .build())
                .build())
            .retryPolicy(TriggerRetryPolicyArgs.builder()
                .maxAttempts(1)
                .build())
            .build());

    }
}
resources:
  primary:
    type: gcp:eventarc:Trigger
    properties:
      name: some-trigger
      location: us-central1
      matchingCriterias:
        - attribute: type
          value: google.cloud.pubsub.topic.v1.messagePublished
      destination:
        cloudRunService:
          service: ${default.name}
          region: us-central1
      labels:
        foo: bar
      transport:
        pubsub:
          topic: ${foo.id}
      retryPolicy:
        maxAttempts: 1
  foo:
    type: gcp:pubsub:Topic
    properties:
      name: some-topic
  default:
    type: gcp:cloudrun:Service
    properties:
      name: some-service
      location: us-central1
      template:
        spec:
          containers:
            - image: gcr.io/cloudrun/hello
              ports:
                - containerPort: 8080
          containerConcurrency: 50
          timeoutSeconds: 100
      traffics:
        - percent: 100
          latestRevision: true

Import

Trigger can be imported using any of these accepted formats:

  • projects/{{project}}/locations/{{location}}/triggers/{{name}}
  • {{project}}/{{location}}/{{name}}
  • {{location}}/{{name}}

When using the pulumi import command, Trigger can be imported using one of the formats above. For example:

$ pulumi import gcp:eventarc/trigger:Trigger default projects/{{project}}/locations/{{location}}/triggers/{{name}}
$ pulumi import gcp:eventarc/trigger:Trigger default {{project}}/{{location}}/{{name}}
$ pulumi import gcp:eventarc/trigger:Trigger default {{location}}/{{name}}

Constructors

Trigger(String name, {TriggerArgs? args, CustomResourceOptions? options})
Creates a new Trigger. name The Pulumi resource name. args Arguments used to configure this Trigger. The set of arguments for Trigger. options Resource options controlling this resource's behavior.
Trigger.reference(String urn)
Creates a typed reference to an existing Trigger resource.

Properties

channel ↔ Output<String?>
Optional. The name of the channel associated with the trigger in projects/{project}/locations/{location}/channels/{channel} format. You must provide a channel to receive events from Eventarc SaaS partners.
latefinal
childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
conditions ↔ Output<Map<String, String>>
Output only. The reason(s) why a trigger is in FAILED state.
latefinal
createTime ↔ Output<String>
Output only. The creation time.
latefinal
deletionPolicy ↔ Output<String>
Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. When a 'terraform destroy' or 'pulumi up' would delete the resource, the command will fail if this field is set to "PREVENT" in Terraform state. When set to "ABANDON", the command will remove the resource from Terraform management without updating or deleting the resource in the API. When set to "DELETE", deleting the resource is allowed.
latefinal
destination ↔ Output<TriggerDestination>
Required. Destination specifies where the events should be sent to. Structure is documented below.
latefinal
effectiveLabels ↔ Output<Map<String, String>>
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Pulumi, other clients and services.
latefinal
etag ↔ Output<String>
Output only. This checksum is computed by the server based on the value of other fields, and may be sent only on create requests to ensure the client has an up-to-date value before proceeding.
latefinal
eventDataContentType ↔ Output<String>
Optional. EventDataContentType specifies the type of payload in MIME format that is expected from the CloudEvent data field. This is set to application/json if the value is not defined.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
labels ↔ Output<Map<String, String>?>
Optional. User labels attached to the triggers that can be used to group resources. Note: This field is non-authoritative, and will only manage the labels present in your configuration. Please refer to the field effectiveLabels for all of the labels present on the resource.
latefinal
location ↔ Output<String>
The location for the resource
latefinal
matchingCriterias ↔ Output<List<TriggerMatchingCriteria>>
Required. null The list of filters that applies to event attributes. Only events that match all the provided filters will be sent to the destination. Structure is documented below.
latefinal
name ↔ Output<String>
Required. The resource name of the trigger. Must be unique within the location on the project.
latefinal
project ↔ Output<String>
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
latefinal
pulumiLabels ↔ Output<Map<String, String>>
The combination of labels configured directly on the resource and default labels configured on the provider.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
retryPolicy ↔ Output<TriggerRetryPolicy?>
The retry policy configuration for the Trigger. Can only be set with Cloud Run destinations. Structure is documented below.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serviceAccount ↔ Output<String?>
Optional. The IAM service account email associated with the trigger. The service account represents the identity of the trigger. The principal who calls this API must have iam.serviceAccounts.actAs permission in the service account. See https://cloud.google.com/iam/docs/understanding-service-accounts#sa_common for more information. For Cloud Run destinations, this service account is used to generate identity tokens when invoking the service. See https://cloud.google.com/run/docs/triggering/pubsub-push#create-service-account for information on how to invoke authenticated Cloud Run services. In order to create Audit Log triggers, the service account should also have roles/eventarc.eventReceiver IAM role.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
transport ↔ Output<TriggerTransport>
Optional. In order to deliver messages, Eventarc may use other GCP products as transport intermediary. This field contains a reference to that transport intermediary. This information can be used for debugging purposes. Structure is documented below.
latefinal
uid ↔ Output<String>
Output only. Server assigned unique identifier for the trigger. The value is a UUID4 string and guaranteed to remain unchanged until the resource is deleted.
latefinal
updateTime ↔ Output<String>
Output only. The last-modified time.
latefinal
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {TriggerState? state, CustomResourceOptions? options}) → Trigger
Gets an existing Trigger resource's state with the given name and id.