github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/secretsmanager/secretRotation.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 rotation. To manage a secret, see the `secretsmanager.Secret` resource. To manage a secret value, see the `secretsmanager.SecretVersion` resource. 16 // 17 // ## Example Usage 18 // 19 // ### Basic 20 // 21 // <!--Start PulumiCodeChooser --> 22 // ```go 23 // package main 24 // 25 // import ( 26 // 27 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/secretsmanager" 28 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 29 // 30 // ) 31 // 32 // func main() { 33 // pulumi.Run(func(ctx *pulumi.Context) error { 34 // _, err := secretsmanager.NewSecretRotation(ctx, "example", &secretsmanager.SecretRotationArgs{ 35 // SecretId: pulumi.Any(exampleAwsSecretsmanagerSecret.Id), 36 // RotationLambdaArn: pulumi.Any(exampleAwsLambdaFunction.Arn), 37 // RotationRules: &secretsmanager.SecretRotationRotationRulesArgs{ 38 // AutomaticallyAfterDays: pulumi.Int(30), 39 // }, 40 // }) 41 // if err != nil { 42 // return err 43 // } 44 // return nil 45 // }) 46 // } 47 // 48 // ``` 49 // <!--End PulumiCodeChooser --> 50 // 51 // ### Rotation Configuration 52 // 53 // To enable automatic secret rotation, the Secrets Manager service requires usage of a Lambda function. The [Rotate Secrets section in the Secrets Manager User Guide](https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotating-secrets.html) provides additional information about deploying a prebuilt Lambda functions for supported credential rotation (e.g., RDS) or deploying a custom Lambda function. 54 // 55 // > **NOTE:** Configuring rotation causes the secret to rotate once as soon as you enable rotation. Before you do this, you must ensure that all of your applications that use the credentials stored in the secret are updated to retrieve the secret from AWS Secrets Manager. The old credentials might no longer be usable after the initial rotation and any applications that you fail to update will break as soon as the old credentials are no longer valid. 56 // 57 // > **NOTE:** If you cancel a rotation that is in progress (by removing the `rotation` configuration), it can leave the VersionStage labels in an unexpected state. Depending on what step of the rotation was in progress, you might need to remove the staging label AWSPENDING from the partially created version, specified by the SecretVersionId response value. You should also evaluate the partially rotated new version to see if it should be deleted, which you can do by removing all staging labels from the new version's VersionStage field. 58 // 59 // ## Import 60 // 61 // Using `pulumi import`, import `aws_secretsmanager_secret_rotation` using the secret Amazon Resource Name (ARN). For example: 62 // 63 // ```sh 64 // $ pulumi import aws:secretsmanager/secretRotation:SecretRotation example arn:aws:secretsmanager:us-east-1:123456789012:secret:example-123456 65 // ``` 66 type SecretRotation struct { 67 pulumi.CustomResourceState 68 69 // Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. The rotation schedule is defined in `rotationRules`. For secrets that use a Lambda rotation function to rotate, if you don't immediately rotate the secret, Secrets Manager tests the rotation configuration by running the testSecret step (https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_how.html) of the Lambda rotation function. The test creates an AWSPENDING version of the secret and then removes it. Defaults to `true`. 70 RotateImmediately pulumi.BoolPtrOutput `pulumi:"rotateImmediately"` 71 // Specifies whether automatic rotation is enabled for this secret. 72 RotationEnabled pulumi.BoolOutput `pulumi:"rotationEnabled"` 73 // Specifies the ARN of the Lambda function that can rotate the secret. Must be supplied if the secret is not managed by AWS. 74 RotationLambdaArn pulumi.StringPtrOutput `pulumi:"rotationLambdaArn"` 75 // A structure that defines the rotation configuration for this secret. Defined below. 76 RotationRules SecretRotationRotationRulesOutput `pulumi:"rotationRules"` 77 // 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. 78 SecretId pulumi.StringOutput `pulumi:"secretId"` 79 } 80 81 // NewSecretRotation registers a new resource with the given unique name, arguments, and options. 82 func NewSecretRotation(ctx *pulumi.Context, 83 name string, args *SecretRotationArgs, opts ...pulumi.ResourceOption) (*SecretRotation, error) { 84 if args == nil { 85 return nil, errors.New("missing one or more required arguments") 86 } 87 88 if args.RotationRules == nil { 89 return nil, errors.New("invalid value for required argument 'RotationRules'") 90 } 91 if args.SecretId == nil { 92 return nil, errors.New("invalid value for required argument 'SecretId'") 93 } 94 opts = internal.PkgResourceDefaultOpts(opts) 95 var resource SecretRotation 96 err := ctx.RegisterResource("aws:secretsmanager/secretRotation:SecretRotation", name, args, &resource, opts...) 97 if err != nil { 98 return nil, err 99 } 100 return &resource, nil 101 } 102 103 // GetSecretRotation gets an existing SecretRotation resource's state with the given name, ID, and optional 104 // state properties that are used to uniquely qualify the lookup (nil if not required). 105 func GetSecretRotation(ctx *pulumi.Context, 106 name string, id pulumi.IDInput, state *SecretRotationState, opts ...pulumi.ResourceOption) (*SecretRotation, error) { 107 var resource SecretRotation 108 err := ctx.ReadResource("aws:secretsmanager/secretRotation:SecretRotation", name, id, state, &resource, opts...) 109 if err != nil { 110 return nil, err 111 } 112 return &resource, nil 113 } 114 115 // Input properties used for looking up and filtering SecretRotation resources. 116 type secretRotationState struct { 117 // Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. The rotation schedule is defined in `rotationRules`. For secrets that use a Lambda rotation function to rotate, if you don't immediately rotate the secret, Secrets Manager tests the rotation configuration by running the testSecret step (https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_how.html) of the Lambda rotation function. The test creates an AWSPENDING version of the secret and then removes it. Defaults to `true`. 118 RotateImmediately *bool `pulumi:"rotateImmediately"` 119 // Specifies whether automatic rotation is enabled for this secret. 120 RotationEnabled *bool `pulumi:"rotationEnabled"` 121 // Specifies the ARN of the Lambda function that can rotate the secret. Must be supplied if the secret is not managed by AWS. 122 RotationLambdaArn *string `pulumi:"rotationLambdaArn"` 123 // A structure that defines the rotation configuration for this secret. Defined below. 124 RotationRules *SecretRotationRotationRules `pulumi:"rotationRules"` 125 // 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. 126 SecretId *string `pulumi:"secretId"` 127 } 128 129 type SecretRotationState struct { 130 // Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. The rotation schedule is defined in `rotationRules`. For secrets that use a Lambda rotation function to rotate, if you don't immediately rotate the secret, Secrets Manager tests the rotation configuration by running the testSecret step (https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_how.html) of the Lambda rotation function. The test creates an AWSPENDING version of the secret and then removes it. Defaults to `true`. 131 RotateImmediately pulumi.BoolPtrInput 132 // Specifies whether automatic rotation is enabled for this secret. 133 RotationEnabled pulumi.BoolPtrInput 134 // Specifies the ARN of the Lambda function that can rotate the secret. Must be supplied if the secret is not managed by AWS. 135 RotationLambdaArn pulumi.StringPtrInput 136 // A structure that defines the rotation configuration for this secret. Defined below. 137 RotationRules SecretRotationRotationRulesPtrInput 138 // 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. 139 SecretId pulumi.StringPtrInput 140 } 141 142 func (SecretRotationState) ElementType() reflect.Type { 143 return reflect.TypeOf((*secretRotationState)(nil)).Elem() 144 } 145 146 type secretRotationArgs struct { 147 // Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. The rotation schedule is defined in `rotationRules`. For secrets that use a Lambda rotation function to rotate, if you don't immediately rotate the secret, Secrets Manager tests the rotation configuration by running the testSecret step (https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_how.html) of the Lambda rotation function. The test creates an AWSPENDING version of the secret and then removes it. Defaults to `true`. 148 RotateImmediately *bool `pulumi:"rotateImmediately"` 149 // Specifies the ARN of the Lambda function that can rotate the secret. Must be supplied if the secret is not managed by AWS. 150 RotationLambdaArn *string `pulumi:"rotationLambdaArn"` 151 // A structure that defines the rotation configuration for this secret. Defined below. 152 RotationRules SecretRotationRotationRules `pulumi:"rotationRules"` 153 // 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. 154 SecretId string `pulumi:"secretId"` 155 } 156 157 // The set of arguments for constructing a SecretRotation resource. 158 type SecretRotationArgs struct { 159 // Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. The rotation schedule is defined in `rotationRules`. For secrets that use a Lambda rotation function to rotate, if you don't immediately rotate the secret, Secrets Manager tests the rotation configuration by running the testSecret step (https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_how.html) of the Lambda rotation function. The test creates an AWSPENDING version of the secret and then removes it. Defaults to `true`. 160 RotateImmediately pulumi.BoolPtrInput 161 // Specifies the ARN of the Lambda function that can rotate the secret. Must be supplied if the secret is not managed by AWS. 162 RotationLambdaArn pulumi.StringPtrInput 163 // A structure that defines the rotation configuration for this secret. Defined below. 164 RotationRules SecretRotationRotationRulesInput 165 // 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. 166 SecretId pulumi.StringInput 167 } 168 169 func (SecretRotationArgs) ElementType() reflect.Type { 170 return reflect.TypeOf((*secretRotationArgs)(nil)).Elem() 171 } 172 173 type SecretRotationInput interface { 174 pulumi.Input 175 176 ToSecretRotationOutput() SecretRotationOutput 177 ToSecretRotationOutputWithContext(ctx context.Context) SecretRotationOutput 178 } 179 180 func (*SecretRotation) ElementType() reflect.Type { 181 return reflect.TypeOf((**SecretRotation)(nil)).Elem() 182 } 183 184 func (i *SecretRotation) ToSecretRotationOutput() SecretRotationOutput { 185 return i.ToSecretRotationOutputWithContext(context.Background()) 186 } 187 188 func (i *SecretRotation) ToSecretRotationOutputWithContext(ctx context.Context) SecretRotationOutput { 189 return pulumi.ToOutputWithContext(ctx, i).(SecretRotationOutput) 190 } 191 192 // SecretRotationArrayInput is an input type that accepts SecretRotationArray and SecretRotationArrayOutput values. 193 // You can construct a concrete instance of `SecretRotationArrayInput` via: 194 // 195 // SecretRotationArray{ SecretRotationArgs{...} } 196 type SecretRotationArrayInput interface { 197 pulumi.Input 198 199 ToSecretRotationArrayOutput() SecretRotationArrayOutput 200 ToSecretRotationArrayOutputWithContext(context.Context) SecretRotationArrayOutput 201 } 202 203 type SecretRotationArray []SecretRotationInput 204 205 func (SecretRotationArray) ElementType() reflect.Type { 206 return reflect.TypeOf((*[]*SecretRotation)(nil)).Elem() 207 } 208 209 func (i SecretRotationArray) ToSecretRotationArrayOutput() SecretRotationArrayOutput { 210 return i.ToSecretRotationArrayOutputWithContext(context.Background()) 211 } 212 213 func (i SecretRotationArray) ToSecretRotationArrayOutputWithContext(ctx context.Context) SecretRotationArrayOutput { 214 return pulumi.ToOutputWithContext(ctx, i).(SecretRotationArrayOutput) 215 } 216 217 // SecretRotationMapInput is an input type that accepts SecretRotationMap and SecretRotationMapOutput values. 218 // You can construct a concrete instance of `SecretRotationMapInput` via: 219 // 220 // SecretRotationMap{ "key": SecretRotationArgs{...} } 221 type SecretRotationMapInput interface { 222 pulumi.Input 223 224 ToSecretRotationMapOutput() SecretRotationMapOutput 225 ToSecretRotationMapOutputWithContext(context.Context) SecretRotationMapOutput 226 } 227 228 type SecretRotationMap map[string]SecretRotationInput 229 230 func (SecretRotationMap) ElementType() reflect.Type { 231 return reflect.TypeOf((*map[string]*SecretRotation)(nil)).Elem() 232 } 233 234 func (i SecretRotationMap) ToSecretRotationMapOutput() SecretRotationMapOutput { 235 return i.ToSecretRotationMapOutputWithContext(context.Background()) 236 } 237 238 func (i SecretRotationMap) ToSecretRotationMapOutputWithContext(ctx context.Context) SecretRotationMapOutput { 239 return pulumi.ToOutputWithContext(ctx, i).(SecretRotationMapOutput) 240 } 241 242 type SecretRotationOutput struct{ *pulumi.OutputState } 243 244 func (SecretRotationOutput) ElementType() reflect.Type { 245 return reflect.TypeOf((**SecretRotation)(nil)).Elem() 246 } 247 248 func (o SecretRotationOutput) ToSecretRotationOutput() SecretRotationOutput { 249 return o 250 } 251 252 func (o SecretRotationOutput) ToSecretRotationOutputWithContext(ctx context.Context) SecretRotationOutput { 253 return o 254 } 255 256 // Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. The rotation schedule is defined in `rotationRules`. For secrets that use a Lambda rotation function to rotate, if you don't immediately rotate the secret, Secrets Manager tests the rotation configuration by running the testSecret step (https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_how.html) of the Lambda rotation function. The test creates an AWSPENDING version of the secret and then removes it. Defaults to `true`. 257 func (o SecretRotationOutput) RotateImmediately() pulumi.BoolPtrOutput { 258 return o.ApplyT(func(v *SecretRotation) pulumi.BoolPtrOutput { return v.RotateImmediately }).(pulumi.BoolPtrOutput) 259 } 260 261 // Specifies whether automatic rotation is enabled for this secret. 262 func (o SecretRotationOutput) RotationEnabled() pulumi.BoolOutput { 263 return o.ApplyT(func(v *SecretRotation) pulumi.BoolOutput { return v.RotationEnabled }).(pulumi.BoolOutput) 264 } 265 266 // Specifies the ARN of the Lambda function that can rotate the secret. Must be supplied if the secret is not managed by AWS. 267 func (o SecretRotationOutput) RotationLambdaArn() pulumi.StringPtrOutput { 268 return o.ApplyT(func(v *SecretRotation) pulumi.StringPtrOutput { return v.RotationLambdaArn }).(pulumi.StringPtrOutput) 269 } 270 271 // A structure that defines the rotation configuration for this secret. Defined below. 272 func (o SecretRotationOutput) RotationRules() SecretRotationRotationRulesOutput { 273 return o.ApplyT(func(v *SecretRotation) SecretRotationRotationRulesOutput { return v.RotationRules }).(SecretRotationRotationRulesOutput) 274 } 275 276 // 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. 277 func (o SecretRotationOutput) SecretId() pulumi.StringOutput { 278 return o.ApplyT(func(v *SecretRotation) pulumi.StringOutput { return v.SecretId }).(pulumi.StringOutput) 279 } 280 281 type SecretRotationArrayOutput struct{ *pulumi.OutputState } 282 283 func (SecretRotationArrayOutput) ElementType() reflect.Type { 284 return reflect.TypeOf((*[]*SecretRotation)(nil)).Elem() 285 } 286 287 func (o SecretRotationArrayOutput) ToSecretRotationArrayOutput() SecretRotationArrayOutput { 288 return o 289 } 290 291 func (o SecretRotationArrayOutput) ToSecretRotationArrayOutputWithContext(ctx context.Context) SecretRotationArrayOutput { 292 return o 293 } 294 295 func (o SecretRotationArrayOutput) Index(i pulumi.IntInput) SecretRotationOutput { 296 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *SecretRotation { 297 return vs[0].([]*SecretRotation)[vs[1].(int)] 298 }).(SecretRotationOutput) 299 } 300 301 type SecretRotationMapOutput struct{ *pulumi.OutputState } 302 303 func (SecretRotationMapOutput) ElementType() reflect.Type { 304 return reflect.TypeOf((*map[string]*SecretRotation)(nil)).Elem() 305 } 306 307 func (o SecretRotationMapOutput) ToSecretRotationMapOutput() SecretRotationMapOutput { 308 return o 309 } 310 311 func (o SecretRotationMapOutput) ToSecretRotationMapOutputWithContext(ctx context.Context) SecretRotationMapOutput { 312 return o 313 } 314 315 func (o SecretRotationMapOutput) MapIndex(k pulumi.StringInput) SecretRotationOutput { 316 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *SecretRotation { 317 return vs[0].(map[string]*SecretRotation)[vs[1].(string)] 318 }).(SecretRotationOutput) 319 } 320 321 func init() { 322 pulumi.RegisterInputType(reflect.TypeOf((*SecretRotationInput)(nil)).Elem(), &SecretRotation{}) 323 pulumi.RegisterInputType(reflect.TypeOf((*SecretRotationArrayInput)(nil)).Elem(), SecretRotationArray{}) 324 pulumi.RegisterInputType(reflect.TypeOf((*SecretRotationMapInput)(nil)).Elem(), SecretRotationMap{}) 325 pulumi.RegisterOutputType(SecretRotationOutput{}) 326 pulumi.RegisterOutputType(SecretRotationArrayOutput{}) 327 pulumi.RegisterOutputType(SecretRotationMapOutput{}) 328 }