HashiCorp Vault

v5.0.0 published on Tuesday, Nov 30, 2021 by Pulumi

SecretBackendStaticRole

Creates a Database Secret Backend static role in Vault. Database secret backend static roles can be used to manage 1-to-1 mapping of a Vault Role to a user in a database for the database.

Example Usage

using Pulumi;
using Vault = Pulumi.Vault;

class MyStack : Stack
{
    public MyStack()
    {
        var db = new Vault.Mount("db", new Vault.MountArgs
        {
            Path = "postgres",
            Type = "database",
        });
        var postgres = new Vault.Database.SecretBackendConnection("postgres", new Vault.Database.SecretBackendConnectionArgs
        {
            Backend = db.Path,
            AllowedRoles = 
            {
                "*",
            },
            Postgresql = new Vault.Database.Inputs.SecretBackendConnectionPostgresqlArgs
            {
                ConnectionUrl = "postgres://username:password@host:port/database",
            },
        });
        var staticRole = new Vault.Database.SecretBackendStaticRole("staticRole", new Vault.Database.SecretBackendStaticRoleArgs
        {
            Backend = db.Path,
            DbName = postgres.Name,
            Username = "example",
            RotationPeriod = 3600,
            RotationStatements = 
            {
                "ALTER USER \"{{name}}\" WITH PASSWORD '{{password}}';",
            },
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-vault/sdk/v5/go/vault"
	"github.com/pulumi/pulumi-vault/sdk/v5/go/vault/database"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		db, err := vault.NewMount(ctx, "db", &vault.MountArgs{
			Path: pulumi.String("postgres"),
			Type: pulumi.String("database"),
		})
		if err != nil {
			return err
		}
		postgres, err := database.NewSecretBackendConnection(ctx, "postgres", &database.SecretBackendConnectionArgs{
			Backend: db.Path,
			AllowedRoles: pulumi.StringArray{
				pulumi.String("*"),
			},
			Postgresql: &database.SecretBackendConnectionPostgresqlArgs{
				ConnectionUrl: pulumi.String("postgres://username:password@host:port/database"),
			},
		})
		if err != nil {
			return err
		}
		_, err = database.NewSecretBackendStaticRole(ctx, "staticRole", &database.SecretBackendStaticRoleArgs{
			Backend:        db.Path,
			DbName:         postgres.Name,
			Username:       pulumi.String("example"),
			RotationPeriod: pulumi.Int(3600),
			RotationStatements: pulumi.StringArray{
				pulumi.String("ALTER USER \"{{name}}\" WITH PASSWORD '{{password}}';"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_vault as vault

db = vault.Mount("db",
    path="postgres",
    type="database")
postgres = vault.database.SecretBackendConnection("postgres",
    backend=db.path,
    allowed_roles=["*"],
    postgresql=vault.database.SecretBackendConnectionPostgresqlArgs(
        connection_url="postgres://username:password@host:port/database",
    ))
static_role = vault.database.SecretBackendStaticRole("staticRole",
    backend=db.path,
    db_name=postgres.name,
    username="example",
    rotation_period=3600,
    rotation_statements=["ALTER USER \"{{name}}\" WITH PASSWORD '{{password}}';"])
import * as pulumi from "@pulumi/pulumi";
import * as vault from "@pulumi/vault";

const db = new vault.Mount("db", {
    path: "postgres",
    type: "database",
});
const postgres = new vault.database.SecretBackendConnection("postgres", {
    backend: db.path,
    allowedRoles: ["*"],
    postgresql: {
        connectionUrl: "postgres://username:password@host:port/database",
    },
});
const staticRole = new vault.database.SecretBackendStaticRole("staticRole", {
    backend: db.path,
    dbName: postgres.name,
    username: "example",
    rotationPeriod: "3600",
    rotationStatements: ["ALTER USER \"{{name}}\" WITH PASSWORD '{{password}}';"],
});

Create a SecretBackendStaticRole Resource

new SecretBackendStaticRole(name: string, args: SecretBackendStaticRoleArgs, opts?: CustomResourceOptions);
@overload
def SecretBackendStaticRole(resource_name: str,
                            opts: Optional[ResourceOptions] = None,
                            backend: Optional[str] = None,
                            db_name: Optional[str] = None,
                            name: Optional[str] = None,
                            rotation_period: Optional[int] = None,
                            rotation_statements: Optional[Sequence[str]] = None,
                            username: Optional[str] = None)
@overload
def SecretBackendStaticRole(resource_name: str,
                            args: SecretBackendStaticRoleArgs,
                            opts: Optional[ResourceOptions] = None)
func NewSecretBackendStaticRole(ctx *Context, name string, args SecretBackendStaticRoleArgs, opts ...ResourceOption) (*SecretBackendStaticRole, error)
public SecretBackendStaticRole(string name, SecretBackendStaticRoleArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args SecretBackendStaticRoleArgs
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 SecretBackendStaticRoleArgs
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 SecretBackendStaticRoleArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args SecretBackendStaticRoleArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

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

Backend string
The unique name of the Vault mount to configure.
DbName string
The unique name of the database connection to use for the static role.
RotationPeriod int
The amount of time Vault should wait before rotating the password, in seconds.
Username string
The database username that this static role corresponds to.
Name string
A unique name to give the static role.
RotationStatements List<string>
Database statements to execute to rotate the password for the configured database user.
Backend string
The unique name of the Vault mount to configure.
DbName string
The unique name of the database connection to use for the static role.
RotationPeriod int
The amount of time Vault should wait before rotating the password, in seconds.
Username string
The database username that this static role corresponds to.
Name string
A unique name to give the static role.
RotationStatements []string
Database statements to execute to rotate the password for the configured database user.
backend string
The unique name of the Vault mount to configure.
dbName string
The unique name of the database connection to use for the static role.
rotationPeriod number
The amount of time Vault should wait before rotating the password, in seconds.
username string
The database username that this static role corresponds to.
name string
A unique name to give the static role.
rotationStatements string[]
Database statements to execute to rotate the password for the configured database user.
backend str
The unique name of the Vault mount to configure.
db_name str
The unique name of the database connection to use for the static role.
rotation_period int
The amount of time Vault should wait before rotating the password, in seconds.
username str
The database username that this static role corresponds to.
name str
A unique name to give the static role.
rotation_statements Sequence[str]
Database statements to execute to rotate the password for the configured database user.

Outputs

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

Get an existing SecretBackendStaticRole 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?: SecretBackendStaticRoleState, opts?: CustomResourceOptions): SecretBackendStaticRole
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        backend: Optional[str] = None,
        db_name: Optional[str] = None,
        name: Optional[str] = None,
        rotation_period: Optional[int] = None,
        rotation_statements: Optional[Sequence[str]] = None,
        username: Optional[str] = None) -> SecretBackendStaticRole
func GetSecretBackendStaticRole(ctx *Context, name string, id IDInput, state *SecretBackendStaticRoleState, opts ...ResourceOption) (*SecretBackendStaticRole, error)
public static SecretBackendStaticRole Get(string name, Input<string> id, SecretBackendStaticRoleState? 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:

Backend string
The unique name of the Vault mount to configure.
DbName string
The unique name of the database connection to use for the static role.
Name string
A unique name to give the static role.
RotationPeriod int
The amount of time Vault should wait before rotating the password, in seconds.
RotationStatements List<string>
Database statements to execute to rotate the password for the configured database user.
Username string
The database username that this static role corresponds to.
Backend string
The unique name of the Vault mount to configure.
DbName string
The unique name of the database connection to use for the static role.
Name string
A unique name to give the static role.
RotationPeriod int
The amount of time Vault should wait before rotating the password, in seconds.
RotationStatements []string
Database statements to execute to rotate the password for the configured database user.
Username string
The database username that this static role corresponds to.
backend string
The unique name of the Vault mount to configure.
dbName string
The unique name of the database connection to use for the static role.
name string
A unique name to give the static role.
rotationPeriod number
The amount of time Vault should wait before rotating the password, in seconds.
rotationStatements string[]
Database statements to execute to rotate the password for the configured database user.
username string
The database username that this static role corresponds to.
backend str
The unique name of the Vault mount to configure.
db_name str
The unique name of the database connection to use for the static role.
name str
A unique name to give the static role.
rotation_period int
The amount of time Vault should wait before rotating the password, in seconds.
rotation_statements Sequence[str]
Database statements to execute to rotate the password for the configured database user.
username str
The database username that this static role corresponds to.

Import

Database secret backend static roles can be imported using the backend, /static-roles/, and the name e.g.

 $ pulumi import vault:database/secretBackendStaticRole:SecretBackendStaticRole example postgres/static-roles/my-role

Package Details

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