Hello I need guidance over creating s3 public acce...
# aws
b
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
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
thanks for replying the bucket is already being managed by pulumi please let me know how could I achieve blockpubic acess on bucket
l
Your code above should do it. You may want to add the
restrictPublicBuckets
and
ignorePublicAcls
properties, too.