Ready to level-up your engineering skills? Join a Pulumi Workshop. Register Now

Grant

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

See PostgreSQL documentation

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.Grant("readonly_tables", {
    database: "test_db",
    objectType: "table",
    privileges: ["SELECT"],
    role: "test_role",
    schema: "public",
});
import pulumi
import pulumi_postgresql as postgresql

readonly_tables = postgresql.Grant("readonlyTables",
    database="test_db",
    object_type="table",
    privileges=["SELECT"],
    role="test_role",
    schema="public")
using Pulumi;
using PostgreSql = Pulumi.PostgreSql;

class MyStack : Stack
{
    public MyStack()
    {
        var readonlyTables = new PostgreSql.Grant("readonlyTables", new PostgreSql.GrantArgs
        {
            Database = "test_db",
            ObjectType = "table",
            Privileges = 
            {
                "SELECT",
            },
            Role = "test_role",
            Schema = "public",
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-postgresql/sdk/v2/go/postgresql"
	"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := postgresql.NewGrant(ctx, "readonlyTables", &postgresql.GrantArgs{
			Database:   pulumi.String("test_db"),
			ObjectType: pulumi.String("table"),
			Privileges: pulumi.StringArray{
				pulumi.String("SELECT"),
			},
			Role:   pulumi.String("test_role"),
			Schema: pulumi.String("public"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}

Examples

Revoke default accesses for public schema:

import * as pulumi from "@pulumi/pulumi";
import * as postgresql from "@pulumi/postgresql";

const revokePublic = new postgresql.Grant("revoke_public", {
    database: "test_db",
    objectType: "schema",
    privileges: [],
    role: "public",
    schema: "public",
});
import pulumi
import pulumi_postgresql as postgresql

revoke_public = postgresql.Grant("revokePublic",
    database="test_db",
    object_type="schema",
    privileges=[],
    role="public",
    schema="public")
using Pulumi;
using PostgreSql = Pulumi.PostgreSql;

class MyStack : Stack
{
    public MyStack()
    {
        var revokePublic = new PostgreSql.Grant("revokePublic", new PostgreSql.GrantArgs
        {
            Database = "test_db",
            ObjectType = "schema",
            Privileges = {},
            Role = "public",
            Schema = "public",
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-postgresql/sdk/v2/go/postgresql"
	"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := postgresql.NewGrant(ctx, "revokePublic", &postgresql.GrantArgs{
			Database:   pulumi.String("test_db"),
			ObjectType: pulumi.String("schema"),
			Privileges: []interface{}{},
			Role:       pulumi.String("public"),
			Schema:     pulumi.String("public"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}

Create a Grant Resource

new Grant(name: string, args: GrantArgs, opts?: CustomResourceOptions);
def Grant(resource_name: str, opts: Optional[ResourceOptions] = None, database: Optional[str] = None, object_type: Optional[str] = None, privileges: Optional[Sequence[str]] = None, role: Optional[str] = None, schema: Optional[str] = None, with_grant_option: Optional[bool] = None)
func NewGrant(ctx *Context, name string, args GrantArgs, opts ...ResourceOption) (*Grant, error)
public Grant(string name, GrantArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args GrantArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
opts ResourceOptions
A bag of options that control this resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args GrantArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args GrantArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

Grant Resource Properties

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

Inputs

The Grant resource accepts the following input properties:

Database string

The database to grant privileges on for this role.

ObjectType string

The PostgreSQL object type to grant the privileges on (one of: database, schema, table, sequence,function).

Privileges List<string>

The list of privileges to grant. There are different kinds of privileges: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE. An empty list could be provided to revoke all privileges for this role.

Role string

The name of the role to grant privileges on, Set it to “public” for all roles.

Schema string

The database schema to grant privileges on for this role (Required except if object_type is “database”)

WithGrantOption bool

Permit the grant recipient to grant it to others

Database string

The database to grant privileges on for this role.

ObjectType string

The PostgreSQL object type to grant the privileges on (one of: database, schema, table, sequence,function).

Privileges []string

The list of privileges to grant. There are different kinds of privileges: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE. An empty list could be provided to revoke all privileges for this role.

Role string

The name of the role to grant privileges on, Set it to “public” for all roles.

Schema string

The database schema to grant privileges on for this role (Required except if object_type is “database”)

WithGrantOption bool

Permit the grant recipient to grant it to others

database string

The database to grant privileges on for this role.

objectType string

The PostgreSQL object type to grant the privileges on (one of: database, schema, table, sequence,function).

privileges string[]

The list of privileges to grant. There are different kinds of privileges: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE. An empty list could be provided to revoke all privileges for this role.

role string

The name of the role to grant privileges on, Set it to “public” for all roles.

schema string

The database schema to grant privileges on for this role (Required except if object_type is “database”)

withGrantOption boolean

Permit the grant recipient to grant it to others

database str

The database to grant privileges on for this role.

object_type str

The PostgreSQL object type to grant the privileges on (one of: database, schema, table, sequence,function).

privileges Sequence[str]

The list of privileges to grant. There are different kinds of privileges: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE. An empty list could be provided to revoke all privileges for this role.

role str

The name of the role to grant privileges on, Set it to “public” for all roles.

schema str

The database schema to grant privileges on for this role (Required except if object_type is “database”)

with_grant_option bool

Permit the grant recipient to grant it to others

Outputs

All input properties are implicitly available as output properties. Additionally, the Grant 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 str
The provider-assigned unique ID for this managed resource.

Look up an Existing Grant Resource

Get an existing Grant 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?: GrantState, opts?: CustomResourceOptions): Grant
@staticmethod
def get(resource_name: str, id: str, opts: Optional[ResourceOptions] = None, database: Optional[str] = None, object_type: Optional[str] = None, privileges: Optional[Sequence[str]] = None, role: Optional[str] = None, schema: Optional[str] = None, with_grant_option: Optional[bool] = None) -> Grant
func GetGrant(ctx *Context, name string, id IDInput, state *GrantState, opts ...ResourceOption) (*Grant, error)
public static Grant Get(string name, Input<string> id, GrantState? state, CustomResourceOptions? opts = null)
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.

The following state arguments are supported:

Database string

The database to grant privileges on for this role.

ObjectType string

The PostgreSQL object type to grant the privileges on (one of: database, schema, table, sequence,function).

Privileges List<string>

The list of privileges to grant. There are different kinds of privileges: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE. An empty list could be provided to revoke all privileges for this role.

Role string

The name of the role to grant privileges on, Set it to “public” for all roles.

Schema string

The database schema to grant privileges on for this role (Required except if object_type is “database”)

WithGrantOption bool

Permit the grant recipient to grant it to others

Database string

The database to grant privileges on for this role.

ObjectType string

The PostgreSQL object type to grant the privileges on (one of: database, schema, table, sequence,function).

Privileges []string

The list of privileges to grant. There are different kinds of privileges: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE. An empty list could be provided to revoke all privileges for this role.

Role string

The name of the role to grant privileges on, Set it to “public” for all roles.

Schema string

The database schema to grant privileges on for this role (Required except if object_type is “database”)

WithGrantOption bool

Permit the grant recipient to grant it to others

database string

The database to grant privileges on for this role.

objectType string

The PostgreSQL object type to grant the privileges on (one of: database, schema, table, sequence,function).

privileges string[]

The list of privileges to grant. There are different kinds of privileges: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE. An empty list could be provided to revoke all privileges for this role.

role string

The name of the role to grant privileges on, Set it to “public” for all roles.

schema string

The database schema to grant privileges on for this role (Required except if object_type is “database”)

withGrantOption boolean

Permit the grant recipient to grant it to others

database str

The database to grant privileges on for this role.

object_type str

The PostgreSQL object type to grant the privileges on (one of: database, schema, table, sequence,function).

privileges Sequence[str]

The list of privileges to grant. There are different kinds of privileges: SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE. An empty list could be provided to revoke all privileges for this role.

role str

The name of the role to grant privileges on, Set it to “public” for all roles.

schema str

The database schema to grant privileges on for this role (Required except if object_type is “database”)

with_grant_option bool

Permit the grant recipient to grant it to others

Package Details

Repository
https://github.com/pulumi/pulumi-postgresql
License
Apache-2.0
Notes
This Pulumi package is based on the postgresql Terraform Provider.