github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/secretsmanager/secretVersion.go (about)

     1  // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package secretsmanager
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"errors"
    11  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    12  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    13  )
    14  
    15  // Provides a resource to manage AWS Secrets Manager secret version including its secret value. To manage secret metadata, see the `secretsmanager.Secret` resource.
    16  //
    17  // > **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.
    18  //
    19  // ## Example Usage
    20  //
    21  // ### Simple String Value
    22  //
    23  // <!--Start PulumiCodeChooser -->
    24  // ```go
    25  // package main
    26  //
    27  // import (
    28  //
    29  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/secretsmanager"
    30  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    31  //
    32  // )
    33  //
    34  //	func main() {
    35  //		pulumi.Run(func(ctx *pulumi.Context) error {
    36  //			_, err := secretsmanager.NewSecretVersion(ctx, "example", &secretsmanager.SecretVersionArgs{
    37  //				SecretId:     pulumi.Any(exampleAwsSecretsmanagerSecret.Id),
    38  //				SecretString: pulumi.String("example-string-to-protect"),
    39  //			})
    40  //			if err != nil {
    41  //				return err
    42  //			}
    43  //			return nil
    44  //		})
    45  //	}
    46  //
    47  // ```
    48  // <!--End PulumiCodeChooser -->
    49  //
    50  // ### Key-Value Pairs
    51  //
    52  // Secrets Manager also accepts key-value pairs in JSON.
    53  //
    54  // <!--Start PulumiCodeChooser -->
    55  // ```go
    56  // package main
    57  //
    58  // import (
    59  //
    60  //	"encoding/json"
    61  //
    62  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/secretsmanager"
    63  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    64  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    65  //
    66  // )
    67  //
    68  //	func main() {
    69  //		pulumi.Run(func(ctx *pulumi.Context) error {
    70  //			cfg := config.New(ctx, "")
    71  //			example := map[string]interface{}{
    72  //				"key1": "value1",
    73  //				"key2": "value2",
    74  //			}
    75  //			if param := cfg.GetObject("example"); param != nil {
    76  //				example = param
    77  //			}
    78  //			tmpJSON0, err := json.Marshal(example)
    79  //			if err != nil {
    80  //				return err
    81  //			}
    82  //			json0 := string(tmpJSON0)
    83  //			_, err = secretsmanager.NewSecretVersion(ctx, "example", &secretsmanager.SecretVersionArgs{
    84  //				SecretId:     pulumi.Any(exampleAwsSecretsmanagerSecret.Id),
    85  //				SecretString: pulumi.String(json0),
    86  //			})
    87  //			if err != nil {
    88  //				return err
    89  //			}
    90  //			return nil
    91  //		})
    92  //	}
    93  //
    94  // ```
    95  // <!--End PulumiCodeChooser -->
    96  //
    97  // # Reading key-value pairs from JSON back into a native map
    98  //
    99  // ## Import
   100  //
   101  // Using `pulumi import`, import `aws_secretsmanager_secret_version` using the secret ID and version ID. For example:
   102  //
   103  // ```sh
   104  // $ pulumi import aws:secretsmanager/secretVersion:SecretVersion example 'arn:aws:secretsmanager:us-east-1:123456789012:secret:example-123456|xxxxx-xxxxxxx-xxxxxxx-xxxxx'
   105  // ```
   106  type SecretVersion struct {
   107  	pulumi.CustomResourceState
   108  
   109  	// The ARN of the secret.
   110  	Arn pulumi.StringOutput `pulumi:"arn"`
   111  	// Specifies binary data that you want to encrypt and store in this version of the secret. This is required if `secretString` is not set. Needs to be encoded to base64.
   112  	SecretBinary pulumi.StringPtrOutput `pulumi:"secretBinary"`
   113  	// 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.
   114  	SecretId pulumi.StringOutput `pulumi:"secretId"`
   115  	// Specifies text data that you want to encrypt and store in this version of the secret. This is required if `secretBinary` is not set.
   116  	SecretString pulumi.StringPtrOutput `pulumi:"secretString"`
   117  	// The unique identifier of the version of the secret.
   118  	VersionId pulumi.StringOutput `pulumi:"versionId"`
   119  	// 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.
   120  	//
   121  	// > **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.
   122  	VersionStages pulumi.StringArrayOutput `pulumi:"versionStages"`
   123  }
   124  
   125  // NewSecretVersion registers a new resource with the given unique name, arguments, and options.
   126  func NewSecretVersion(ctx *pulumi.Context,
   127  	name string, args *SecretVersionArgs, opts ...pulumi.ResourceOption) (*SecretVersion, error) {
   128  	if args == nil {
   129  		return nil, errors.New("missing one or more required arguments")
   130  	}
   131  
   132  	if args.SecretId == nil {
   133  		return nil, errors.New("invalid value for required argument 'SecretId'")
   134  	}
   135  	if args.SecretBinary != nil {
   136  		args.SecretBinary = pulumi.ToSecret(args.SecretBinary).(pulumi.StringPtrInput)
   137  	}
   138  	if args.SecretString != nil {
   139  		args.SecretString = pulumi.ToSecret(args.SecretString).(pulumi.StringPtrInput)
   140  	}
   141  	secrets := pulumi.AdditionalSecretOutputs([]string{
   142  		"secretBinary",
   143  		"secretString",
   144  	})
   145  	opts = append(opts, secrets)
   146  	opts = internal.PkgResourceDefaultOpts(opts)
   147  	var resource SecretVersion
   148  	err := ctx.RegisterResource("aws:secretsmanager/secretVersion:SecretVersion", name, args, &resource, opts...)
   149  	if err != nil {
   150  		return nil, err
   151  	}
   152  	return &resource, nil
   153  }
   154  
   155  // GetSecretVersion gets an existing SecretVersion resource's state with the given name, ID, and optional
   156  // state properties that are used to uniquely qualify the lookup (nil if not required).
   157  func GetSecretVersion(ctx *pulumi.Context,
   158  	name string, id pulumi.IDInput, state *SecretVersionState, opts ...pulumi.ResourceOption) (*SecretVersion, error) {
   159  	var resource SecretVersion
   160  	err := ctx.ReadResource("aws:secretsmanager/secretVersion:SecretVersion", name, id, state, &resource, opts...)
   161  	if err != nil {
   162  		return nil, err
   163  	}
   164  	return &resource, nil
   165  }
   166  
   167  // Input properties used for looking up and filtering SecretVersion resources.
   168  type secretVersionState struct {
   169  	// The ARN of the secret.
   170  	Arn *string `pulumi:"arn"`
   171  	// Specifies binary data that you want to encrypt and store in this version of the secret. This is required if `secretString` is not set. Needs to be encoded to base64.
   172  	SecretBinary *string `pulumi:"secretBinary"`
   173  	// 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.
   174  	SecretId *string `pulumi:"secretId"`
   175  	// Specifies text data that you want to encrypt and store in this version of the secret. This is required if `secretBinary` is not set.
   176  	SecretString *string `pulumi:"secretString"`
   177  	// The unique identifier of the version of the secret.
   178  	VersionId *string `pulumi:"versionId"`
   179  	// 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.
   180  	//
   181  	// > **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.
   182  	VersionStages []string `pulumi:"versionStages"`
   183  }
   184  
   185  type SecretVersionState struct {
   186  	// The ARN of the secret.
   187  	Arn pulumi.StringPtrInput
   188  	// Specifies binary data that you want to encrypt and store in this version of the secret. This is required if `secretString` is not set. Needs to be encoded to base64.
   189  	SecretBinary pulumi.StringPtrInput
   190  	// 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.
   191  	SecretId pulumi.StringPtrInput
   192  	// Specifies text data that you want to encrypt and store in this version of the secret. This is required if `secretBinary` is not set.
   193  	SecretString pulumi.StringPtrInput
   194  	// The unique identifier of the version of the secret.
   195  	VersionId pulumi.StringPtrInput
   196  	// 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.
   197  	//
   198  	// > **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.
   199  	VersionStages pulumi.StringArrayInput
   200  }
   201  
   202  func (SecretVersionState) ElementType() reflect.Type {
   203  	return reflect.TypeOf((*secretVersionState)(nil)).Elem()
   204  }
   205  
   206  type secretVersionArgs struct {
   207  	// Specifies binary data that you want to encrypt and store in this version of the secret. This is required if `secretString` is not set. Needs to be encoded to base64.
   208  	SecretBinary *string `pulumi:"secretBinary"`
   209  	// 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.
   210  	SecretId string `pulumi:"secretId"`
   211  	// Specifies text data that you want to encrypt and store in this version of the secret. This is required if `secretBinary` is not set.
   212  	SecretString *string `pulumi:"secretString"`
   213  	// 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.
   214  	//
   215  	// > **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.
   216  	VersionStages []string `pulumi:"versionStages"`
   217  }
   218  
   219  // The set of arguments for constructing a SecretVersion resource.
   220  type SecretVersionArgs struct {
   221  	// Specifies binary data that you want to encrypt and store in this version of the secret. This is required if `secretString` is not set. Needs to be encoded to base64.
   222  	SecretBinary pulumi.StringPtrInput
   223  	// 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.
   224  	SecretId pulumi.StringInput
   225  	// Specifies text data that you want to encrypt and store in this version of the secret. This is required if `secretBinary` is not set.
   226  	SecretString pulumi.StringPtrInput
   227  	// 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.
   228  	//
   229  	// > **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.
   230  	VersionStages pulumi.StringArrayInput
   231  }
   232  
   233  func (SecretVersionArgs) ElementType() reflect.Type {
   234  	return reflect.TypeOf((*secretVersionArgs)(nil)).Elem()
   235  }
   236  
   237  type SecretVersionInput interface {
   238  	pulumi.Input
   239  
   240  	ToSecretVersionOutput() SecretVersionOutput
   241  	ToSecretVersionOutputWithContext(ctx context.Context) SecretVersionOutput
   242  }
   243  
   244  func (*SecretVersion) ElementType() reflect.Type {
   245  	return reflect.TypeOf((**SecretVersion)(nil)).Elem()
   246  }
   247  
   248  func (i *SecretVersion) ToSecretVersionOutput() SecretVersionOutput {
   249  	return i.ToSecretVersionOutputWithContext(context.Background())
   250  }
   251  
   252  func (i *SecretVersion) ToSecretVersionOutputWithContext(ctx context.Context) SecretVersionOutput {
   253  	return pulumi.ToOutputWithContext(ctx, i).(SecretVersionOutput)
   254  }
   255  
   256  // SecretVersionArrayInput is an input type that accepts SecretVersionArray and SecretVersionArrayOutput values.
   257  // You can construct a concrete instance of `SecretVersionArrayInput` via:
   258  //
   259  //	SecretVersionArray{ SecretVersionArgs{...} }
   260  type SecretVersionArrayInput interface {
   261  	pulumi.Input
   262  
   263  	ToSecretVersionArrayOutput() SecretVersionArrayOutput
   264  	ToSecretVersionArrayOutputWithContext(context.Context) SecretVersionArrayOutput
   265  }
   266  
   267  type SecretVersionArray []SecretVersionInput
   268  
   269  func (SecretVersionArray) ElementType() reflect.Type {
   270  	return reflect.TypeOf((*[]*SecretVersion)(nil)).Elem()
   271  }
   272  
   273  func (i SecretVersionArray) ToSecretVersionArrayOutput() SecretVersionArrayOutput {
   274  	return i.ToSecretVersionArrayOutputWithContext(context.Background())
   275  }
   276  
   277  func (i SecretVersionArray) ToSecretVersionArrayOutputWithContext(ctx context.Context) SecretVersionArrayOutput {
   278  	return pulumi.ToOutputWithContext(ctx, i).(SecretVersionArrayOutput)
   279  }
   280  
   281  // SecretVersionMapInput is an input type that accepts SecretVersionMap and SecretVersionMapOutput values.
   282  // You can construct a concrete instance of `SecretVersionMapInput` via:
   283  //
   284  //	SecretVersionMap{ "key": SecretVersionArgs{...} }
   285  type SecretVersionMapInput interface {
   286  	pulumi.Input
   287  
   288  	ToSecretVersionMapOutput() SecretVersionMapOutput
   289  	ToSecretVersionMapOutputWithContext(context.Context) SecretVersionMapOutput
   290  }
   291  
   292  type SecretVersionMap map[string]SecretVersionInput
   293  
   294  func (SecretVersionMap) ElementType() reflect.Type {
   295  	return reflect.TypeOf((*map[string]*SecretVersion)(nil)).Elem()
   296  }
   297  
   298  func (i SecretVersionMap) ToSecretVersionMapOutput() SecretVersionMapOutput {
   299  	return i.ToSecretVersionMapOutputWithContext(context.Background())
   300  }
   301  
   302  func (i SecretVersionMap) ToSecretVersionMapOutputWithContext(ctx context.Context) SecretVersionMapOutput {
   303  	return pulumi.ToOutputWithContext(ctx, i).(SecretVersionMapOutput)
   304  }
   305  
   306  type SecretVersionOutput struct{ *pulumi.OutputState }
   307  
   308  func (SecretVersionOutput) ElementType() reflect.Type {
   309  	return reflect.TypeOf((**SecretVersion)(nil)).Elem()
   310  }
   311  
   312  func (o SecretVersionOutput) ToSecretVersionOutput() SecretVersionOutput {
   313  	return o
   314  }
   315  
   316  func (o SecretVersionOutput) ToSecretVersionOutputWithContext(ctx context.Context) SecretVersionOutput {
   317  	return o
   318  }
   319  
   320  // The ARN of the secret.
   321  func (o SecretVersionOutput) Arn() pulumi.StringOutput {
   322  	return o.ApplyT(func(v *SecretVersion) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput)
   323  }
   324  
   325  // Specifies binary data that you want to encrypt and store in this version of the secret. This is required if `secretString` is not set. Needs to be encoded to base64.
   326  func (o SecretVersionOutput) SecretBinary() pulumi.StringPtrOutput {
   327  	return o.ApplyT(func(v *SecretVersion) pulumi.StringPtrOutput { return v.SecretBinary }).(pulumi.StringPtrOutput)
   328  }
   329  
   330  // 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.
   331  func (o SecretVersionOutput) SecretId() pulumi.StringOutput {
   332  	return o.ApplyT(func(v *SecretVersion) pulumi.StringOutput { return v.SecretId }).(pulumi.StringOutput)
   333  }
   334  
   335  // Specifies text data that you want to encrypt and store in this version of the secret. This is required if `secretBinary` is not set.
   336  func (o SecretVersionOutput) SecretString() pulumi.StringPtrOutput {
   337  	return o.ApplyT(func(v *SecretVersion) pulumi.StringPtrOutput { return v.SecretString }).(pulumi.StringPtrOutput)
   338  }
   339  
   340  // The unique identifier of the version of the secret.
   341  func (o SecretVersionOutput) VersionId() pulumi.StringOutput {
   342  	return o.ApplyT(func(v *SecretVersion) pulumi.StringOutput { return v.VersionId }).(pulumi.StringOutput)
   343  }
   344  
   345  // 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.
   346  //
   347  // > **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.
   348  func (o SecretVersionOutput) VersionStages() pulumi.StringArrayOutput {
   349  	return o.ApplyT(func(v *SecretVersion) pulumi.StringArrayOutput { return v.VersionStages }).(pulumi.StringArrayOutput)
   350  }
   351  
   352  type SecretVersionArrayOutput struct{ *pulumi.OutputState }
   353  
   354  func (SecretVersionArrayOutput) ElementType() reflect.Type {
   355  	return reflect.TypeOf((*[]*SecretVersion)(nil)).Elem()
   356  }
   357  
   358  func (o SecretVersionArrayOutput) ToSecretVersionArrayOutput() SecretVersionArrayOutput {
   359  	return o
   360  }
   361  
   362  func (o SecretVersionArrayOutput) ToSecretVersionArrayOutputWithContext(ctx context.Context) SecretVersionArrayOutput {
   363  	return o
   364  }
   365  
   366  func (o SecretVersionArrayOutput) Index(i pulumi.IntInput) SecretVersionOutput {
   367  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *SecretVersion {
   368  		return vs[0].([]*SecretVersion)[vs[1].(int)]
   369  	}).(SecretVersionOutput)
   370  }
   371  
   372  type SecretVersionMapOutput struct{ *pulumi.OutputState }
   373  
   374  func (SecretVersionMapOutput) ElementType() reflect.Type {
   375  	return reflect.TypeOf((*map[string]*SecretVersion)(nil)).Elem()
   376  }
   377  
   378  func (o SecretVersionMapOutput) ToSecretVersionMapOutput() SecretVersionMapOutput {
   379  	return o
   380  }
   381  
   382  func (o SecretVersionMapOutput) ToSecretVersionMapOutputWithContext(ctx context.Context) SecretVersionMapOutput {
   383  	return o
   384  }
   385  
   386  func (o SecretVersionMapOutput) MapIndex(k pulumi.StringInput) SecretVersionOutput {
   387  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *SecretVersion {
   388  		return vs[0].(map[string]*SecretVersion)[vs[1].(string)]
   389  	}).(SecretVersionOutput)
   390  }
   391  
   392  func init() {
   393  	pulumi.RegisterInputType(reflect.TypeOf((*SecretVersionInput)(nil)).Elem(), &SecretVersion{})
   394  	pulumi.RegisterInputType(reflect.TypeOf((*SecretVersionArrayInput)(nil)).Elem(), SecretVersionArray{})
   395  	pulumi.RegisterInputType(reflect.TypeOf((*SecretVersionMapInput)(nil)).Elem(), SecretVersionMap{})
   396  	pulumi.RegisterOutputType(SecretVersionOutput{})
   397  	pulumi.RegisterOutputType(SecretVersionArrayOutput{})
   398  	pulumi.RegisterOutputType(SecretVersionMapOutput{})
   399  }