Class SecretVersion


  • public class SecretVersion
    extends com.pulumi.resources.CustomResource
    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. > **NOTE:** This resource manages one specific version of a secret. If something else creates newer versions, such as rotation, another Pulumi program, or the console, this resource keeps tracking its own version even after that version is no longer `AWSCURRENT`. To read the current value of a secret, use the `aws.secretsmanager.SecretVersion` data source. > **NOTE:** When a secret's KMS key changes, Secrets Manager re-encrypts only the `AWSCURRENT`, `AWSPENDING`, and `AWSPREVIOUS` versions with the new key. Once the previous key is disabled or deleted, older versions can no longer be decrypted. If this resource's version is one of them, Pulumi keeps the value from state and shows a warning, but cannot import the version or move staging labels onto it. If the version is still `AWSCURRENT` or `AWSPENDING`, reading it fails. See [Change the encryption key for a secret](https://docs.aws.amazon.com/secretsmanager/latest/userguide/manage_update-encryption-key.html). ## Example Usage ### Simple String Value
     
     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());
     
         }
     }
     
     
    ### Key-Value Pairs Secrets Manager also accepts key-value pairs in JSON.
     
     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());
     
         }
     }
     
     
    Reading key-value pairs from JSON back into a native map
     
     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());
         }
     }
     
     
    ## 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: ```sh $ pulumi import aws:secretsmanager/secretVersion:SecretVersion example 'arn:aws:secretsmanager:us-east-1:123456789012:secret:example-123456|xxxxx-xxxxxxx-xxxxxxx-xxxxx' ```
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pulumi.resources.CustomResource

        com.pulumi.resources.CustomResource.CustomResourceInternal
      • Nested classes/interfaces inherited from class com.pulumi.resources.Resource

        com.pulumi.resources.Resource.LazyField<T extends java.lang.Object>, com.pulumi.resources.Resource.LazyFields, com.pulumi.resources.Resource.ResourceInternal
    • Field Summary

      • Fields inherited from class com.pulumi.resources.Resource

        childResources, remote
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.pulumi.core.Output<java.lang.String> arn()  
      static SecretVersion get​(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, SecretVersionState state, com.pulumi.resources.CustomResourceOptions options)
      Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
      com.pulumi.core.Output<java.lang.Boolean> hasSecretStringWo()  
      com.pulumi.core.Output<java.lang.String> region()  
      com.pulumi.core.Output<java.lang.String> secretArn()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> secretBinary()  
      com.pulumi.core.Output<java.lang.String> secretId()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> secretString()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> secretStringWo()  
      com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> secretStringWoVersion()  
      com.pulumi.core.Output<java.lang.String> versionId()  
      com.pulumi.core.Output<java.util.List<java.lang.String>> versionStages()  
      • Methods inherited from class com.pulumi.resources.CustomResource

        getId, id, idFuture
      • Methods inherited from class com.pulumi.resources.Resource

        getChildResources, getResourceName, getResourceType, getUrn, pulumiChildResources, pulumiResourceName, pulumiResourceType, urn
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SecretVersion

        public SecretVersion​(java.lang.String name)
        Parameters:
        name - The _unique_ name of the resulting resource.
      • SecretVersion

        public SecretVersion​(java.lang.String name,
                             SecretVersionArgs args)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
      • SecretVersion

        public SecretVersion​(java.lang.String name,
                             SecretVersionArgs args,
                             @Nullable
                             com.pulumi.resources.CustomResourceOptions options)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
        options - A bag of options that control this resource's behavior.
    • Method Detail

      • arn

        public com.pulumi.core.Output<java.lang.String> arn()
        Returns:
        (**Deprecated**) ARN of the secret. Use `secretArn` instead.
      • hasSecretStringWo

        public com.pulumi.core.Output<java.lang.Boolean> hasSecretStringWo()
        Returns:
        Whether a write-only secret string value is set.
      • region

        public com.pulumi.core.Output<java.lang.String> region()
        Returns:
        Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
      • secretArn

        public com.pulumi.core.Output<java.lang.String> secretArn()
        Returns:
        ARN of the secret.
      • secretBinary

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> secretBinary()
        Returns:
        Binary data that you want to encrypt and store in this version of the secret. This is required if `secretString` or `secretStringWo` is not set. Needs to be encoded to base64.
      • secretId

        public com.pulumi.core.Output<java.lang.String> secretId()
        Returns:
        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.
      • secretString

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> secretString()
        Returns:
        Text data that you want to encrypt and store in this version of the secret. This is required if `secretBinary` or `secretStringWo` is not set.
      • secretStringWo

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> secretStringWo()
        Returns:
        **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 `secretBinary` or `secretString` is not set. If set, requires `secretStringWoVersion` to be set.
      • secretStringWoVersion

        public com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> secretStringWoVersion()
        Returns:
        Required when `secretStringWo` is set. Changing this value triggers an update to `secretStringWo`.
      • versionId

        public com.pulumi.core.Output<java.lang.String> versionId()
        Returns:
        Unique identifier of the version of the secret.
      • versionStages

        public com.pulumi.core.Output<java.util.List<java.lang.String>> versionStages()
        Returns:
        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. > **NOTE:** If `versionStages` is configured, you must include the `AWSCURRENT` staging label if this secret version is the only version or if the label is currently present on this secret version, otherwise this provider will show a perpetual difference.
      • get

        public static SecretVersion get​(java.lang.String name,
                                        com.pulumi.core.Output<java.lang.String> id,
                                        @Nullable
                                        SecretVersionState state,
                                        @Nullable
                                        com.pulumi.resources.CustomResourceOptions options)
        Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
        Parameters:
        name - The _unique_ name of the resulting resource.
        id - The _unique_ provider ID of the resource to lookup.
        state -
        options - Optional settings to control the behavior of the CustomResource.