Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I was able to create a bucket in an amazon S3 using this link.

I used the following code to create a bucket :

resource "aws_s3_bucket" "b" {

    bucket = "my_tf_test_bucket"

    acl    = "private"

}

Now I wanted to create folders inside the bucket, say Folder1.

I found the link for creating an S3 object. But this has a mandatory parameter source. I am not sure what this value have to since my intent is to create a folder inside the S3 bucket.

1 Answer

0 votes
by (44.4k points)

You can use the following to run terraform on macOS or Linux,

resource "aws_s3_bucket_object" "folder1" {

    bucket = "${aws_s3_bucket.b.id}"

    acl    = "private"

    key    = "Folder1/"

    source = "/dev/null"

}

In Windows, you can use an empty file. Using a folder that is a key prefix in S3, makes life easier to take out objects. Like S3 sync for instance.

Related questions

0 votes
1 answer
asked Jan 18, 2020 in AWS by R. Raman (790 points)
Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...