Topic

class Topic : KotlinCustomResource

A named resource to which messages are sent by publishers. To get more information about Topic, see:

Note: You can retrieve the email of the Google Managed Pub/Sub Service Account used for forwarding by using the gcp.projects.ServiceIdentity resource.

Example Usage

Pubsub Topic Basic

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 java.util.List;
import java.util.ArrayList;
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 example = new Topic("example", TopicArgs.builder()
.labels(Map.of("foo", "bar"))
.messageRetentionDuration("86600s")
.build());
}
}

Pubsub Topic Cmek

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.kms.KeyRing;
import com.pulumi.gcp.kms.KeyRingArgs;
import com.pulumi.gcp.kms.CryptoKey;
import com.pulumi.gcp.kms.CryptoKeyArgs;
import com.pulumi.gcp.pubsub.Topic;
import com.pulumi.gcp.pubsub.TopicArgs;
import java.util.List;
import java.util.ArrayList;
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 keyRing = new KeyRing("keyRing", KeyRingArgs.builder()
.location("global")
.build());
var cryptoKey = new CryptoKey("cryptoKey", CryptoKeyArgs.builder()
.keyRing(keyRing.id())
.build());
var example = new Topic("example", TopicArgs.builder()
.kmsKeyName(cryptoKey.id())
.build());
}
}

Pubsub Topic Geo Restricted

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.pubsub.inputs.TopicMessageStoragePolicyArgs;
import java.util.List;
import java.util.ArrayList;
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 example = new Topic("example", TopicArgs.builder()
.messageStoragePolicy(TopicMessageStoragePolicyArgs.builder()
.allowedPersistenceRegions("europe-west3")
.build())
.build());
}
}

Pubsub Topic Schema Settings

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.pubsub.Schema;
import com.pulumi.gcp.pubsub.SchemaArgs;
import com.pulumi.gcp.pubsub.Topic;
import com.pulumi.gcp.pubsub.TopicArgs;
import com.pulumi.gcp.pubsub.inputs.TopicSchemaSettingsArgs;
import com.pulumi.resources.CustomResourceOptions;
import java.util.List;
import java.util.ArrayList;
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 exampleSchema = new Schema("exampleSchema", SchemaArgs.builder()
.type("AVRO")
.definition("""
{
"type" : "record",
"name" : "Avro",
"fields" : [
{
"name" : "StringField",
"type" : "string"
},
{
"name" : "IntField",
"type" : "int"
}
]
}
""")
.build());
var exampleTopic = new Topic("exampleTopic", TopicArgs.builder()
.schemaSettings(TopicSchemaSettingsArgs.builder()
.schema("projects/my-project-name/schemas/example")
.encoding("JSON")
.build())
.build(), CustomResourceOptions.builder()
.dependsOn(exampleSchema)
.build());
}
}

Import

Topic can be imported using any of these accepted formats

$ pulumi import gcp:pubsub/topic:Topic default projects/{{project}}/topics/{{name}}
$ pulumi import gcp:pubsub/topic:Topic default {{project}}/{{name}}
$ pulumi import gcp:pubsub/topic:Topic default {{name}}

Properties

Link copied to clipboard
val id: Output<String>
Link copied to clipboard
val kmsKeyName: Output<String>?

The resource name of the Cloud KMS CryptoKey to be used to protect access to messages published on this topic. Your project's PubSub service account (service-{{PROJECT_NUMBER}}@gcp-sa-pubsub.iam.gserviceaccount.com) must have roles/cloudkms.cryptoKeyEncrypterDecrypter to use this feature. The expected format is projects/*/locations/*/keyRings/*/cryptoKeys/* ////

Link copied to clipboard
val labels: Output<Map<String, String>>?

A set of key/value label pairs to assign to this Topic.

Link copied to clipboard

Indicates the minimum duration to retain a message after it is published to the topic. If this field is set, messages published to the topic in the last messageRetentionDuration are always available to subscribers. For instance, it allows any attached subscription to seek to a timestamp that is up to messageRetentionDuration in the past. If this field is not set, message retention is controlled by settings on individual subscriptions. Cannot be more than 31 days or less than 10 minutes.

Link copied to clipboard

Policy constraining the set of Google Cloud Platform regions where messages published to the topic may be stored. If not present, then no constraints are in effect. Structure is documented below.

Link copied to clipboard
val name: Output<String>

Name of the topic.

Link copied to clipboard
val project: Output<String>

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

Link copied to clipboard
val pulumiChildResources: Set<KotlinResource>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Settings for validating messages published against a schema. Structure is documented below.

Link copied to clipboard
val urn: Output<String>