All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pulumi.gcp.storage.kotlin.NotificationArgs.kt Maven / Gradle / Ivy

Go to download

Build cloud applications and infrastructure by combining the safety and reliability of infrastructure as code with the power of the Kotlin programming language.

There is a newer version: 8.10.0.0
Show newest version
@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.gcp.storage.kotlin

import com.pulumi.core.Output
import com.pulumi.core.Output.of
import com.pulumi.gcp.storage.NotificationArgs.builder
import com.pulumi.kotlin.ConvertibleToJava
import com.pulumi.kotlin.PulumiTagMarker
import kotlin.Pair
import kotlin.String
import kotlin.Suppress
import kotlin.collections.List
import kotlin.collections.Map
import kotlin.jvm.JvmName

/**
 * Creates a new notification configuration on a specified bucket, establishing a flow of event notifications from GCS to a Cloud Pub/Sub topic.
 *  For more information see
 * [the official documentation](https://cloud.google.com/storage/docs/pubsub-notifications)
 * and
 * [API](https://cloud.google.com/storage/docs/json_api/v1/notifications).
 * In order to enable notifications, a special Google Cloud Storage service account unique to the project
 * must exist and have the IAM permission "projects.topics.publish" for a Cloud Pub/Sub topic in the project.
 * This service account is not created automatically when a project is created.
 * To ensure the service account exists and obtain its email address for use in granting the correct IAM permission, use the
 * [`gcp.storage.getProjectServiceAccount`](https://www.terraform.io/docs/providers/google/d/storage_project_service_account.html)
 * datasource's `email_address` value, and see below for an example of enabling notifications by granting the correct IAM permission.
 * See [the notifications documentation](https://cloud.google.com/storage/docs/gsutil/commands/notification) for more details.
 * >**NOTE**: This resource can affect your storage IAM policy. If you are using this in the same config as your storage IAM policy resources, consider
 * making this resource dependent on those IAM resources via `depends_on`. This will safeguard against errors due to IAM race conditions.
 * ## Example Usage
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * // End enabling notifications
 * const bucket = new gcp.storage.Bucket("bucket", {
 *     name: "default_bucket",
 *     location: "US",
 * });
 * const topic = new gcp.pubsub.Topic("topic", {name: "default_topic"});
 * const notification = new gcp.storage.Notification("notification", {
 *     bucket: bucket.name,
 *     payloadFormat: "JSON_API_V1",
 *     topic: topic.id,
 *     eventTypes: [
 *         "OBJECT_FINALIZE",
 *         "OBJECT_METADATA_UPDATE",
 *     ],
 *     customAttributes: {
 *         "new-attribute": "new-attribute-value",
 *     },
 * });
 * // Enable notifications by giving the correct IAM permission to the unique service account.
 * const gcsAccount = gcp.storage.getProjectServiceAccount({});
 * const binding = new gcp.pubsub.TopicIAMBinding("binding", {
 *     topic: topic.id,
 *     role: "roles/pubsub.publisher",
 *     members: [gcsAccount.then(gcsAccount => `serviceAccount:${gcsAccount.emailAddress}`)],
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * # End enabling notifications
 * bucket = gcp.storage.Bucket("bucket",
 *     name="default_bucket",
 *     location="US")
 * topic = gcp.pubsub.Topic("topic", name="default_topic")
 * notification = gcp.storage.Notification("notification",
 *     bucket=bucket.name,
 *     payload_format="JSON_API_V1",
 *     topic=topic.id,
 *     event_types=[
 *         "OBJECT_FINALIZE",
 *         "OBJECT_METADATA_UPDATE",
 *     ],
 *     custom_attributes={
 *         "new-attribute": "new-attribute-value",
 *     })
 * # Enable notifications by giving the correct IAM permission to the unique service account.
 * gcs_account = gcp.storage.get_project_service_account()
 * binding = gcp.pubsub.TopicIAMBinding("binding",
 *     topic=topic.id,
 *     role="roles/pubsub.publisher",
 *     members=[f"serviceAccount:{gcs_account.email_address}"])
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     // End enabling notifications
 *     var bucket = new Gcp.Storage.Bucket("bucket", new()
 *     {
 *         Name = "default_bucket",
 *         Location = "US",
 *     });
 *     var topic = new Gcp.PubSub.Topic("topic", new()
 *     {
 *         Name = "default_topic",
 *     });
 *     var notification = new Gcp.Storage.Notification("notification", new()
 *     {
 *         Bucket = bucket.Name,
 *         PayloadFormat = "JSON_API_V1",
 *         Topic = topic.Id,
 *         EventTypes = new[]
 *         {
 *             "OBJECT_FINALIZE",
 *             "OBJECT_METADATA_UPDATE",
 *         },
 *         CustomAttributes =
 *         {
 *             { "new-attribute", "new-attribute-value" },
 *         },
 *     });
 *     // Enable notifications by giving the correct IAM permission to the unique service account.
 *     var gcsAccount = Gcp.Storage.GetProjectServiceAccount.Invoke();
 *     var binding = new Gcp.PubSub.TopicIAMBinding("binding", new()
 *     {
 *         Topic = topic.Id,
 *         Role = "roles/pubsub.publisher",
 *         Members = new[]
 *         {
 *             $"serviceAccount:{gcsAccount.Apply(getProjectServiceAccountResult => getProjectServiceAccountResult.EmailAddress)}",
 *         },
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"fmt"
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/pubsub"
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/storage"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		// End enabling notifications
 * 		bucket, err := storage.NewBucket(ctx, "bucket", &storage.BucketArgs{
 * 			Name:     pulumi.String("default_bucket"),
 * 			Location: pulumi.String("US"),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		topic, err := pubsub.NewTopic(ctx, "topic", &pubsub.TopicArgs{
 * 			Name: pulumi.String("default_topic"),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = storage.NewNotification(ctx, "notification", &storage.NotificationArgs{
 * 			Bucket:        bucket.Name,
 * 			PayloadFormat: pulumi.String("JSON_API_V1"),
 * 			Topic:         topic.ID(),
 * 			EventTypes: pulumi.StringArray{
 * 				pulumi.String("OBJECT_FINALIZE"),
 * 				pulumi.String("OBJECT_METADATA_UPDATE"),
 * 			},
 * 			CustomAttributes: pulumi.StringMap{
 * 				"new-attribute": pulumi.String("new-attribute-value"),
 * 			},
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		// Enable notifications by giving the correct IAM permission to the unique service account.
 * 		gcsAccount, err := storage.GetProjectServiceAccount(ctx, nil, nil)
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = pubsub.NewTopicIAMBinding(ctx, "binding", &pubsub.TopicIAMBindingArgs{
 * 			Topic: topic.ID(),
 * 			Role:  pulumi.String("roles/pubsub.publisher"),
 * 			Members: pulumi.StringArray{
 * 				pulumi.String(fmt.Sprintf("serviceAccount:%v", gcsAccount.EmailAddress)),
 * 			},
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		return nil
 * 	})
 * }
 * ```
 * ```java
 * package generated_program;
 * import com.pulumi.Context;
 * import com.pulumi.Pulumi;
 * import com.pulumi.core.Output;
 * import com.pulumi.gcp.storage.Bucket;
 * import com.pulumi.gcp.storage.BucketArgs;
 * import com.pulumi.gcp.pubsub.Topic;
 * import com.pulumi.gcp.pubsub.TopicArgs;
 * import com.pulumi.gcp.storage.Notification;
 * import com.pulumi.gcp.storage.NotificationArgs;
 * import com.pulumi.gcp.storage.StorageFunctions;
 * import com.pulumi.gcp.storage.inputs.GetProjectServiceAccountArgs;
 * import com.pulumi.gcp.pubsub.TopicIAMBinding;
 * import com.pulumi.gcp.pubsub.TopicIAMBindingArgs;
 * 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) {
 *         // End enabling notifications
 *         var bucket = new Bucket("bucket", BucketArgs.builder()
 *             .name("default_bucket")
 *             .location("US")
 *             .build());
 *         var topic = new Topic("topic", TopicArgs.builder()
 *             .name("default_topic")
 *             .build());
 *         var notification = new Notification("notification", NotificationArgs.builder()
 *             .bucket(bucket.name())
 *             .payloadFormat("JSON_API_V1")
 *             .topic(topic.id())
 *             .eventTypes(
 *                 "OBJECT_FINALIZE",
 *                 "OBJECT_METADATA_UPDATE")
 *             .customAttributes(Map.of("new-attribute", "new-attribute-value"))
 *             .build());
 *         // Enable notifications by giving the correct IAM permission to the unique service account.
 *         final var gcsAccount = StorageFunctions.getProjectServiceAccount();
 *         var binding = new TopicIAMBinding("binding", TopicIAMBindingArgs.builder()
 *             .topic(topic.id())
 *             .role("roles/pubsub.publisher")
 *             .members(String.format("serviceAccount:%s", gcsAccount.applyValue(getProjectServiceAccountResult -> getProjectServiceAccountResult.emailAddress())))
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   notification:
 *     type: gcp:storage:Notification
 *     properties:
 *       bucket: ${bucket.name}
 *       payloadFormat: JSON_API_V1
 *       topic: ${topic.id}
 *       eventTypes:
 *         - OBJECT_FINALIZE
 *         - OBJECT_METADATA_UPDATE
 *       customAttributes:
 *         new-attribute: new-attribute-value
 *   binding:
 *     type: gcp:pubsub:TopicIAMBinding
 *     properties:
 *       topic: ${topic.id}
 *       role: roles/pubsub.publisher
 *       members:
 *         - serviceAccount:${gcsAccount.emailAddress}
 *   # End enabling notifications
 *   bucket:
 *     type: gcp:storage:Bucket
 *     properties:
 *       name: default_bucket
 *       location: US
 *   topic:
 *     type: gcp:pubsub:Topic
 *     properties:
 *       name: default_topic
 * variables:
 *   # Enable notifications by giving the correct IAM permission to the unique service account.
 *   gcsAccount:
 *     fn::invoke:
 *       Function: gcp:storage:getProjectServiceAccount
 *       Arguments: {}
 * ```
 * 
 * ## Import
 * Storage notifications can be imported using any of these accepted formats:
 * * `{{bucket_name}}/notificationConfigs/{{id}}`
 * When using the `pulumi import` command, Storage notifications can be imported using one of the formats above. For example:
 * ```sh
 * $ pulumi import gcp:storage/notification:Notification default {{bucket_name}}/notificationConfigs/{{id}}
 * ```
 * @property bucket The name of the bucket.
 * @property customAttributes A set of key/value attribute pairs to attach to each Cloud PubSub message published for this notification subscription
 * @property eventTypes List of event type filters for this notification config. If not specified, Cloud Storage will send notifications for all event types. The valid types are: `"OBJECT_FINALIZE"`, `"OBJECT_METADATA_UPDATE"`, `"OBJECT_DELETE"`, `"OBJECT_ARCHIVE"`
 * @property objectNamePrefix Specifies a prefix path filter for this notification config. Cloud Storage will only send notifications for objects in this bucket whose names begin with the specified prefix.
 * @property payloadFormat The desired content of the Payload. One of `"JSON_API_V1"` or `"NONE"`.
 * @property topic The Cloud PubSub topic to which this subscription publishes. Expects either the
 * topic name, assumed to belong to the default GCP provider project, or the project-level name,
 * i.e. `projects/my-gcp-project/topics/my-topic` or `my-topic`. If the project is not set in the provider,
 * you will need to use the project-level name.
 * - - -
 */
