Grant class
The postgresql.Grant resource creates and manages privileges given to a user for a database schema.
> Note: This resource needs Postgresql version 9 or above. > Note: Using column & table grants on the same table with the same privileges can lead to unexpected behaviours.
Usage
import * as pulumi from "@pulumi/pulumi";
import * as postgresql from "@pulumi/postgresql";
// Grant SELECT privileges on 2 tables
const readonlyTables = new postgresql.Grant("readonly_tables", {
database: "test_db",
role: "test_role",
schema: "public",
objectType: "table",
objects: [
"table1",
"table2",
],
privileges: ["SELECT"],
});
// Grant SELECT & INSERT privileges on 2 columns in 1 table
const readInsertColumn = new postgresql.Grant("read_insert_column", {
database: "test_db",
role: "test_role",
schema: "public",
objectType: "column",
objects: ["table1"],
columns: [
"col1",
"col2",
],
privileges: [
"UPDATE",
"INSERT",
],
});
import pulumi
import pulumi_postgresql as postgresql
# Grant SELECT privileges on 2 tables
readonly_tables = postgresql.Grant("readonly_tables",
database="test_db",
role="test_role",
schema="public",
object_type="table",
objects=[
"table1",
"table2",
],
privileges=["SELECT"])
# Grant SELECT & INSERT privileges on 2 columns in 1 table
read_insert_column = postgresql.Grant("read_insert_column",
database="test_db",
role="test_role",
schema="public",
object_type="column",
objects=["table1"],
columns=[
"col1",
"col2",
],
privileges=[
"UPDATE",
"INSERT",
])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using PostgreSql = Pulumi.PostgreSql;
return await Deployment.RunAsync(() =>
{
// Grant SELECT privileges on 2 tables
var readonlyTables = new PostgreSql.Grant("readonly_tables", new()
{
Database = "test_db",
Role = "test_role",
Schema = "public",
ObjectType = "table",
Objects = new[]
{
"table1",
"table2",
},
Privileges = new[]
{
"SELECT",
},
});
// Grant SELECT & INSERT privileges on 2 columns in 1 table
var readInsertColumn = new PostgreSql.Grant("read_insert_column", new()
{
Database = "test_db",
Role = "test_role",
Schema = "public",
ObjectType = "column",
Objects = new[]
{
"table1",
},
Columns = new[]
{
"col1",
"col2",
},
Privileges = new[]
{
"UPDATE",
"INSERT",
},
});
});
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 {
// Grant SELECT privileges on 2 tables
_, err := postgresql.NewGrant(ctx, "readonly_tables", &postgresql.GrantArgs{
Database: pulumi.String("test_db"),
Role: pulumi.String("test_role"),
Schema: pulumi.String("public"),
ObjectType: pulumi.String("table"),
Objects: pulumi.StringArray{
pulumi.String("table1"),
pulumi.String("table2"),
},
Privileges: pulumi.StringArray{
pulumi.String("SELECT"),
},
})
if err != nil {
return err
}
// Grant SELECT & INSERT privileges on 2 columns in 1 table
_, err = postgresql.NewGrant(ctx, "read_insert_column", &postgresql.GrantArgs{
Database: pulumi.String("test_db"),
Role: pulumi.String("test_role"),
Schema: pulumi.String("public"),
ObjectType: pulumi.String("column"),
Objects: pulumi.StringArray{
pulumi.String("table1"),
},
Columns: pulumi.StringArray{
pulumi.String("col1"),
pulumi.String("col2"),
},
Privileges: pulumi.StringArray{
pulumi.String("UPDATE"),
pulumi.String("INSERT"),
},
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
postgresql = {
source = "pulumi/postgresql"
}
}
}
# Grant SELECT privileges on 2 tables
resource "postgresql_grant" "readonly_tables" {
database = "test_db"
role = "test_role"
schema = "public"
object_type = "table"
objects = ["table1", "table2"]
privileges = ["SELECT"]
}
# Grant SELECT & INSERT privileges on 2 columns in 1 table
resource "postgresql_grant" "read_insert_column" {
database = "test_db"
role = "test_role"
schema = "public"
object_type = "column"
objects = ["table1"]
columns = ["col1", "col2"]
privileges = ["UPDATE", "INSERT"]
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.postgresql.Grant;
import com.pulumi.postgresql.GrantArgs;
import java.util.ArrayList;
import java.util.Arrays;
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) {
// Grant SELECT privileges on 2 tables
var readonlyTables = new Grant("readonlyTables", GrantArgs.builder()
.database("test_db")
.role("test_role")
.schema("public")
.objectType("table")
.objects(
"table1",
"table2")
.privileges("SELECT")
.build());
// Grant SELECT & INSERT privileges on 2 columns in 1 table
var readInsertColumn = new Grant("readInsertColumn", GrantArgs.builder()
.database("test_db")
.role("test_role")
.schema("public")
.objectType("column")
.objects("table1")
.columns(
"col1",
"col2")
.privileges(
"UPDATE",
"INSERT")
.build());
}
}
resources:
# Grant SELECT privileges on 2 tables
readonlyTables:
type: postgresql:Grant
name: readonly_tables
properties:
database: test_db
role: test_role
schema: public
objectType: table
objects:
- table1
- table2
privileges:
- SELECT
# Grant SELECT & INSERT privileges on 2 columns in 1 table
readInsertColumn:
type: postgresql:Grant
name: read_insert_column
properties:
database: test_db
role: test_role
schema: public
objectType: column
objects:
- table1
columns:
- col1
- col2
privileges:
- UPDATE
- INSERT
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",
role: "public",
schema: "public",
objectType: "schema",
privileges: [],
});
import pulumi
import pulumi_postgresql as postgresql
revoke_public = postgresql.Grant("revoke_public",
database="test_db",
role="public",
schema="public",
object_type="schema",
privileges=[])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using PostgreSql = Pulumi.PostgreSql;
return await Deployment.RunAsync(() =>
{
var revokePublic = new PostgreSql.Grant("revoke_public", new()
{
Database = "test_db",
Role = "public",
Schema = "public",
ObjectType = "schema",
Privileges = new[] {},
});
});
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.NewGrant(ctx, "revoke_public", &postgresql.GrantArgs{
Database: pulumi.String("test_db"),
Role: pulumi.String("public"),
Schema: pulumi.String("public"),
ObjectType: pulumi.String("schema"),
Privileges: pulumi.StringArray{},
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
postgresql = {
source = "pulumi/postgresql"
}
}
}
resource "postgresql_grant" "revoke_public" {
database = "test_db"
role = "public"
schema = "public"
object_type = "schema"
privileges = []
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.postgresql.Grant;
import com.pulumi.postgresql.GrantArgs;
import java.util.ArrayList;
import java.util.Arrays;
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 Grant("revokePublic", GrantArgs.builder()
.database("test_db")
.role("public")
.schema("public")
.objectType("schema")
.privileges()
.build());
}
}
resources:
revokePublic:
type: postgresql:Grant
name: revoke_public
properties:
database: test_db
role: public
schema: public
objectType: schema
privileges: []
Constructors
Properties
-
childResources
→ Set<
Resource> -
finalinherited
-
columns
↔ Output<
List< String> ?> -
The columns upon which to grant the privileges. Required when
objectTypeiscolumn. You cannot specify this option if theobjectTypeis notcolumn.latefinal -
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
database
↔ Output<
String> -
The database to grant privileges on for this role.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
objects
↔ Output<
List< String> ?> -
The objects upon which to grant the privileges. An empty list (the default) means to grant permissions on all objects of the specified type. You cannot specify this option if the
objectTypeisdatabaseorschema. WhenobjectTypeiscolumn, only one value is allowed.latefinal -
objectType
↔ Output<
String> -
The PostgreSQL object type to grant the privileges on (one of: database, schema, table, sequence, function, procedure, routine, foreign_data_wrapper, foreign_server, column).
latefinal
-
privileges
↔ Output<
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.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
-
role
↔ Output<
String> -
The name of the role to grant privileges on, Set it to "public" for all roles.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
schema
↔ Output<
String?> -
The database schema to grant privileges on for this role (Required except if objectType is "database")
latefinal
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
-
withGrantOption
↔ Output<
bool?> -
Whether the recipient of these privileges can grant the same privileges to others. Defaults to false.
latefinal
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited