https://pulumi.com logo
#aws
Title
# aws
b

breezy-laptop-42679

08/04/2022, 2:05 PM
Hello I need guidance over creating s3 public access block the code mentioned in official documentation creates a new bucket and policy however I need to do it for a already created one please check the code below
Copy code
[6:11 PM] /*
   *   s3 public access block
   */
const bucketNameList = ["prod-nueve-media-9184fce"]
const bucketIdList: pulumi.Output<string>[] = []

bucketNameList.forEach(bucketName => {
  // Create an AWS resource (S3 Bucket) 
  const bucket = new aws.s3.Bucket(bucketName, {});
  bucketIdList.push(bucket.id)
});

for (let index = 0; index < bucketIdList.length; index++) {
  new aws.s3.BucketPublicAccessBlock(`${bucketNameList[index]}-publicAccessBlock`, {
    bucket: bucketIdList[index],
    blockPublicAcls: true,
    blockPublicPolicy: true,
  });
}
l

little-cartoon-10569

08/04/2022, 8:40 PM
If you want to manage a resource that already exists, you need to import it into Pulumi. This code doesn't import any buckets. You would need to run
pulumi import
or add the
import
opt, and you almost certainly wouldn't do it in a loop.
b

breezy-laptop-42679

08/05/2022, 11:27 AM
thanks for replying the bucket is already being managed by pulumi please let me know how could I achieve blockpubic acess on bucket
l

little-cartoon-10569

08/06/2022, 10:58 PM
Your code above should do it. You may want to add the
restrictPublicBuckets
and
ignorePublicAcls
properties, too.
2 Views