From adf5adbbc3a446fc3e35ca3970e7ec2d37939954 Mon Sep 17 00:00:00 2001 From: Edmund Miller Date: Fri, 21 Jun 2024 16:02:03 -0500 Subject: [PATCH] feat: Allow @edmundmiller to add files to bucket --- pulumi/test-datasets/__main__.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/pulumi/test-datasets/__main__.py b/pulumi/test-datasets/__main__.py index 4f9bceb..9e767a4 100644 --- a/pulumi/test-datasets/__main__.py +++ b/pulumi/test-datasets/__main__.py @@ -3,7 +3,7 @@ import pulumi import pulumi_aws as aws -awsmegatests_bucket = aws.s3.Bucket( +test_datasets_bucket = aws.s3.Bucket( "test-datasets-bucket", arn="arn:aws:s3:::nf-core-test-datasets", bucket="nf-core-test-datasets", @@ -36,3 +36,33 @@ ), ), ) + +# Define the policy which allows users to put objects in the S3 bucket +policy = aws.iam.Policy( + "bucketPutPolicy", + description="Allow users to put objects in the S3 bucket", + policy=test_datasets_bucket.arn.apply( + lambda bucket_arn: f"""{{ + "Version": "2012-10-17", + "Statement": [ + {{ + "Effect": "Allow", + "Action": "s3:PutObject", + "Resource": "{bucket_arn}/*" + }} + ] + }}""" + ), +) + +# List of AWS user names to attach the policy to +usernames = ["edmund", "maxime"] + +# Attach the policy to each user +for username in usernames: + aws.iam.UserPolicyAttachment( + f"{username}-putPolicyAttachment", user=username, policy_arn=policy.arn + ) + +# Export the bucket name +pulumi.export("bucket_name", test_datasets_bucket.bucket)