Class BucketVersioning


  • public class BucketVersioning
    extends com.pulumi.resources.CustomResource
    Provides a resource for controlling versioning on an S3 bucket. Deleting this resource will either suspend versioning on the associated S3 bucket or simply remove the resource from state if the associated S3 bucket is unversioned. For more information, see [How S3 versioning works](https://docs.aws.amazon.com/AmazonS3/latest/userguide/manage-versioning-examples.html). > **NOTE:** If you are enabling versioning on the bucket for the first time, AWS recommends that you wait for 15 minutes after enabling versioning before issuing write operations (PUT or DELETE) on objects in the bucket. > This resource cannot be used with S3 directory buckets. ## Example Usage ### With Versioning Enabled
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.s3.Bucket;
     import com.pulumi.aws.s3.BucketArgs;
     import com.pulumi.aws.s3.BucketAcl;
     import com.pulumi.aws.s3.BucketAclArgs;
     import com.pulumi.aws.s3.BucketVersioning;
     import com.pulumi.aws.s3.BucketVersioningArgs;
     import com.pulumi.aws.s3.inputs.BucketVersioningVersioningConfigurationArgs;
     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 Bucket("example", BucketArgs.builder()
                 .bucket("example-bucket")
                 .build());
     
             var exampleBucketAcl = new BucketAcl("exampleBucketAcl", BucketAclArgs.builder()
                 .bucket(example.id())
                 .acl("private")
                 .build());
     
             var versioningExample = new BucketVersioning("versioningExample", BucketVersioningArgs.builder()
                 .versioningConfiguration(BucketVersioningVersioningConfigurationArgs.builder()
                     .status("Enabled")
                     .build())
                 .bucket(example.id())
                 .build());
     
         }
     }
     
     
    ### With Versioning Disabled
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.s3.Bucket;
     import com.pulumi.aws.s3.BucketArgs;
     import com.pulumi.aws.s3.BucketAcl;
     import com.pulumi.aws.s3.BucketAclArgs;
     import com.pulumi.aws.s3.BucketVersioning;
     import com.pulumi.aws.s3.BucketVersioningArgs;
     import com.pulumi.aws.s3.inputs.BucketVersioningVersioningConfigurationArgs;
     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 Bucket("example", BucketArgs.builder()
                 .bucket("example-bucket")
                 .build());
     
             var exampleBucketAcl = new BucketAcl("exampleBucketAcl", BucketAclArgs.builder()
                 .bucket(example.id())
                 .acl("private")
                 .build());
     
             var versioningExample = new BucketVersioning("versioningExample", BucketVersioningArgs.builder()
                 .versioningConfiguration(BucketVersioningVersioningConfigurationArgs.builder()
                     .status("Disabled")
                     .build())
                 .bucket(example.id())
                 .build());
     
         }
     }
     
     
    ### Object Dependency On Versioning When you create an object whose `versionId` you need and an `aws.s3.BucketVersioning` resource in the same configuration, you are more likely to have success by ensuring the `s3Object` depends either implicitly (see below) or explicitly (i.e., using `dependsOn = [aws_s3_bucket_versioning.example]`) on the `aws.s3.BucketVersioning` resource. > **NOTE:** For critical and/or production S3 objects, do not create a bucket, enable versioning, and create an object in the bucket within the same configuration. Doing so will not allow the AWS-recommended 15 minutes between enabling versioning and writing to the bucket. This example shows the `aws_s3_object.example` depending implicitly on the versioning resource through the reference to `aws_s3_bucket_versioning.example.bucket` to define `bucket`:
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.s3.Bucket;
     import com.pulumi.aws.s3.BucketArgs;
     import com.pulumi.aws.s3.BucketVersioning;
     import com.pulumi.aws.s3.BucketVersioningArgs;
     import com.pulumi.aws.s3.inputs.BucketVersioningVersioningConfigurationArgs;
     import com.pulumi.aws.s3.BucketObjectv2;
     import com.pulumi.aws.s3.BucketObjectv2Args;
     import com.pulumi.asset.FileAsset;
     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 Bucket("example", BucketArgs.builder()
                 .bucket("yotto")
                 .build());
     
             var exampleBucketVersioning = new BucketVersioning("exampleBucketVersioning", BucketVersioningArgs.builder()
                 .versioningConfiguration(BucketVersioningVersioningConfigurationArgs.builder()
                     .status("Enabled")
                     .build())
                 .bucket(example.id())
                 .build());
     
             var exampleBucketObjectv2 = new BucketObjectv2("exampleBucketObjectv2", BucketObjectv2Args.builder()
                 .bucket(exampleBucketVersioning.id())
                 .key("droeloe")
                 .source(new FileAsset("example.txt"))
                 .build());
     
         }
     }
     
     
    ## Import ### Identity Schema #### Required * `bucket` (String) S3 bucket name. #### Optional * `accountId` (String) AWS Account where this resource is managed. * `region` (String) Region where this resource is managed. If the owner (account ID) of the source bucket differs from the account used to configure the AWS Provider, import using the `bucket` and `expectedBucketOwner` separated by a comma (`,`): **Using `pulumi import` to import** S3 bucket versioning using the `bucket` or using the `bucket` and `expectedBucketOwner` separated by a comma (`,`). For example: If the owner (account ID) of the source bucket is the same account used to configure the AWS Provider, import using the `bucket`: ```sh $ pulumi import aws:s3/bucketVersioning:BucketVersioning example bucket-name ``` If the owner (account ID) of the source bucket differs from the account used to configure the AWS Provider, import using the `bucket` and `expectedBucketOwner` separated by a comma (`,`): ```sh $ pulumi import aws:s3/bucketVersioning:BucketVersioning example bucket-name,123456789012 ```
    • 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> bucket()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> expectedBucketOwner()  
      static BucketVersioning get​(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, BucketVersioningState 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.util.Optional<java.lang.String>> mfa()  
      com.pulumi.core.Output<java.lang.String> region()  
      com.pulumi.core.Output<BucketVersioningVersioningConfiguration> versioningConfiguration()  
      • 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

      • BucketVersioning

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

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

        public BucketVersioning​(java.lang.String name,
                                BucketVersioningArgs 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

      • bucket

        public com.pulumi.core.Output<java.lang.String> bucket()
        Returns:
        Name of the S3 bucket.
      • expectedBucketOwner

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> expectedBucketOwner()
        Returns:
        Account ID of the expected bucket owner.
      • mfa

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> mfa()
        Returns:
        Concatenation of the authentication device's serial number, a space, and the value that is displayed on your authentication device.
      • 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.
      • versioningConfiguration

        public com.pulumi.core.Output<BucketVersioningVersioningConfiguration> versioningConfiguration()
        Returns:
        Configuration block for the versioning parameters. See below.
      • get

        public static BucketVersioning get​(java.lang.String name,
                                           com.pulumi.core.Output<java.lang.String> id,
                                           @Nullable
                                           BucketVersioningState 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.