Expand description
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.
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
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
let example = bucket_v_2::create(
"example",
BucketV2Args::builder().bucket("example-bucket").build_struct(),
);
let exampleBucketAclV2 = bucket_acl_v_2::create(
"exampleBucketAclV2",
BucketAclV2Args::builder().acl("private").bucket("${example.id}").build_struct(),
);
let versioningExample = bucket_versioning_v_2::create(
"versioningExample",
BucketVersioningV2Args::builder()
.bucket("${example.id}")
.versioning_configuration(
BucketVersioningV2VersioningConfiguration::builder()
.status("Enabled")
.build_struct(),
)
.build_struct(),
);
}
§With Versioning Disabled
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
let example = bucket_v_2::create(
"example",
BucketV2Args::builder().bucket("example-bucket").build_struct(),
);
let exampleBucketAclV2 = bucket_acl_v_2::create(
"exampleBucketAclV2",
BucketAclV2Args::builder().acl("private").bucket("${example.id}").build_struct(),
);
let versioningExample = bucket_versioning_v_2::create(
"versioningExample",
BucketVersioningV2Args::builder()
.bucket("${example.id}")
.versioning_configuration(
BucketVersioningV2VersioningConfiguration::builder()
.status("Disabled")
.build_struct(),
)
.build_struct(),
);
}
§Object Dependency On Versioning
When you create an object whose version_id
you need and an aws.s3.BucketVersioningV2
resource in the same configuration, you are more likely to have success by ensuring the s3_object
depends either implicitly (see below) or explicitly (i.e., using depends_on = [aws_s3_bucket_versioning.example]
) on the aws.s3.BucketVersioningV2
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
:
resources:
example:
type: aws:s3:BucketV2
properties:
bucket: yotto
exampleBucketVersioningV2:
type: aws:s3:BucketVersioningV2
name: example
properties:
bucket: ${example.id}
versioningConfiguration:
status: Enabled
exampleBucketObjectv2:
type: aws:s3:BucketObjectv2
name: example
properties:
bucket: ${exampleBucketVersioningV2.id}
key: droeloe
source:
fn::FileAsset: example.txt
§Import
If the owner (account ID) of the source bucket differs from the account used to configure the AWS Provider, import using the bucket
and expected_bucket_owner
separated by a comma (,
):
Using pulumi import
to import S3 bucket versioning using the bucket
or using the bucket
and expected_bucket_owner
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
:
$ pulumi import aws:s3/bucketVersioningV2:BucketVersioningV2 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 expected_bucket_owner
separated by a comma (,
):
$ pulumi import aws:s3/bucketVersioningV2:BucketVersioningV2 example bucket-name,123456789012
Structs§
- Use builder syntax to set the inputs and finish with
build_struct()
.
Functions§
- Registers a new resource with the given unique name and arguments