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

com.pulumi.gcp.pubsub.kotlin.Schema.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.pubsub.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

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

    public var args: SchemaArgs = SchemaArgs()

    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 SchemaArgsBuilder.() -> Unit) {
        val builder = SchemaArgsBuilder()
        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(): Schema {
        val builtJavaResource = com.pulumi.gcp.pubsub.Schema(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return Schema(builtJavaResource)
    }
}

/**
 * A schema is a format that messages must follow,
 * creating a contract between publisher and subscriber that Pub/Sub will enforce.
 * To get more information about Schema, see:
 * * [API documentation](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas)
 * * How-to Guides
 *     * [Creating and managing schemas](https://cloud.google.com/pubsub/docs/schemas)
 * ## Example Usage
 * ### Pubsub Schema Basic
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * const example = new gcp.pubsub.Schema("example", {
 *     name: "example-schema",
 *     type: "AVRO",
 *     definition: `{
 *   "type" : "record",
 *   "name" : "Avro",
 *   "fields" : [
 *     {
 *       "name" : "StringField",
 *       "type" : "string"
 *     },
 *     {
 *       "name" : "IntField",
 *       "type" : "int"
 *     }
 *   ]
 * }
 * `,
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * example = gcp.pubsub.Schema("example",
 *     name="example-schema",
 *     type="AVRO",
 *     definition="""{
 *   "type" : "record",
 *   "name" : "Avro",
 *   "fields" : [
 *     {
 *       "name" : "StringField",
 *       "type" : "string"
 *     },
 *     {
 *       "name" : "IntField",
 *       "type" : "int"
 *     }
 *   ]
 * }
 * """)
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     var example = new Gcp.PubSub.Schema("example", new()
 *     {
 *         Name = "example-schema",
 *         Type = "AVRO",
 *         Definition = @"{
 *   ""type"" : ""record"",
 *   ""name"" : ""Avro"",
 *   ""fields"" : [
 *     {
 *       ""name"" : ""StringField"",
 *       ""type"" : ""string""
 *     },
 *     {
 *       ""name"" : ""IntField"",
 *       ""type"" : ""int""
 *     }
 *   ]
 * }
 * ",
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/pubsub"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		_, err := pubsub.NewSchema(ctx, "example", &pubsub.SchemaArgs{
 * 			Name: pulumi.String("example-schema"),
 * 			Type: pulumi.String("AVRO"),
 * 			Definition: pulumi.String(`{
 *   "type" : "record",
 *   "name" : "Avro",
 *   "fields" : [
 *     {
 *       "name" : "StringField",
 *       "type" : "string"
 *     },
 *     {
 *       "name" : "IntField",
 *       "type" : "int"
 *     }
 *   ]
 * }
 * `),
 * 		})
 * 		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.pubsub.Schema;
 * import com.pulumi.gcp.pubsub.SchemaArgs;
 * 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 Schema("example", SchemaArgs.builder()
 *             .name("example-schema")
 *             .type("AVRO")
 *             .definition("""
 * {
 *   "type" : "record",
 *   "name" : "Avro",
 *   "fields" : [
 *     {
 *       "name" : "StringField",
 *       "type" : "string"
 *     },
 *     {
 *       "name" : "IntField",
 *       "type" : "int"
 *     }
 *   ]
 * }
 *             """)
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   example:
 *     type: gcp:pubsub:Schema
 *     properties:
 *       name: example-schema
 *       type: AVRO
 *       definition: |
 *         {
 *           "type" : "record",
 *           "name" : "Avro",
 *           "fields" : [
 *             {
 *               "name" : "StringField",
 *               "type" : "string"
 *             },
 *             {
 *               "name" : "IntField",
 *               "type" : "int"
 *             }
 *           ]
 *         }
 * ```
 * 
 * ### Pubsub Schema Protobuf
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * const example = new gcp.pubsub.Schema("example", {
 *     name: "example",
 *     type: "PROTOCOL_BUFFER",
 *     definition: `syntax = "proto3";
 * message Results {
 * string message_request = 1;
 * string message_response = 2;
 * string timestamp_request = 3;
 * string timestamp_response = 4;
 * }`,
 * });
 * const exampleTopic = new gcp.pubsub.Topic("example", {
 *     name: "example-topic",
 *     schemaSettings: {
 *         schema: "projects/my-project-name/schemas/example",
 *         encoding: "JSON",
 *     },
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * example = gcp.pubsub.Schema("example",
 *     name="example",
 *     type="PROTOCOL_BUFFER",
 *     definition="""syntax = "proto3";
 * message Results {
 * string message_request = 1;
 * string message_response = 2;
 * string timestamp_request = 3;
 * string timestamp_response = 4;
 * }""")
 * example_topic = gcp.pubsub.Topic("example",
 *     name="example-topic",
 *     schema_settings=gcp.pubsub.TopicSchemaSettingsArgs(
 *         schema="projects/my-project-name/schemas/example",
 *         encoding="JSON",
 *     ))
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     var example = new Gcp.PubSub.Schema("example", new()
 *     {
 *         Name = "example",
 *         Type = "PROTOCOL_BUFFER",
 *         Definition = @"syntax = ""proto3"";
 * message Results {
 * string message_request = 1;
 * string message_response = 2;
 * string timestamp_request = 3;
 * string timestamp_response = 4;
 * }",
 *     });
 *     var exampleTopic = new Gcp.PubSub.Topic("example", new()
 *     {
 *         Name = "example-topic",
 *         SchemaSettings = new Gcp.PubSub.Inputs.TopicSchemaSettingsArgs
 *         {
 *             Schema = "projects/my-project-name/schemas/example",
 *             Encoding = "JSON",
 *         },
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/pubsub"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		_, err := pubsub.NewSchema(ctx, "example", &pubsub.SchemaArgs{
 * 			Name: pulumi.String("example"),
 * 			Type: pulumi.String("PROTOCOL_BUFFER"),
 * 			Definition: pulumi.String(`syntax = "proto3";
 * message Results {
 * string message_request = 1;
 * string message_response = 2;
 * string timestamp_request = 3;
 * string timestamp_response = 4;
 * }`),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = pubsub.NewTopic(ctx, "example", &pubsub.TopicArgs{
 * 			Name: pulumi.String("example-topic"),
 * 			SchemaSettings: &pubsub.TopicSchemaSettingsArgs{
 * 				Schema:   pulumi.String("projects/my-project-name/schemas/example"),
 * 				Encoding: pulumi.String("JSON"),
 * 			},
 * 		})
 * 		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.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 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 Schema("example", SchemaArgs.builder()
 *             .name("example")
 *             .type("PROTOCOL_BUFFER")
 *             .definition("""
 * syntax = "proto3";
 * message Results {
 * string message_request = 1;
 * string message_response = 2;
 * string timestamp_request = 3;
 * string timestamp_response = 4;
 * }            """)
 *             .build());
 *         var exampleTopic = new Topic("exampleTopic", TopicArgs.builder()
 *             .name("example-topic")
 *             .schemaSettings(TopicSchemaSettingsArgs.builder()
 *                 .schema("projects/my-project-name/schemas/example")
 *                 .encoding("JSON")
 *                 .build())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   example:
 *     type: gcp:pubsub:Schema
 *     properties:
 *       name: example
 *       type: PROTOCOL_BUFFER
 *       definition: |-
 *         syntax = "proto3";
 *         message Results {
 *         string message_request = 1;
 *         string message_response = 2;
 *         string timestamp_request = 3;
 *         string timestamp_response = 4;
 *         }
 *   exampleTopic:
 *     type: gcp:pubsub:Topic
 *     name: example
 *     properties:
 *       name: example-topic
 *       schemaSettings:
 *         schema: projects/my-project-name/schemas/example
 *         encoding: JSON
 * ```
 * 
 * ## Import
 * Schema can be imported using any of these accepted formats:
 * * `projects/{{project}}/schemas/{{name}}`
 * * `{{project}}/{{name}}`
 * * `{{name}}`
 * When using the `pulumi import` command, Schema can be imported using one of the formats above. For example:
 * ```sh
 * $ pulumi import gcp:pubsub/schema:Schema default projects/{{project}}/schemas/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:pubsub/schema:Schema default {{project}}/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:pubsub/schema:Schema default {{name}}
 * ```
 */
public class Schema internal constructor(
    override val javaResource: com.pulumi.gcp.pubsub.Schema,
) : KotlinCustomResource(javaResource, SchemaMapper) {
    /**
     * The definition of the schema.
     * This should contain a string representing the full definition of the schema
     * that is a valid schema definition of the type specified in type. Changes
     * to the definition commit new [schema revisions](https://cloud.google.com/pubsub/docs/commit-schema-revision).
     * A schema can only have up to 20 revisions, so updates that fail with an
     * error indicating that the limit has been reached require manually
     * [deleting old revisions](https://cloud.google.com/pubsub/docs/delete-schema-revision).
     */
    public val definition: Output?
        get() = javaResource.definition().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The ID to use for the schema, which will become the final component of the schema's resource name.
     * - - -
     */
    public val name: Output
        get() = javaResource.name().applyValue({ args0 -> args0 })

    /**
     * The ID of the project in which the resource belongs.
     * If it is not provided, the provider project is used.
     */
    public val project: Output
        get() = javaResource.project().applyValue({ args0 -> args0 })

    /**
     * The type of the schema definition
     * Default value is `TYPE_UNSPECIFIED`.
     * Possible values are: `TYPE_UNSPECIFIED`, `PROTOCOL_BUFFER`, `AVRO`.
     */
    public val type: Output?
        get() = javaResource.type().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })
}

public object SchemaMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.gcp.pubsub.Schema::class == javaResource::class

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy