DefaultPrivileges class

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"])
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 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
	})
}
pulumi {
  required_providers {
    postgresql = {
      source = "pulumi/postgresql"
    }
  }
}

resource "postgresql_defaultprivileges" "read_only_tables" {
  role        = "test_role"
  database    = "test_db"
  schema      = "public"
  owner       = "db_owner"
  object_type = "table"
  privileges  = ["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.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 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 "currentRole" 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",
    ])
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 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
	})
}
pulumi {
  required_providers {
    postgresql = {
      source = "pulumi/postgresql"
    }
  }
}

resource "postgresql_defaultprivileges" "grant_table_privileges" {
  database    = exampleDb.name
  role        = "current_role"
  owner       = "owner_role"
  schema      = "public"
  object_type = "table"
  privileges  = ["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.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 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 ownerRole creates a new table in the public schema, the currentRole 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=[])
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 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
	})
}
pulumi {
  required_providers {
    postgresql = {
      source = "pulumi/postgresql"
    }
  }
}

resource "postgresql_defaultprivileges" "revoke_public" {
  database    = exampleDb.name
  role        = "public"
  owner       = "object_owner"
  object_type = "function"
  privileges  = []
}
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.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 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: []

Constructors

DefaultPrivileges(String name, {DefaultPrivilegesArgs? args, CustomResourceOptions? options})
Creates a new DefaultPrivileges. name The Pulumi resource name. args Arguments used to configure this DefaultPrivileges. The set of arguments for DefaultPrivileges. options Resource options controlling this resource's behavior.

Properties

childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
database ↔ Output<String>
The database to grant default privileges 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
objectType ↔ Output<String>
The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, routine, type, schema).
latefinal
owner ↔ Output<String>
Specifies the role that creates objects for which the default privileges will be applied.
latefinal
privileges ↔ Output<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.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
role ↔ Output<String>
The role that will automatically be granted the specified privileges on new objects created by the owner.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
schema ↔ Output<String?>
The database schema to set default privileges for this role.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited
withGrantOption ↔ Output<bool?>
Permit the grant recipient to grant it to others
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

Static Methods

get(String name, Input<String> id, {DefaultPrivilegesState? state}) → DefaultPrivileges
Gets an existing DefaultPrivileges resource's state with the given name and id.