1. Packages
  2. PostgreSQL
  3. API Docs
  4. UserMapping
PostgreSQL v3.11.0 published on Sunday, Mar 3, 2024 by Pulumi

postgresql.UserMapping

Explore with Pulumi AI

postgresql logo
PostgreSQL v3.11.0 published on Sunday, Mar 3, 2024 by Pulumi

    The postgresql.UserMapping resource creates and manages a user mapping on a PostgreSQL server.

    Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as postgresql from "@pulumi/postgresql";
    
    const extPostgresFdw = new postgresql.Extension("extPostgresFdw", {});
    const myserverPostgres = new postgresql.Server("myserverPostgres", {
        serverName: "myserver_postgres",
        fdwName: "postgres_fdw",
        options: {
            host: "foo",
            dbname: "foodb",
            port: "5432",
        },
    }, {
        dependsOn: [extPostgresFdw],
    });
    const remoteRole = new postgresql.Role("remoteRole", {});
    const remoteUserMapping = new postgresql.UserMapping("remoteUserMapping", {
        serverName: myserverPostgres.serverName,
        userName: remoteRole.name,
        options: {
            user: "admin",
            password: "pass",
        },
    });
    
    import pulumi
    import pulumi_postgresql as postgresql
    
    ext_postgres_fdw = postgresql.Extension("extPostgresFdw")
    myserver_postgres = postgresql.Server("myserverPostgres",
        server_name="myserver_postgres",
        fdw_name="postgres_fdw",
        options={
            "host": "foo",
            "dbname": "foodb",
            "port": "5432",
        },
        opts=pulumi.ResourceOptions(depends_on=[ext_postgres_fdw]))
    remote_role = postgresql.Role("remoteRole")
    remote_user_mapping = postgresql.UserMapping("remoteUserMapping",
        server_name=myserver_postgres.server_name,
        user_name=remote_role.name,
        options={
            "user": "admin",
            "password": "pass",
        })
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using PostgreSql = Pulumi.PostgreSql;
    
    return await Deployment.RunAsync(() => 
    {
        var extPostgresFdw = new PostgreSql.Extension("extPostgresFdw");
    
        var myserverPostgres = new PostgreSql.Server("myserverPostgres", new()
        {
            ServerName = "myserver_postgres",
            FdwName = "postgres_fdw",
            Options = 
            {
                { "host", "foo" },
                { "dbname", "foodb" },
                { "port", "5432" },
            },
        }, new CustomResourceOptions
        {
            DependsOn = new[]
            {
                extPostgresFdw,
            },
        });
    
        var remoteRole = new PostgreSql.Role("remoteRole");
    
        var remoteUserMapping = new PostgreSql.UserMapping("remoteUserMapping", new()
        {
            ServerName = myserverPostgres.ServerName,
            UserName = remoteRole.Name,
            Options = 
            {
                { "user", "admin" },
                { "password", "pass" },
            },
        });
    
    });
    
    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 {
    		extPostgresFdw, err := postgresql.NewExtension(ctx, "extPostgresFdw", nil)
    		if err != nil {
    			return err
    		}
    		myserverPostgres, err := postgresql.NewServer(ctx, "myserverPostgres", &postgresql.ServerArgs{
    			ServerName: pulumi.String("myserver_postgres"),
    			FdwName:    pulumi.String("postgres_fdw"),
    			Options: pulumi.StringMap{
    				"host":   pulumi.String("foo"),
    				"dbname": pulumi.String("foodb"),
    				"port":   pulumi.String("5432"),
    			},
    		}, pulumi.DependsOn([]pulumi.Resource{
    			extPostgresFdw,
    		}))
    		if err != nil {
    			return err
    		}
    		remoteRole, err := postgresql.NewRole(ctx, "remoteRole", nil)
    		if err != nil {
    			return err
    		}
    		_, err = postgresql.NewUserMapping(ctx, "remoteUserMapping", &postgresql.UserMappingArgs{
    			ServerName: myserverPostgres.ServerName,
    			UserName:   remoteRole.Name,
    			Options: pulumi.StringMap{
    				"user":     pulumi.String("admin"),
    				"password": pulumi.String("pass"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.postgresql.Extension;
    import com.pulumi.postgresql.Server;
    import com.pulumi.postgresql.ServerArgs;
    import com.pulumi.postgresql.Role;
    import com.pulumi.postgresql.UserMapping;
    import com.pulumi.postgresql.UserMappingArgs;
    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 extPostgresFdw = new Extension("extPostgresFdw");
    
            var myserverPostgres = new Server("myserverPostgres", ServerArgs.builder()        
                .serverName("myserver_postgres")
                .fdwName("postgres_fdw")
                .options(Map.ofEntries(
                    Map.entry("host", "foo"),
                    Map.entry("dbname", "foodb"),
                    Map.entry("port", "5432")
                ))
                .build(), CustomResourceOptions.builder()
                    .dependsOn(extPostgresFdw)
                    .build());
    
            var remoteRole = new Role("remoteRole");
    
            var remoteUserMapping = new UserMapping("remoteUserMapping", UserMappingArgs.builder()        
                .serverName(myserverPostgres.serverName())
                .userName(remoteRole.name())
                .options(Map.ofEntries(
                    Map.entry("user", "admin"),
                    Map.entry("password", "pass")
                ))
                .build());
    
        }
    }
    
    resources:
      extPostgresFdw:
        type: postgresql:Extension
      myserverPostgres:
        type: postgresql:Server
        properties:
          serverName: myserver_postgres
          fdwName: postgres_fdw
          options:
            host: foo
            dbname: foodb
            port: '5432'
        options:
          dependson:
            - ${extPostgresFdw}
      remoteRole:
        type: postgresql:Role
      remoteUserMapping:
        type: postgresql:UserMapping
        properties:
          serverName: ${myserverPostgres.serverName}
          userName: ${remoteRole.name}
          options:
            user: admin
            password: pass
    

    Create UserMapping Resource

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

    Constructor syntax

    new UserMapping(name: string, args: UserMappingArgs, opts?: CustomResourceOptions);
    @overload
    def UserMapping(resource_name: str,
                    args: UserMappingArgs,
                    opts: Optional[ResourceOptions] = None)
    
    @overload
    def UserMapping(resource_name: str,
                    opts: Optional[ResourceOptions] = None,
                    server_name: Optional[str] = None,
                    user_name: Optional[str] = None,
                    options: Optional[Mapping[str, str]] = None)
    func NewUserMapping(ctx *Context, name string, args UserMappingArgs, opts ...ResourceOption) (*UserMapping, error)
    public UserMapping(string name, UserMappingArgs args, CustomResourceOptions? opts = null)
    public UserMapping(String name, UserMappingArgs args)
    public UserMapping(String name, UserMappingArgs args, CustomResourceOptions options)
    
    type: postgresql:UserMapping
    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 UserMappingArgs
    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 UserMappingArgs
    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 UserMappingArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args UserMappingArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args UserMappingArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Example

    The following reference example uses placeholder values for all input properties.

    var userMappingResource = new PostgreSql.UserMapping("userMappingResource", new()
    {
        ServerName = "string",
        UserName = "string",
        Options = 
        {
            { "string", "string" },
        },
    });
    
    example, err := postgresql.NewUserMapping(ctx, "userMappingResource", &postgresql.UserMappingArgs{
    	ServerName: pulumi.String("string"),
    	UserName:   pulumi.String("string"),
    	Options: pulumi.StringMap{
    		"string": pulumi.String("string"),
    	},
    })
    
    var userMappingResource = new UserMapping("userMappingResource", UserMappingArgs.builder()        
        .serverName("string")
        .userName("string")
        .options(Map.of("string", "string"))
        .build());
    
    user_mapping_resource = postgresql.UserMapping("userMappingResource",
        server_name="string",
        user_name="string",
        options={
            "string": "string",
        })
    
    const userMappingResource = new postgresql.UserMapping("userMappingResource", {
        serverName: "string",
        userName: "string",
        options: {
            string: "string",
        },
    });
    
    type: postgresql:UserMapping
    properties:
        options:
            string: string
        serverName: string
        userName: string
    

    UserMapping Resource Properties

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

    Inputs

    The UserMapping resource accepts the following input properties:

    ServerName string
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    UserName string
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    Options Dictionary<string, string>
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    ServerName string
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    UserName string
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    Options map[string]string
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    serverName String
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    userName String
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    options Map<String,String>
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    serverName string
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    userName string
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    options {[key: string]: string}
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    server_name str
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    user_name str
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    options Mapping[str, str]
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    serverName String
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    userName String
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    options Map<String>
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.

    Outputs

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

    Get an existing UserMapping 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?: UserMappingState, opts?: CustomResourceOptions): UserMapping
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            options: Optional[Mapping[str, str]] = None,
            server_name: Optional[str] = None,
            user_name: Optional[str] = None) -> UserMapping
    func GetUserMapping(ctx *Context, name string, id IDInput, state *UserMappingState, opts ...ResourceOption) (*UserMapping, error)
    public static UserMapping Get(string name, Input<string> id, UserMappingState? state, CustomResourceOptions? opts = null)
    public static UserMapping get(String name, Output<String> id, UserMappingState 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:
    Options Dictionary<string, string>
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    ServerName string
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    UserName string
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    Options map[string]string
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    ServerName string
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    UserName string
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    options Map<String,String>
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    serverName String
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    userName String
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    options {[key: string]: string}
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    serverName string
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    userName string
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    options Mapping[str, str]
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    server_name str
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    user_name str
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    options Map<String>
    This clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.
    serverName String
    The name of an existing server for which the user mapping is to be created. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.
    userName String
    The name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Changing this value will force the creation of a new resource as this value can only be set when the user mapping is created.

    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.11.0 published on Sunday, Mar 3, 2024 by Pulumi