Skip to content

Commit

Permalink
Converting to BucketV2, fixes #1716
Browse files Browse the repository at this point in the history
  • Loading branch information
rshade committed Jan 10, 2025
1 parent b5deb9d commit 30737bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
8 changes: 4 additions & 4 deletions testing-integration-py/resource_s3.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import pulumi
from pulumi_aws import s3

BUCKET_NAME = 'pulumi-it-bucket'
OUTPUT_KEY_BUCKET_NAME = 'bucket_name'
OUTPUT_KEY_REGION = 'region'
BUCKET_NAME = "pulumi-it-bucket"
OUTPUT_KEY_BUCKET_NAME = "bucket_name"
OUTPUT_KEY_REGION = "region"


def create_s3_bucket():
# Create an AWS resource (S3 Bucket)
bucket = s3.Bucket(BUCKET_NAME)
bucket = s3.BucketV2(BUCKET_NAME)

# Export the value of the bucket
pulumi.export(OUTPUT_KEY_BUCKET_NAME, bucket.bucket)
Expand Down
22 changes: 14 additions & 8 deletions testing-integration-py/test_s3_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ class TestS3(unittest.TestCase):

@classmethod
def setUpClass(cls) -> None:
cls.STACK_NAME = 'staging'
cls.REGION_NAME = 'eu-north-1'
cls.STACK_NAME = "staging"
cls.REGION_NAME = "eu-north-1"
cls.WORK_DIR = os.path.join(os.path.dirname(__file__))
cls.FILE_NAME = 'bucket.txt'
cls.FILE_NAME = "bucket.txt"

cls.stack = auto.create_or_select_stack(stack_name=cls.STACK_NAME, work_dir=cls.WORK_DIR)
cls.stack = auto.create_or_select_stack(
stack_name=cls.STACK_NAME, work_dir=cls.WORK_DIR
)
cls.stack.set_config("aws:region", auto.ConfigValue(value=cls.REGION_NAME))
cls.stack.up(on_output=print)
cls.outputs = cls.stack.outputs()
cls.s3 = boto3.resource('s3')
cls.s3 = boto3.resource("s3")

@classmethod
def tearDownClass(cls) -> None:
Expand All @@ -45,14 +47,18 @@ def test_s3_exist(self):

def test_s3_create_permission(self):
output_bucket_name = self.outputs.get(OUTPUT_KEY_BUCKET_NAME).value
created_response = self.s3.Bucket(output_bucket_name).put_object(Key=self.FILE_NAME, Body='Hi')
created_response = self.s3.Bucket(output_bucket_name).put_object(
Key=self.FILE_NAME, Body="Hi"
)
self.assertEqual(created_response.key, self.FILE_NAME)

def test_s3_delete_permission(self):
output_bucket_name = self.outputs.get(OUTPUT_KEY_BUCKET_NAME).value
delete_response = self.s3.meta.client.delete_object(Bucket=output_bucket_name, Key=self.FILE_NAME)
delete_response = self.s3.meta.client.delete_object(
Bucket=output_bucket_name, Key=self.FILE_NAME
)
self.assertIsNotNone(delete_response)


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
8 changes: 4 additions & 4 deletions testing-unit-ts/mocha/bucket_pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import * as pulumi from "@pulumi/pulumi";

export class BucketPair extends pulumi.ComponentResource {

contentBucket: aws.s3.Bucket;
logsBucket: aws.s3.Bucket;
contentBucket: aws.s3.BucketV2;
logsBucket: aws.s3.BucketV2;

constructor(contentBucketName: string, logsBucketName: string, opts: any) {
super("pulumi:examples:BucketPair", "BucketPair", {}, opts);

this.contentBucket = new aws.s3.Bucket("contentBucket", {
this.contentBucket = new aws.s3.BucketV2("contentBucket", {
bucket: contentBucketName,
}, { parent: this });

this.logsBucket = new aws.s3.Bucket("logsBucket", {
this.logsBucket = new aws.s3.BucketV2("logsBucket", {
bucket: logsBucketName,
}, { parent: this });

Expand Down

0 comments on commit 30737bb

Please sign in to comment.