AWS Classic

Pulumi Official
Package maintained by Pulumi
v5.10.0 published on Monday, Jul 11, 2022 by Pulumi

SecretVersion

Provides a resource to manage AWS Secrets Manager secret version including its secret value. To manage secret metadata, see the aws.secretsmanager.Secret resource.

NOTE: If the AWSCURRENT staging label is present on this version during resource deletion, that label cannot be removed and will be skipped to prevent errors when fully deleting the secret. That label will leave this secret version active even after the resource is deleted from this provider unless the secret itself is deleted. Move the AWSCURRENT staging label before or after deleting this resource from this provider to fully trigger version deprecation if necessary.

Example Usage

Simple String Value

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var example = new Aws.SecretsManager.SecretVersion("example", new Aws.SecretsManager.SecretVersionArgs
        {
            SecretId = aws_secretsmanager_secret.Example.Id,
            SecretString = "example-string-to-protect",
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/secretsmanager"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := secretsmanager.NewSecretVersion(ctx, "example", &secretsmanager.SecretVersionArgs{
			SecretId:     pulumi.Any(aws_secretsmanager_secret.Example.Id),
			SecretString: pulumi.String("example-string-to-protect"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var example = new SecretVersion("example", SecretVersionArgs.builder()        
            .secretId(aws_secretsmanager_secret.example().id())
            .secretString("example-string-to-protect")
            .build());

    }
}
import pulumi
import pulumi_aws as aws

example = aws.secretsmanager.SecretVersion("example",
    secret_id=aws_secretsmanager_secret["example"]["id"],
    secret_string="example-string-to-protect")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.secretsmanager.SecretVersion("example", {
    secretId: aws_secretsmanager_secret.example.id,
    secretString: "example-string-to-protect",
});
resources:
  example:
    type: aws:secretsmanager:SecretVersion
    properties:
      secretId: ${aws_secretsmanager_secret.example.id}
      secretString: example-string-to-protect

Key-Value Pairs

using System.Collections.Generic;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var config = new Config();
        var example = config.GetObject<dynamic>("example") ?? 
        {
            { "key1", "value1" },
            { "key2", "value2" },
        };
        var exampleSecretVersion = new Aws.SecretsManager.SecretVersion("exampleSecretVersion", new Aws.SecretsManager.SecretVersionArgs
        {
            SecretId = aws_secretsmanager_secret.Example.Id,
            SecretString = JsonSerializer.Serialize(example),
        });
    }

}
package main

import (
	"encoding/json"

	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/secretsmanager"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		cfg := config.New(ctx, "")
		example := map[string]interface{}{
			"key1": "value1",
			"key2": "value2",
		}
		if param := cfg.GetBool("example"); param != nil {
			example = param
		}
		tmpJSON0, err := json.Marshal(example)
		if err != nil {
			return err
		}
		json0 := string(tmpJSON0)
		_, err := secretsmanager.NewSecretVersion(ctx, "exampleSecretVersion", &secretsmanager.SecretVersionArgs{
			SecretId:     pulumi.Any(aws_secretsmanager_secret.Example.Id),
			SecretString: pulumi.String(json0),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;
import static com.pulumi.codegen.internal.Serialization.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var config = ctx.config();
        final var example = config.get("example").orElse(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference));
        var exampleSecretVersion = new SecretVersion("exampleSecretVersion", SecretVersionArgs.builder()        
            .secretId(aws_secretsmanager_secret.example().id())
            .secretString(serializeJson(
                example))
            .build());

    }
}
import pulumi
import json
import pulumi_aws as aws

config = pulumi.Config()
example = config.get_object("example")
if example is None:
    example = {
        "key1": "value1",
        "key2": "value2",
    }
example_secret_version = aws.secretsmanager.SecretVersion("exampleSecretVersion",
    secret_id=aws_secretsmanager_secret["example"]["id"],
    secret_string=json.dumps(example))
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const config = new pulumi.Config();
const example = config.getObject("example") || {
    key1: "value1",
    key2: "value2",
};
const exampleSecretVersion = new aws.secretsmanager.SecretVersion("exampleSecretVersion", {
    secretId: aws_secretsmanager_secret.example.id,
    secretString: JSON.stringify(example),
});
configuration:
  example:
    type: map(string)
    default:
      key1: value1
      key2: value2
resources:
  exampleSecretVersion:
    type: aws:secretsmanager:SecretVersion
    properties:
      secretId: ${aws_secretsmanager_secret.example.id}
      secretString:
        Fn::ToJSON: ${example}

Create a SecretVersion Resource

new SecretVersion(name: string, args: SecretVersionArgs, opts?: CustomResourceOptions);
@overload
def SecretVersion(resource_name: str,
                  opts: Optional[ResourceOptions] = None,
                  secret_binary: Optional[str] = None,
                  secret_id: Optional[str] = None,
                  secret_string: Optional[str] = None,
                  version_stages: Optional[Sequence[str]] = None)
@overload
def SecretVersion(resource_name: str,
                  args: SecretVersionArgs,
                  opts: Optional[ResourceOptions] = None)
func NewSecretVersion(ctx *Context, name string, args SecretVersionArgs, opts ...ResourceOption) (*SecretVersion, error)
public SecretVersion(string name, SecretVersionArgs args, CustomResourceOptions? opts = null)
public SecretVersion(String name, SecretVersionArgs args)
public SecretVersion(String name, SecretVersionArgs args, CustomResourceOptions options)
type: aws:secretsmanager:SecretVersion
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args SecretVersionArgs
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 SecretVersionArgs
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 SecretVersionArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args SecretVersionArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args SecretVersionArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

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

SecretId string

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

SecretBinary string

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

SecretString string

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

VersionStages List<string>

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

SecretId string

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

SecretBinary string

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

SecretString string

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

VersionStages []string

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

secretId String

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

secretBinary String

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

secretString String

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

versionStages List<String>

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

secretId string

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

secretBinary string

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

secretString string

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

versionStages string[]

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

secret_id str

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

secret_binary str

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

secret_string str

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

version_stages Sequence[str]

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

secretId String

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

secretBinary String

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

secretString String

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

versionStages List<String>

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

Outputs

All input properties are implicitly available as output properties. Additionally, the SecretVersion resource produces the following output properties:

Arn string

The ARN of the secret.

Id string

The provider-assigned unique ID for this managed resource.

VersionId string

The unique identifier of the version of the secret.

Arn string

The ARN of the secret.

Id string

The provider-assigned unique ID for this managed resource.

VersionId string

The unique identifier of the version of the secret.

arn String

The ARN of the secret.

id String

The provider-assigned unique ID for this managed resource.

versionId String

The unique identifier of the version of the secret.

arn string

The ARN of the secret.

id string

The provider-assigned unique ID for this managed resource.

versionId string

The unique identifier of the version of the secret.

arn str

The ARN of the secret.

id str

The provider-assigned unique ID for this managed resource.

version_id str

The unique identifier of the version of the secret.

arn String

The ARN of the secret.

id String

The provider-assigned unique ID for this managed resource.

versionId String

The unique identifier of the version of the secret.

Look up an Existing SecretVersion Resource

Get an existing SecretVersion 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?: SecretVersionState, opts?: CustomResourceOptions): SecretVersion
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        arn: Optional[str] = None,
        secret_binary: Optional[str] = None,
        secret_id: Optional[str] = None,
        secret_string: Optional[str] = None,
        version_id: Optional[str] = None,
        version_stages: Optional[Sequence[str]] = None) -> SecretVersion
func GetSecretVersion(ctx *Context, name string, id IDInput, state *SecretVersionState, opts ...ResourceOption) (*SecretVersion, error)
public static SecretVersion Get(string name, Input<string> id, SecretVersionState? state, CustomResourceOptions? opts = null)
public static SecretVersion get(String name, Output<String> id, SecretVersionState 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:
Arn string

The ARN of the secret.

SecretBinary string

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

SecretId string

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

SecretString string

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

VersionId string

The unique identifier of the version of the secret.

VersionStages List<string>

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

Arn string

The ARN of the secret.

SecretBinary string

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

SecretId string

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

SecretString string

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

VersionId string

The unique identifier of the version of the secret.

VersionStages []string

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

arn String

The ARN of the secret.

secretBinary String

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

secretId String

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

secretString String

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

versionId String

The unique identifier of the version of the secret.

versionStages List<String>

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

arn string

The ARN of the secret.

secretBinary string

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

secretId string

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

secretString string

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

versionId string

The unique identifier of the version of the secret.

versionStages string[]

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

arn str

The ARN of the secret.

secret_binary str

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

secret_id str

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

secret_string str

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

version_id str

The unique identifier of the version of the secret.

version_stages Sequence[str]

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

arn String

The ARN of the secret.

secretBinary String

Specifies binary data that you want to encrypt and store in this version of the secret. This is required if secret_string is not set. Needs to be encoded to base64.

secretId String

Specifies the secret to which you want to add a new version. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret. The secret must already exist.

secretString String

Specifies text data that you want to encrypt and store in this version of the secret. This is required if secret_binary is not set.

versionId String

The unique identifier of the version of the secret.

versionStages List<String>

Specifies a list of staging labels that are attached to this version of the secret. A staging label must be unique to a single version of the secret. If you specify a staging label that's already associated with a different version of the same secret then that staging label is automatically removed from the other version and attached to this version. If you do not specify a value, then AWS Secrets Manager automatically moves the staging label AWSCURRENT to this new version on creation.

Import

aws_secretsmanager_secret_version can be imported by using the secret ID and version ID, e.g.,

 $ pulumi import aws:secretsmanager/secretVersion:SecretVersion example 'arn:aws:secretsmanager:us-east-1:123456789012:secret:example-123456|xxxxx-xxxxxxx-xxxxxxx-xxxxx'

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes

This Pulumi package is based on the aws Terraform Provider.