gcp.pubsub.Schema
Explore with Pulumi AI
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
- How-to Guides
Example Usage
Pubsub Schema Basic
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"
}
]
}
`,
});
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"
}
]
}
""")
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v8/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
})
}
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""
}
]
}
",
});
});
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());
}
}
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
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",
},
}, {
dependsOn: [example],
});
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={
"schema": "projects/my-project-name/schemas/example",
"encoding": "JSON",
},
opts = pulumi.ResourceOptions(depends_on=[example]))
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/pubsub"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, 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"),
},
}, pulumi.DependsOn([]pulumi.Resource{
example,
}))
if err != nil {
return err
}
return nil
})
}
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",
},
}, new CustomResourceOptions
{
DependsOn =
{
example,
},
});
});
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 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(), CustomResourceOptions.builder()
.dependsOn(example)
.build());
}
}
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
options:
dependson:
- ${example}
Create Schema Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new Schema(name: string, args?: SchemaArgs, opts?: CustomResourceOptions);
@overload
def Schema(resource_name: str,
args: Optional[SchemaArgs] = None,
opts: Optional[ResourceOptions] = None)
@overload
def Schema(resource_name: str,
opts: Optional[ResourceOptions] = None,
definition: Optional[str] = None,
name: Optional[str] = None,
project: Optional[str] = None,
type: Optional[str] = None)
func NewSchema(ctx *Context, name string, args *SchemaArgs, opts ...ResourceOption) (*Schema, error)
public Schema(string name, SchemaArgs? args = null, CustomResourceOptions? opts = null)
public Schema(String name, SchemaArgs args)
public Schema(String name, SchemaArgs args, CustomResourceOptions options)
type: gcp:pubsub:Schema
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args SchemaArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args SchemaArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args SchemaArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args SchemaArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args SchemaArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var gcpSchemaResource = new Gcp.PubSub.Schema("gcpSchemaResource", new()
{
Definition = "string",
Name = "string",
Project = "string",
Type = "string",
});
example, err := pubsub.NewSchema(ctx, "gcpSchemaResource", &pubsub.SchemaArgs{
Definition: pulumi.String("string"),
Name: pulumi.String("string"),
Project: pulumi.String("string"),
Type: pulumi.String("string"),
})
var gcpSchemaResource = new Schema("gcpSchemaResource", SchemaArgs.builder()
.definition("string")
.name("string")
.project("string")
.type("string")
.build());
gcp_schema_resource = gcp.pubsub.Schema("gcpSchemaResource",
definition="string",
name="string",
project="string",
type="string")
const gcpSchemaResource = new gcp.pubsub.Schema("gcpSchemaResource", {
definition: "string",
name: "string",
project: "string",
type: "string",
});
type: gcp:pubsub:Schema
properties:
definition: string
name: string
project: string
type: string
Schema Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
The Schema resource accepts the following input properties:
- Definition string
- 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. 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.
- Name string
- The ID to use for the schema, which will become the final component of the schema's resource name.
- Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- Type string
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- Definition string
- 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. 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.
- Name string
- The ID to use for the schema, which will become the final component of the schema's resource name.
- Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- Type string
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- definition String
- 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. 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.
- name String
- The ID to use for the schema, which will become the final component of the schema's resource name.
- project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- type String
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- definition string
- 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. 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.
- name string
- The ID to use for the schema, which will become the final component of the schema's resource name.
- project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- type string
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- definition str
- 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. 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.
- name str
- The ID to use for the schema, which will become the final component of the schema's resource name.
- project str
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- type str
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- definition String
- 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. 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.
- name String
- The ID to use for the schema, which will become the final component of the schema's resource name.
- project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- type String
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
Outputs
All input properties are implicitly available as output properties. Additionally, the Schema resource produces the following output properties:
- Id string
- The provider-assigned unique ID for this managed resource.
- Id string
- The provider-assigned unique ID for this managed resource.
- id String
- The provider-assigned unique ID for this managed resource.
- id string
- The provider-assigned unique ID for this managed resource.
- id str
- The provider-assigned unique ID for this managed resource.
- id String
- The provider-assigned unique ID for this managed resource.
Look up Existing Schema Resource
Get an existing Schema resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: SchemaState, opts?: CustomResourceOptions): Schema
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
definition: Optional[str] = None,
name: Optional[str] = None,
project: Optional[str] = None,
type: Optional[str] = None) -> Schema
func GetSchema(ctx *Context, name string, id IDInput, state *SchemaState, opts ...ResourceOption) (*Schema, error)
public static Schema Get(string name, Input<string> id, SchemaState? state, CustomResourceOptions? opts = null)
public static Schema get(String name, Output<String> id, SchemaState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Definition string
- 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. 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.
- Name string
- The ID to use for the schema, which will become the final component of the schema's resource name.
- Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- Type string
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- Definition string
- 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. 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.
- Name string
- The ID to use for the schema, which will become the final component of the schema's resource name.
- Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- Type string
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- definition String
- 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. 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.
- name String
- The ID to use for the schema, which will become the final component of the schema's resource name.
- project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- type String
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- definition string
- 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. 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.
- name string
- The ID to use for the schema, which will become the final component of the schema's resource name.
- project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- type string
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- definition str
- 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. 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.
- name str
- The ID to use for the schema, which will become the final component of the schema's resource name.
- project str
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- type str
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
- definition String
- 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. 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.
- name String
- The ID to use for the schema, which will become the final component of the schema's resource name.
- project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- type String
- The type of the schema definition
Default value is
TYPE_UNSPECIFIED
. Possible values are:TYPE_UNSPECIFIED
,PROTOCOL_BUFFER
,AVRO
.
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:
$ pulumi import gcp:pubsub/schema:Schema default projects/{{project}}/schemas/{{name}}
$ pulumi import gcp:pubsub/schema:Schema default {{project}}/{{name}}
$ pulumi import gcp:pubsub/schema:Schema default {{name}}
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- Google Cloud (GCP) Classic pulumi/pulumi-gcp
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
google-beta
Terraform Provider.