public data class NotificationArgs(
    public val bucket: Output? = null,
    public val customAttributes: Output>? = null,
    public val eventTypes: Output>? = null,
    public val objectNamePrefix: Output? = null,
    public val payloadFormat: Output? = null,
    public val topic: Output? = null,
) : ConvertibleToJava {
    override fun toJava(): com.pulumi.gcp.storage.NotificationArgs =
        com.pulumi.gcp.storage.NotificationArgs.builder()
            .bucket(bucket?.applyValue({ args0 -> args0 }))
            .customAttributes(
                customAttributes?.applyValue({ args0 ->
                    args0.map({ args0 ->
                        args0.key.to(args0.value)
                    }).toMap()
                }),
            )
            .eventTypes(eventTypes?.applyValue({ args0 -> args0.map({ args0 -> args0 }) }))
            .objectNamePrefix(objectNamePrefix?.applyValue({ args0 -> args0 }))
            .payloadFormat(payloadFormat?.applyValue({ args0 -> args0 }))
            .topic(topic?.applyValue({ args0 -> args0 })).build()
}

/**
 * Builder for [NotificationArgs].
 */
@PulumiTagMarker
public class NotificationArgsBuilder internal constructor() {
    private var bucket: Output? = null

    private var customAttributes: Output>? = null

    private var eventTypes: Output>? = null

    private var objectNamePrefix: Output? = null

    private var payloadFormat: Output? = null

    private var topic: Output? = null

    /**
     * @param value The name of the bucket.
     */
    @JvmName("mudjphtjsixcnwym")
    public suspend fun bucket(`value`: Output) {
        this.bucket = value
    }

    /**
     * @param value A set of key/value attribute pairs to attach to each Cloud PubSub message published for this notification subscription
     */
    @JvmName("vwurghvfjavqhghx")
    public suspend fun customAttributes(`value`: Output>) {
        this.customAttributes = value
    }

    /**
     * @param value List of event type filters for this notification config. If not specified, Cloud Storage will send notifications for all event types. The valid types are: `"OBJECT_FINALIZE"`, `"OBJECT_METADATA_UPDATE"`, `"OBJECT_DELETE"`, `"OBJECT_ARCHIVE"`
     */
    @JvmName("okoehkdnuelltbfk")
    public suspend fun eventTypes(`value`: Output>) {
        this.eventTypes = value
    }

    @JvmName("gskuikvqwwjggqst")
    public suspend fun eventTypes(vararg values: Output) {
        this.eventTypes = Output.all(values.asList())
    }

    /**
     * @param values List of event type filters for this notification config. If not specified, Cloud Storage will send notifications for all event types. The valid types are: `"OBJECT_FINALIZE"`, `"OBJECT_METADATA_UPDATE"`, `"OBJECT_DELETE"`, `"OBJECT_ARCHIVE"`
     */
    @JvmName("xqwwxfajqcvuudnt")
    public suspend fun eventTypes(values: List>) {
        this.eventTypes = Output.all(values)
    }

    /**
     * @param value Specifies a prefix path filter for this notification config. Cloud Storage will only send notifications for objects in this bucket whose names begin with the specified prefix.
     */
    @JvmName("dplwqngjvaxhgcnu")
    public suspend fun objectNamePrefix(`value`: Output) {
        this.objectNamePrefix = value
    }

    /**
     * @param value The desired content of the Payload. One of `"JSON_API_V1"` or `"NONE"`.
     */
    @JvmName("fmdgncaitqnemoae")
    public suspend fun payloadFormat(`value`: Output) {
        this.payloadFormat = value
    }

    /**
     * @param value The Cloud PubSub topic to which this subscription publishes. Expects either the
     * topic name, assumed to belong to the default GCP provider project, or the project-level name,
     * i.e. `projects/my-gcp-project/topics/my-topic` or `my-topic`. If the project is not set in the provider,
     * you will need to use the project-level name.
     * - - -
     */
    @JvmName("jmroosxsqorcxcgo")
    public suspend fun topic(`value`: Output) {
        this.topic = value
    }

    /**
     * @param value The name of the bucket.
     */
    @JvmName("byrcdbsbwkhgutkr")
    public suspend fun bucket(`value`: String?) {
        val toBeMapped = value
        val mapped = toBeMapped?.let({ args0 -> of(args0) })
        this.bucket = mapped
    }

    /**
     * @param value A set of key/value attribute pairs to attach to each Cloud PubSub message published for this notification subscription
     */
    @JvmName("ygtmpegqlkmmntja")
    public suspend fun customAttributes(`value`: Map?) {
        val toBeMapped = value
        val mapped = toBeMapped?.let({ args0 -> of(args0) })
        this.customAttributes = mapped
    }

    /**
     * @param values A set of key/value attribute pairs to attach to each Cloud PubSub message published for this notification subscription
     */
    @JvmName("nrqefywmlmheounj")
    public fun customAttributes(vararg values: Pair) {
        val toBeMapped = values.toMap()
        val mapped = toBeMapped.let({ args0 -> of(args0) })
        this.customAttributes = mapped
    }

    /**
     * @param value List of event type filters for this notification config. If not specified, Cloud Storage will send notifications for all event types. The valid types are: `"OBJECT_FINALIZE"`, `"OBJECT_METADATA_UPDATE"`, `"OBJECT_DELETE"`, `"OBJECT_ARCHIVE"`
     */
    @JvmName("wbrpekrtrdvmsvga")
    public suspend fun eventTypes(`value`: List?) {
        val toBeMapped = value
        val mapped = toBeMapped?.let({ args0 -> of(args0) })
        this.eventTypes = mapped
    }

    /**
     * @param values List of event type filters for this notification config. If not specified, Cloud Storage will send notifications for all event types. The valid types are: `"OBJECT_FINALIZE"`, `"OBJECT_METADATA_UPDATE"`, `"OBJECT_DELETE"`, `"OBJECT_ARCHIVE"`
     */
    @JvmName("vechjvpqasymynyf")
    public suspend fun eventTypes(vararg values: String) {
        val toBeMapped = values.toList()
        val mapped = toBeMapped.let({ args0 -> of(args0) })
        this.eventTypes = mapped
    }

    /**
     * @param value Specifies a prefix path filter for this notification config. Cloud Storage will only send notifications for objects in this bucket whose names begin with the specified prefix.
     */
    @JvmName("ukrghletydabjnss")
    public suspend fun objectNamePrefix(`value`: String?) {
        val toBeMapped = value
        val mapped = toBeMapped?.let({ args0 -> of(args0) })
        this.objectNamePrefix = mapped
    }

    /**
     * @param value The desired content of the Payload. One of `"JSON_API_V1"` or `"NONE"`.
     */
    @JvmName("etsvwpfmgcuoicaj")
    public suspend fun payloadFormat(`value`: String?) {
        val toBeMapped = value
        val mapped = toBeMapped?.let({ args0 -> of(args0) })
        this.payloadFormat = mapped
    }

    /**
     * @param value The Cloud PubSub topic to which this subscription publishes. Expects either the
     * topic name, assumed to belong to the default GCP provider project, or the project-level name,
     * i.e. `projects/my-gcp-project/topics/my-topic` or `my-topic`. If the project is not set in the provider,
     * you will need to use the project-level name.
     * - - -
     */
    @JvmName("gyxsktvkucihuyfp")
    public suspend fun topic(`value`: String?) {
        val toBeMapped = value
        val mapped = toBeMapped?.let({ args0 -> of(args0) })
        this.topic = mapped
    }

    internal fun build(): NotificationArgs = NotificationArgs(
        bucket = bucket,
        customAttributes = customAttributes,
        eventTypes = eventTypes,
        objectNamePrefix = objectNamePrefix,
        payloadFormat = payloadFormat,
        topic = topic,
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy