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

com.pulumi.gcp.storage.kotlin.Notification.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.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.Map

/**
 * Builder for [Notification].
 */
@PulumiTagMarker
public class NotificationResourceBuilder internal constructor() {
    public var name: String? = null

    public var args: NotificationArgs = NotificationArgs()

    public var opts: CustomResourceOptions = CustomResourceOptions()

    /**
     * @param name The _unique_ name of the resulting resource.
     */
    public fun name(`value`: String) {
        this.name = value
    }

    /**
     * @param block The arguments to use to populate this resource's properties.
     */
    public suspend fun args(block: suspend NotificationArgsBuilder.() -> Unit) {
        val builder = NotificationArgsBuilder()
        block(builder)
        this.args = builder.build()
    }

    /**
     * @param block A bag of options that control this resource's behavior.
     */
    public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
        this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
    }

    internal fun build(): Notification {
        val builtJavaResource = com.pulumi.gcp.storage.Notification(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return Notification(builtJavaResource)
    }
}

/**
 * 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}}
 * ```
 */
public class Notification internal constructor(
    override val javaResource: com.pulumi.gcp.storage.Notification,
) : KotlinCustomResource(javaResource, NotificationMapper) {
    /**
     * The name of the bucket.
     */
    public val bucket: Output
        get() = javaResource.bucket().applyValue({ args0 -> args0 })

    /**
     * A set of key/value attribute pairs to attach to each Cloud PubSub message published for this notification subscription
     */
    public val customAttributes: Output>?
        get() = javaResource.customAttributes().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.map({ args0 -> args0.key.to(args0.value) }).toMap()
            }).orElse(null)
        })

    /**
     * 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"`
     */
    public val eventTypes: Output>?
        get() = javaResource.eventTypes().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.map({ args0 ->
                    args0
                })
            }).orElse(null)
        })

    /**
     * The ID of the created notification.
     */
    public val notificationId: Output
        get() = javaResource.notificationId().applyValue({ args0 -> args0 })

    /**
     * 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.
     */
    public val objectNamePrefix: Output?
        get() = javaResource.objectNamePrefix().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The desired content of the Payload. One of `"JSON_API_V1"` or `"NONE"`.
     */
    public val payloadFormat: Output
        get() = javaResource.payloadFormat().applyValue({ args0 -> args0 })

    /**
     * The URI of the created resource.
     */
    public val selfLink: Output
        get() = javaResource.selfLink().applyValue({ args0 -> args0 })

    /**
     * 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 val topic: Output
        get() = javaResource.topic().applyValue({ args0 -> args0 })
}

public object NotificationMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.gcp.storage.Notification::class == javaResource::class

    override fun map(javaResource: Resource): Notification = Notification(
        javaResource as
            com.pulumi.gcp.storage.Notification,
    )
}

/**
 * @see [Notification].
 * @param name The _unique_ name of the resulting resource.
 * @param block Builder for [Notification].
 */
public suspend fun notification(
    name: String,
    block: suspend NotificationResourceBuilder.() -> Unit,
): Notification {
    val builder = NotificationResourceBuilder()
    builder.name(name)
    block(builder)
    return builder.build()
}

/**
 * @see [Notification].
 * @param name The _unique_ name of the resulting resource.
 */
public fun notification(name: String): Notification {
    val builder = NotificationResourceBuilder()
    builder.name(name)
    return builder.build()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy