1. Packages
  2. Postgresql Provider
  3. API Docs
  4. DefaultPrivileg
PostgreSQL v3.14.0 published on Friday, Dec 6, 2024 by Pulumi

postgresql.DefaultPrivileg

Explore with Pulumi AI

postgresql logo
PostgreSQL v3.14.0 published on Friday, Dec 6, 2024 by Pulumi
    Deprecated: postgresql.DefaultPrivileg has been deprecated in favor of postgresql.DefaultPrivileges

    The postgresql.DefaultPrivileges resource creates and manages default privileges given to a user for a database schema.

    Note: This resource needs Postgresql version 9 or above.

    Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as postgresql from "@pulumi/postgresql";
    
    const readOnlyTables = new postgresql.DefaultPrivileges("read_only_tables", {
        role: "test_role",
        database: "test_db",
        schema: "public",
        owner: "db_owner",
        objectType: "table",
        privileges: ["SELECT"],
    });
    
    import pulumi
    import pulumi_postgresql as postgresql
    
    read_only_tables = postgresql.DefaultPrivileges("read_only_tables",
        role="test_role",
        database="test_db",
        schema="public",
        owner="db_owner",
        object_type="table",
        privileges=["SELECT"])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-postgresql/sdk/v3/go/postgresql"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := postgresql.NewDefaultPrivileges(ctx, "read_only_tables", &postgresql.DefaultPrivilegesArgs{
    			Role:       pulumi.String("test_role"),
    			Database:   pulumi.String("test_db"),
    			Schema:     pulumi.String("public"),
    			Owner:      pulumi.String("db_owner"),
    			ObjectType: pulumi.String("table"),
    			Privileges: pulumi.StringArray{
    				pulumi.String("SELECT"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using PostgreSql = Pulumi.PostgreSql;
    
    return await Deployment.RunAsync(() => 
    {
        var readOnlyTables = new PostgreSql.DefaultPrivileges("read_only_tables", new()
        {
            Role = "test_role",
            Database = "test_db",
            Schema = "public",
            Owner = "db_owner",
            ObjectType = "table",
            Privileges = new[]
            {
                "SELECT",
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.postgresql.DefaultPrivileges;
    import com.pulumi.postgresql.DefaultPrivilegesArgs;
    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 readOnlyTables = new DefaultPrivileges("readOnlyTables", DefaultPrivilegesArgs.builder()
                .role("test_role")
                .database("test_db")
                .schema("public")
                .owner("db_owner")
                .objectType("table")
                .privileges("SELECT")
                .build());
    
        }
    }
    
    resources:
      readOnlyTables:
        type: postgresql:DefaultPrivileges
        name: read_only_tables
        properties:
          role: test_role
          database: test_db
          schema: public
          owner: db_owner
          objectType: table
          privileges:
            - SELECT
    

    Examples

    Grant default privileges for tables to “current_role” role:

    import * as pulumi from "@pulumi/pulumi";
    import * as postgresql from "@pulumi/postgresql";
    
    const grantTablePrivileges = new postgresql.DefaultPrivileges("grant_table_privileges", {
        database: exampleDb.name,
        role: "current_role",
        owner: "owner_role",
        schema: "public",
        objectType: "table",
        privileges: [
            "SELECT",
            "INSERT",
            "UPDATE",
        ],
    });
    
    import pulumi
    import pulumi_postgresql as postgresql
    
    grant_table_privileges = postgresql.DefaultPrivileges("grant_table_privileges",
        database=example_db["name"],
        role="current_role",
        owner="owner_role",
        schema="public",
        object_type="table",
        privileges=[
            "SELECT",
            "INSERT",
            "UPDATE",
        ])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-postgresql/sdk/v3/go/postgresql"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := postgresql.NewDefaultPrivileges(ctx, "grant_table_privileges", &postgresql.DefaultPrivilegesArgs{
    			Database:   pulumi.Any(exampleDb.Name),
    			Role:       pulumi.String("current_role"),
    			Owner:      pulumi.String("owner_role"),
    			Schema:     pulumi.String("public"),
    			ObjectType: pulumi.String("table"),
    			Privileges: pulumi.StringArray{
    				pulumi.String("SELECT"),
    				pulumi.String("INSERT"),
    				pulumi.String("UPDATE"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using PostgreSql = Pulumi.PostgreSql;
    
    return await Deployment.RunAsync(() => 
    {
        var grantTablePrivileges = new PostgreSql.DefaultPrivileges("grant_table_privileges", new()
        {
            Database = exampleDb.Name,
            Role = "current_role",
            Owner = "owner_role",
            Schema = "public",
            ObjectType = "table",
            Privileges = new[]
            {
                "SELECT",
                "INSERT",
                "UPDATE",
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.postgresql.DefaultPrivileges;
    import com.pulumi.postgresql.DefaultPrivilegesArgs;
    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 grantTablePrivileges = new DefaultPrivileges("grantTablePrivileges", DefaultPrivilegesArgs.builder()
                .database(exampleDb.name())
                .role("current_role")
                .owner("owner_role")
                .schema("public")
                .objectType("table")
                .privileges(            
                    "SELECT",
                    "INSERT",
                    "UPDATE")
                .build());
    
        }
    }
    
    resources:
      grantTablePrivileges:
        type: postgresql:DefaultPrivileges
        name: grant_table_privileges
        properties:
          database: ${exampleDb.name}
          role: current_role
          owner: owner_role
          schema: public
          objectType: table
          privileges:
            - SELECT
            - INSERT
            - UPDATE
    

    Whenever the owner_role creates a new table in the public schema, the current_role is automatically granted SELECT, INSERT, and UPDATE privileges on that table.

    Revoke default privileges for functions for “public” role:

    import * as pulumi from "@pulumi/pulumi";
    import * as postgresql from "@pulumi/postgresql";
    
    const revokePublic = new postgresql.DefaultPrivileges("revoke_public", {
        database: exampleDb.name,
        role: "public",
        owner: "object_owner",
        objectType: "function",
        privileges: [],
    });
    
    import pulumi
    import pulumi_postgresql as postgresql
    
    revoke_public = postgresql.DefaultPrivileges("revoke_public",
        database=example_db["name"],
        role="public",
        owner="object_owner",
        object_type="function",
        privileges=[])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-postgresql/sdk/v3/go/postgresql"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := postgresql.NewDefaultPrivileges(ctx, "revoke_public", &postgresql.DefaultPrivilegesArgs{
    			Database:   pulumi.Any(exampleDb.Name),
    			Role:       pulumi.String("public"),
    			Owner:      pulumi.String("object_owner"),
    			ObjectType: pulumi.String("function"),
    			Privileges: pulumi.StringArray{},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using PostgreSql = Pulumi.PostgreSql;
    
    return await Deployment.RunAsync(() => 
    {
        var revokePublic = new PostgreSql.DefaultPrivileges("revoke_public", new()
        {
            Database = exampleDb.Name,
            Role = "public",
            Owner = "object_owner",
            ObjectType = "function",
            Privileges = new[] {},
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.postgresql.DefaultPrivileges;
    import com.pulumi.postgresql.DefaultPrivilegesArgs;
    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 revokePublic = new DefaultPrivileges("revokePublic", DefaultPrivilegesArgs.builder()
                .database(exampleDb.name())
                .role("public")
                .owner("object_owner")
                .objectType("function")
                .privileges()
                .build());
    
        }
    }
    
    resources:
      revokePublic:
        type: postgresql:DefaultPrivileges
        name: revoke_public
        properties:
          database: ${exampleDb.name}
          role: public
          owner: object_owner
          objectType: function
          privileges: []
    

    Create DefaultPrivileg Resource

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

    Constructor syntax

    new DefaultPrivileg(name: string, args: DefaultPrivilegArgs, opts?: CustomResourceOptions);
    @overload
    def DefaultPrivileg(resource_name: str,
                        args: DefaultPrivilegArgs,
                        opts: Optional[ResourceOptions] = None)
    
    @overload
    def DefaultPrivileg(resource_name: str,
                        opts: Optional[ResourceOptions] = None,
                        database: Optional[str] = None,
                        object_type: Optional[str] = None,
                        owner: Optional[str] = None,
                        privileges: Optional[Sequence[str]] = None,
                        role: Optional[str] = None,
                        schema: Optional[str] = None,
                        with_grant_option: Optional[bool] = None)
    func NewDefaultPrivileg(ctx *Context, name string, args DefaultPrivilegArgs, opts ...ResourceOption) (*DefaultPrivileg, error)
    public DefaultPrivileg(string name, DefaultPrivilegArgs args, CustomResourceOptions? opts = null)
    public DefaultPrivileg(String name, DefaultPrivilegArgs args)
    public DefaultPrivileg(String name, DefaultPrivilegArgs args, CustomResourceOptions options)
    
    type: postgresql:DefaultPrivileg
    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 DefaultPrivilegArgs
    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 DefaultPrivilegArgs
    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 DefaultPrivilegArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args DefaultPrivilegArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args DefaultPrivilegArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    DefaultPrivileg 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 DefaultPrivileg resource accepts the following input properties:

    Database string
    The database to grant default privileges for this role.
    ObjectType string
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    Owner string
    Specifies the role that creates objects for which the default privileges will be applied.
    Privileges List<string>
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    Role string
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    Schema string
    The database schema to set default privileges for this role.
    WithGrantOption bool
    Permit the grant recipient to grant it to others
    Database string
    The database to grant default privileges for this role.
    ObjectType string
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    Owner string
    Specifies the role that creates objects for which the default privileges will be applied.
    Privileges []string
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    Role string
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    Schema string
    The database schema to set default privileges for this role.
    WithGrantOption bool
    Permit the grant recipient to grant it to others
    database String
    The database to grant default privileges for this role.
    objectType String
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    owner String
    Specifies the role that creates objects for which the default privileges will be applied.
    privileges List<String>
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    role String
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    schema String
    The database schema to set default privileges for this role.
    withGrantOption Boolean
    Permit the grant recipient to grant it to others
    database string
    The database to grant default privileges for this role.
    objectType string
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    owner string
    Specifies the role that creates objects for which the default privileges will be applied.
    privileges string[]
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    role string
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    schema string
    The database schema to set default privileges for this role.
    withGrantOption boolean
    Permit the grant recipient to grant it to others
    database str
    The database to grant default privileges for this role.
    object_type str
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    owner str
    Specifies the role that creates objects for which the default privileges will be applied.
    privileges Sequence[str]
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    role str
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    schema str
    The database schema to set default privileges for this role.
    with_grant_option bool
    Permit the grant recipient to grant it to others
    database String
    The database to grant default privileges for this role.
    objectType String
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    owner String
    Specifies the role that creates objects for which the default privileges will be applied.
    privileges List<String>
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    role String
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    schema String
    The database schema to set default privileges for this role.
    withGrantOption Boolean
    Permit the grant recipient to grant it to others

    Outputs

    All input properties are implicitly available as output properties. Additionally, the DefaultPrivileg 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 DefaultPrivileg Resource

    Get an existing DefaultPrivileg 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?: DefaultPrivilegState, opts?: CustomResourceOptions): DefaultPrivileg
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            database: Optional[str] = None,
            object_type: Optional[str] = None,
            owner: Optional[str] = None,
            privileges: Optional[Sequence[str]] = None,
            role: Optional[str] = None,
            schema: Optional[str] = None,
            with_grant_option: Optional[bool] = None) -> DefaultPrivileg
    func GetDefaultPrivileg(ctx *Context, name string, id IDInput, state *DefaultPrivilegState, opts ...ResourceOption) (*DefaultPrivileg, error)
    public static DefaultPrivileg Get(string name, Input<string> id, DefaultPrivilegState? state, CustomResourceOptions? opts = null)
    public static DefaultPrivileg get(String name, Output<String> id, DefaultPrivilegState 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.
    The following state arguments are supported:
    Database string
    The database to grant default privileges for this role.
    ObjectType string
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    Owner string
    Specifies the role that creates objects for which the default privileges will be applied.
    Privileges List<string>
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    Role string
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    Schema string
    The database schema to set default privileges for this role.
    WithGrantOption bool
    Permit the grant recipient to grant it to others
    Database string
    The database to grant default privileges for this role.
    ObjectType string
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    Owner string
    Specifies the role that creates objects for which the default privileges will be applied.
    Privileges []string
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    Role string
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    Schema string
    The database schema to set default privileges for this role.
    WithGrantOption bool
    Permit the grant recipient to grant it to others
    database String
    The database to grant default privileges for this role.
    objectType String
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    owner String
    Specifies the role that creates objects for which the default privileges will be applied.
    privileges List<String>
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    role String
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    schema String
    The database schema to set default privileges for this role.
    withGrantOption Boolean
    Permit the grant recipient to grant it to others
    database string
    The database to grant default privileges for this role.
    objectType string
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    owner string
    Specifies the role that creates objects for which the default privileges will be applied.
    privileges string[]
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    role string
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    schema string
    The database schema to set default privileges for this role.
    withGrantOption boolean
    Permit the grant recipient to grant it to others
    database str
    The database to grant default privileges for this role.
    object_type str
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    owner str
    Specifies the role that creates objects for which the default privileges will be applied.
    privileges Sequence[str]
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    role str
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    schema str
    The database schema to set default privileges for this role.
    with_grant_option bool
    Permit the grant recipient to grant it to others
    database String
    The database to grant default privileges for this role.
    objectType String
    The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
    owner String
    Specifies the role that creates objects for which the default privileges will be applied.
    privileges List<String>
    List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.
    role String
    The role that will automatically be granted the specified privileges on new objects created by the owner.
    schema String
    The database schema to set default privileges for this role.
    withGrantOption Boolean
    Permit the grant recipient to grant it to others

    Package Details

    Repository
    PostgreSQL pulumi/pulumi-postgresql
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the postgresql Terraform Provider.
    postgresql logo
    PostgreSQL v3.14.0 published on Friday, Dec 6, 2024 by Pulumi