1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. bigtable
  5. MaterializedView
Google Cloud v8.30.1 published on Tuesday, May 13, 2025 by Pulumi

gcp.bigtable.MaterializedView

Explore with Pulumi AI

gcp logo
Google Cloud v8.30.1 published on Tuesday, May 13, 2025 by Pulumi

    A materialized view object that can be referenced in SQL queries.

    To get more information about MaterializedView, see:

    Example Usage

    Bigtable Materialized View

    import * as pulumi from "@pulumi/pulumi";
    import * as gcp from "@pulumi/gcp";
    
    const instance = new gcp.bigtable.Instance("instance", {
        name: "bt-instance",
        clusters: [{
            clusterId: "cluster-1",
            zone: "us-east1-b",
            numNodes: 3,
            storageType: "HDD",
        }],
        deletionProtection: true,
    });
    const table = new gcp.bigtable.Table("table", {
        name: "bt-table",
        instanceName: instance.name,
        columnFamilies: [{
            family: "CF",
        }],
    });
    const materializedView = new gcp.bigtable.MaterializedView("materialized_view", {
        materializedViewId: "bt-materialized-view",
        instance: instance.name,
        deletionProtection: false,
        query: `SELECT _key, COUNT(CF['col1']) as Count
    FROM \` + "\`bt-table\`" + \`
    GROUP BY _key
    `,
    }, {
        dependsOn: [table],
    });
    
    import pulumi
    import pulumi_gcp as gcp
    
    instance = gcp.bigtable.Instance("instance",
        name="bt-instance",
        clusters=[{
            "cluster_id": "cluster-1",
            "zone": "us-east1-b",
            "num_nodes": 3,
            "storage_type": "HDD",
        }],
        deletion_protection=True)
    table = gcp.bigtable.Table("table",
        name="bt-table",
        instance_name=instance.name,
        column_families=[{
            "family": "CF",
        }])
    materialized_view = gcp.bigtable.MaterializedView("materialized_view",
        materialized_view_id="bt-materialized-view",
        instance=instance.name,
        deletion_protection=False,
        query="""SELECT _key, COUNT(CF['col1']) as Count
    FROM ` + "`bt-table`" + `
    GROUP BY _key
    """,
        opts = pulumi.ResourceOptions(depends_on=[table]))
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/bigtable"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		instance, err := bigtable.NewInstance(ctx, "instance", &bigtable.InstanceArgs{
    			Name: pulumi.String("bt-instance"),
    			Clusters: bigtable.InstanceClusterArray{
    				&bigtable.InstanceClusterArgs{
    					ClusterId:   pulumi.String("cluster-1"),
    					Zone:        pulumi.String("us-east1-b"),
    					NumNodes:    pulumi.Int(3),
    					StorageType: pulumi.String("HDD"),
    				},
    			},
    			DeletionProtection: pulumi.Bool(true),
    		})
    		if err != nil {
    			return err
    		}
    		table, err := bigtable.NewTable(ctx, "table", &bigtable.TableArgs{
    			Name:         pulumi.String("bt-table"),
    			InstanceName: instance.Name,
    			ColumnFamilies: bigtable.TableColumnFamilyArray{
    				&bigtable.TableColumnFamilyArgs{
    					Family: pulumi.String("CF"),
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = bigtable.NewMaterializedView(ctx, "materialized_view", &bigtable.MaterializedViewArgs{
    			MaterializedViewId: pulumi.String("bt-materialized-view"),
    			Instance:           instance.Name,
    			DeletionProtection: pulumi.Bool(false),
    			Query:              pulumi.String("SELECT _key, COUNT(CF['col1']) as Count\nFROM ` + \"`bt-table`\" + `\nGROUP BY _key\n"),
    		}, pulumi.DependsOn([]pulumi.Resource{
    			table,
    		}))
    		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 instance = new Gcp.BigTable.Instance("instance", new()
        {
            Name = "bt-instance",
            Clusters = new[]
            {
                new Gcp.BigTable.Inputs.InstanceClusterArgs
                {
                    ClusterId = "cluster-1",
                    Zone = "us-east1-b",
                    NumNodes = 3,
                    StorageType = "HDD",
                },
            },
            DeletionProtection = true,
        });
    
        var table = new Gcp.BigTable.Table("table", new()
        {
            Name = "bt-table",
            InstanceName = instance.Name,
            ColumnFamilies = new[]
            {
                new Gcp.BigTable.Inputs.TableColumnFamilyArgs
                {
                    Family = "CF",
                },
            },
        });
    
        var materializedView = new Gcp.BigTable.MaterializedView("materialized_view", new()
        {
            MaterializedViewId = "bt-materialized-view",
            Instance = instance.Name,
            DeletionProtection = false,
            Query = @"SELECT _key, COUNT(CF['col1']) as Count
    FROM ` + ""`bt-table`"" + `
    GROUP BY _key
    ",
        }, new CustomResourceOptions
        {
            DependsOn =
            {
                table,
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.gcp.bigtable.Instance;
    import com.pulumi.gcp.bigtable.InstanceArgs;
    import com.pulumi.gcp.bigtable.inputs.InstanceClusterArgs;
    import com.pulumi.gcp.bigtable.Table;
    import com.pulumi.gcp.bigtable.TableArgs;
    import com.pulumi.gcp.bigtable.inputs.TableColumnFamilyArgs;
    import com.pulumi.gcp.bigtable.MaterializedView;
    import com.pulumi.gcp.bigtable.MaterializedViewArgs;
    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 instance = new Instance("instance", InstanceArgs.builder()
                .name("bt-instance")
                .clusters(InstanceClusterArgs.builder()
                    .clusterId("cluster-1")
                    .zone("us-east1-b")
                    .numNodes(3)
                    .storageType("HDD")
                    .build())
                .deletionProtection(true)
                .build());
    
            var table = new Table("table", TableArgs.builder()
                .name("bt-table")
                .instanceName(instance.name())
                .columnFamilies(TableColumnFamilyArgs.builder()
                    .family("CF")
                    .build())
                .build());
    
            var materializedView = new MaterializedView("materializedView", MaterializedViewArgs.builder()
                .materializedViewId("bt-materialized-view")
                .instance(instance.name())
                .deletionProtection(false)
                .query("""
    SELECT _key, COUNT(CF['col1']) as Count
    FROM ` + "`bt-table`" + `
    GROUP BY _key
                """)
                .build(), CustomResourceOptions.builder()
                    .dependsOn(table)
                    .build());
    
        }
    }
    
    resources:
      instance:
        type: gcp:bigtable:Instance
        properties:
          name: bt-instance
          clusters:
            - clusterId: cluster-1
              zone: us-east1-b
              numNodes: 3
              storageType: HDD
          deletionProtection: true
      table:
        type: gcp:bigtable:Table
        properties:
          name: bt-table
          instanceName: ${instance.name}
          columnFamilies:
            - family: CF
      materializedView:
        type: gcp:bigtable:MaterializedView
        name: materialized_view
        properties:
          materializedViewId: bt-materialized-view
          instance: ${instance.name}
          deletionProtection: false
          query: |
            SELECT _key, COUNT(CF['col1']) as Count
            FROM ` + "`bt-table`" + `
            GROUP BY _key        
        options:
          dependsOn:
            - ${table}
    

    Create MaterializedView Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new MaterializedView(name: string, args: MaterializedViewArgs, opts?: CustomResourceOptions);
    @overload
    def MaterializedView(resource_name: str,
                         args: MaterializedViewArgs,
                         opts: Optional[ResourceOptions] = None)
    
    @overload
    def MaterializedView(resource_name: str,
                         opts: Optional[ResourceOptions] = None,
                         materialized_view_id: Optional[str] = None,
                         query: Optional[str] = None,
                         deletion_protection: Optional[bool] = None,
                         instance: Optional[str] = None,
                         project: Optional[str] = None)
    func NewMaterializedView(ctx *Context, name string, args MaterializedViewArgs, opts ...ResourceOption) (*MaterializedView, error)
    public MaterializedView(string name, MaterializedViewArgs args, CustomResourceOptions? opts = null)
    public MaterializedView(String name, MaterializedViewArgs args)
    public MaterializedView(String name, MaterializedViewArgs args, CustomResourceOptions options)
    
    type: gcp:bigtable:MaterializedView
    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 MaterializedViewArgs
    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 MaterializedViewArgs
    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 MaterializedViewArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args MaterializedViewArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args MaterializedViewArgs
    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 materializedViewResource = new Gcp.BigTable.MaterializedView("materializedViewResource", new()
    {
        MaterializedViewId = "string",
        Query = "string",
        DeletionProtection = false,
        Instance = "string",
        Project = "string",
    });
    
    example, err := bigtable.NewMaterializedView(ctx, "materializedViewResource", &bigtable.MaterializedViewArgs{
    	MaterializedViewId: pulumi.String("string"),
    	Query:              pulumi.String("string"),
    	DeletionProtection: pulumi.Bool(false),
    	Instance:           pulumi.String("string"),
    	Project:            pulumi.String("string"),
    })
    
    var materializedViewResource = new MaterializedView("materializedViewResource", MaterializedViewArgs.builder()
        .materializedViewId("string")
        .query("string")
        .deletionProtection(false)
        .instance("string")
        .project("string")
        .build());
    
    materialized_view_resource = gcp.bigtable.MaterializedView("materializedViewResource",
        materialized_view_id="string",
        query="string",
        deletion_protection=False,
        instance="string",
        project="string")
    
    const materializedViewResource = new gcp.bigtable.MaterializedView("materializedViewResource", {
        materializedViewId: "string",
        query: "string",
        deletionProtection: false,
        instance: "string",
        project: "string",
    });
    
    type: gcp:bigtable:MaterializedView
    properties:
        deletionProtection: false
        instance: string
        materializedViewId: string
        project: string
        query: string
    

    MaterializedView Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The MaterializedView resource accepts the following input properties:

    MaterializedViewId string
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    Query string
    The materialized view's select query.
    DeletionProtection bool
    Set to true to make the MaterializedView protected against deletion.
    Instance string
    The name of the instance to create the materialized view within.
    Project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    MaterializedViewId string
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    Query string
    The materialized view's select query.
    DeletionProtection bool
    Set to true to make the MaterializedView protected against deletion.
    Instance string
    The name of the instance to create the materialized view within.
    Project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    materializedViewId String
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    query String
    The materialized view's select query.
    deletionProtection Boolean
    Set to true to make the MaterializedView protected against deletion.
    instance String
    The name of the instance to create the materialized view within.
    project String
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    materializedViewId string
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    query string
    The materialized view's select query.
    deletionProtection boolean
    Set to true to make the MaterializedView protected against deletion.
    instance string
    The name of the instance to create the materialized view within.
    project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    materialized_view_id str
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    query str
    The materialized view's select query.
    deletion_protection bool
    Set to true to make the MaterializedView protected against deletion.
    instance str
    The name of the instance to create the materialized view within.
    project str
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    materializedViewId String
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    query String
    The materialized view's select query.
    deletionProtection Boolean
    Set to true to make the MaterializedView protected against deletion.
    instance String
    The name of the instance to create the materialized view within.
    project String
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the MaterializedView resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    id string
    The provider-assigned unique ID for this managed resource.
    name string
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    id str
    The provider-assigned unique ID for this managed resource.
    name str
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.

    Look up Existing MaterializedView Resource

    Get an existing MaterializedView 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?: MaterializedViewState, opts?: CustomResourceOptions): MaterializedView
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            deletion_protection: Optional[bool] = None,
            instance: Optional[str] = None,
            materialized_view_id: Optional[str] = None,
            name: Optional[str] = None,
            project: Optional[str] = None,
            query: Optional[str] = None) -> MaterializedView
    func GetMaterializedView(ctx *Context, name string, id IDInput, state *MaterializedViewState, opts ...ResourceOption) (*MaterializedView, error)
    public static MaterializedView Get(string name, Input<string> id, MaterializedViewState? state, CustomResourceOptions? opts = null)
    public static MaterializedView get(String name, Output<String> id, MaterializedViewState state, CustomResourceOptions options)
    resources:  _:    type: gcp:bigtable:MaterializedView    get:      id: ${id}
    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.
    The following state arguments are supported:
    DeletionProtection bool
    Set to true to make the MaterializedView protected against deletion.
    Instance string
    The name of the instance to create the materialized view within.
    MaterializedViewId string
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    Name string
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    Project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    Query string
    The materialized view's select query.
    DeletionProtection bool
    Set to true to make the MaterializedView protected against deletion.
    Instance string
    The name of the instance to create the materialized view within.
    MaterializedViewId string
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    Name string
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    Project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    Query string
    The materialized view's select query.
    deletionProtection Boolean
    Set to true to make the MaterializedView protected against deletion.
    instance String
    The name of the instance to create the materialized view within.
    materializedViewId String
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    name String
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    project String
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    query String
    The materialized view's select query.
    deletionProtection boolean
    Set to true to make the MaterializedView protected against deletion.
    instance string
    The name of the instance to create the materialized view within.
    materializedViewId string
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    name string
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    query string
    The materialized view's select query.
    deletion_protection bool
    Set to true to make the MaterializedView protected against deletion.
    instance str
    The name of the instance to create the materialized view within.
    materialized_view_id str
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    name str
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    project str
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    query str
    The materialized view's select query.
    deletionProtection Boolean
    Set to true to make the MaterializedView protected against deletion.
    instance String
    The name of the instance to create the materialized view within.
    materializedViewId String
    The unique name of the materialized view in the form [_a-zA-Z0-9][-_.a-zA-Z0-9]*.


    name String
    The unique name of the requested materialized view. Values are of the form projects/<project>/instances/<instance>/materializedViews/<materializedViewId>.
    project String
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    query String
    The materialized view's select query.

    Import

    MaterializedView can be imported using any of these accepted formats:

    • projects/{{project}}/instances/{{instance}}/materializedViews/{{materialized_view_id}}

    • {{project}}/{{instance}}/{{materialized_view_id}}

    • {{instance}}/{{materialized_view_id}}

    When using the pulumi import command, MaterializedView can be imported using one of the formats above. For example:

    $ pulumi import gcp:bigtable/materializedView:MaterializedView default projects/{{project}}/instances/{{instance}}/materializedViews/{{materialized_view_id}}
    
    $ pulumi import gcp:bigtable/materializedView:MaterializedView default {{project}}/{{instance}}/{{materialized_view_id}}
    
    $ pulumi import gcp:bigtable/materializedView:MaterializedView default {{instance}}/{{materialized_view_id}}
    

    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.
    gcp logo
    Google Cloud v8.30.1 published on Tuesday, May 13, 2025 by Pulumi