SecretVersion class
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
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.secretsmanager.SecretVersion("example", {
secretId: exampleAwsSecretsmanagerSecret.id,
secretString: "example-string-to-protect",
});
import pulumi
import pulumi_aws as aws
example = aws.secretsmanager.SecretVersion("example",
secret_id=example_aws_secretsmanager_secret["id"],
secret_string="example-string-to-protect")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.SecretsManager.SecretVersion("example", new()
{
SecretId = exampleAwsSecretsmanagerSecret.Id,
SecretString = "example-string-to-protect",
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/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(exampleAwsSecretsmanagerSecret.Id),
SecretString: pulumi.String("example-string-to-protect"),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_secretsmanager_secretversion" "example" {
secret_id = exampleAwsSecretsmanagerSecret.id
secret_string = "example-string-to-protect"
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.secretsmanager.SecretVersion;
import com.pulumi.aws.secretsmanager.SecretVersionArgs;
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 example = new SecretVersion("example", SecretVersionArgs.builder()
.secretId(exampleAwsSecretsmanagerSecret.id())
.secretString("example-string-to-protect")
.build());
}
}
resources:
example:
type: aws:secretsmanager:SecretVersion
properties:
secretId: ${exampleAwsSecretsmanagerSecret.id}
secretString: example-string-to-protect
Key-Value Pairs
Secrets Manager also accepts key-value pairs in JSON.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const config = new pulumi.Config();
const example = config.getObject<Record<string, string>>("example") || {
key1: "value1",
key2: "value2",
};
const exampleSecretVersion = new aws.secretsmanager.SecretVersion("example", {
secretId: exampleAwsSecretsmanagerSecret.id,
secretString: JSON.stringify(example),
});
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("example",
secret_id=example_aws_secretsmanager_secret["id"],
secret_string=json.dumps(example))
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var config = new Config();
var example = config.GetObject<Dictionary<string, string>>("example") ??
{
{ "key1", "value1" },
{ "key2", "value2" },
};
var exampleSecretVersion = new Aws.SecretsManager.SecretVersion("example", new()
{
SecretId = exampleAwsSecretsmanagerSecret.Id,
SecretString = JsonSerializer.Serialize(example),
});
});
package main
import (
"encoding/json"
"github.com/pulumi/pulumi-aws/sdk/v7/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]string{
"key1": "value1",
"key2": "value2",
}
if param := cfg.GetObject("example"); param != nil {
example = param
}
tmpJSON0, err := json.Marshal(example)
if err != nil {
return err
}
json0 := string(tmpJSON0)
_, err = secretsmanager.NewSecretVersion(ctx, "example", &secretsmanager.SecretVersionArgs{
SecretId: pulumi.Any(exampleAwsSecretsmanagerSecret.Id),
SecretString: pulumi.String(json0),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_secretsmanager_secretversion" "example" {
secret_id = exampleAwsSecretsmanagerSecret.id
secret_string = jsonencode(var.example)
}
# The map here can come from other supported configurations
# like locals, resource attribute, map() built-in, etc.
variable "example" {
type = map(optional(string))
default = {
"key1" = "value1"
"key2" = "value2"
}
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.secretsmanager.SecretVersion;
import com.pulumi.aws.secretsmanager.SecretVersionArgs;
import static com.pulumi.codegen.internal.Serialization.*;
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) {
final var config = ctx.config();
final var example = config.get("example").orElse(Map.ofEntries(
Map.entry("key1", "value1"),
Map.entry("key2", "value2")
));
var exampleSecretVersion = new SecretVersion("exampleSecretVersion", SecretVersionArgs.builder()
.secretId(exampleAwsSecretsmanagerSecret.id())
.secretString(serializeJson(
example))
.build());
}
}
configuration:
# The map here can come from other supported configurations
# like locals, resource attribute, map() built-in, etc.
example:
type: object
default:
key1: value1
key2: value2
resources:
exampleSecretVersion:
type: aws:secretsmanager:SecretVersion
name: example
properties:
secretId: ${exampleAwsSecretsmanagerSecret.id}
secretString:
fn::toJSON: ${example}
Reading key-value pairs from JSON back into a native map
import * as pulumi from "@pulumi/pulumi";
import * as std from "@pulumi/std";
export const example = std.jsondecode({
input: exampleAwsSecretsmanagerSecretVersion.secretString,
}).then(invoke => invoke.result?.key1);
import pulumi
import pulumi_std as std
pulumi.export("example", std.jsondecode(input=example_aws_secretsmanager_secret_version["secretString"]).result["key1"])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
return new Dictionary<string, object?>
{
["example"] = Std.Jsondecode.Invoke(new()
{
Input = exampleAwsSecretsmanagerSecretVersion.SecretString,
}).Apply(invoke => invoke.Result?.Key1),
};
});
package main
import (
"github.com/pulumi/pulumi-std/sdk/go/std"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
ctx.Export("example", pulumi.Any(std.Jsondecode(ctx, &std.JsondecodeArgs{
Input: exampleAwsSecretsmanagerSecretVersion.SecretString,
}, nil).Result.Key1))
return nil
})
}
pulumi {
required_providers {
std = {
source = "pulumi/std"
}
}
}
output "example" {
value = jsondecode(exampleAwsSecretsmanagerSecretVersion.secretString)["key1"]
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.JsondecodeArgs;
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) {
ctx.export("example", StdFunctions.jsondecode(JsondecodeArgs.builder()
.input(exampleAwsSecretsmanagerSecretVersion.secretString())
.build()).result().key1());
}
}
outputs:
example:
fn::invoke:
function: std:jsondecode
arguments:
input: ${exampleAwsSecretsmanagerSecretVersion.secretString}
return: result.key1
Import
Identity Schema
Required
secretId- (String) ID of the secret.versionId- (String) ID of the secret version.
Optional
accountId(String) AWS Account where this resource is managed.region(String) Region where this resource is managed.
Using pulumi import, import aws.secretsmanager.SecretVersion using the secret ID and version ID. For example:
$ pulumi import aws:secretsmanager/secretVersion:SecretVersion example 'arn:aws:secretsmanager:us-east-1:123456789012:secret:example-123456|xxxxx-xxxxxxx-xxxxxxx-xxxxx'
Constructors
- SecretVersion(String name, {SecretVersionArgs? args, CustomResourceOptions? options})
-
Creates a new SecretVersion.
nameThe Pulumi resource name.argsArguments used to configure this SecretVersion. The set of arguments for SecretVersion.optionsResource options controlling this resource's behavior. - SecretVersion.reference(String urn)
- Creates a typed reference to an existing SecretVersion resource.
Properties
-
arn
↔ Output<
String> -
(Deprecated) ARN of the secret. Use
secretArninstead.latefinal -
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
hasSecretStringWo
↔ Output<
bool> -
Whether a write-only secret string value is set.
latefinal
-
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
-
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
secretArn
↔ Output<
String> -
ARN of the secret.
latefinal
-
secretBinary
↔ Output<
String?> -
Binary data that you want to encrypt and store in this version of the secret. This is required if
secretStringorsecretStringWois not set. Needs to be encoded to base64.latefinal -
secretId
↔ Output<
String> -
Secret to which you want to add a new version. You can specify either the ARN or the friendly name of the secret. The secret must already exist.
latefinal
-
secretString
↔ Output<
String?> -
Text data that you want to encrypt and store in this version of the secret. This is required if
secretBinaryorsecretStringWois not set.latefinal -
secretStringWo
↔ Output<
String?> -
NOTE: This field is write-only and its value will not be updated in state as part of read operations.
Text data that you want to encrypt and store in this version of the secret. This is required if
secretBinaryorsecretStringis not set.latefinal -
secretStringWoVersion
↔ Output<
int?> -
Version identifier that works together with
secretStringWoto trigger an update. Increment this value when an update tosecretStringWois required.latefinal -
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
-
versionId
↔ Output<
String> -
Unique identifier of the version of the secret.
latefinal
-
versionStages
↔ Output<
List< String> > -
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
AWSCURRENTto this new version on creation.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, {SecretVersionState? state, CustomResourceOptions? options}) → SecretVersion -
Gets an existing SecretVersion resource's state with the given
nameandid.