如何使用 terraform 在亚马逊 S3 存储桶中创建文件夹 [英] How to create a folder in an amazon S3 bucket using terraform

查看:34
本文介绍了如何使用 terraform 在亚马逊 S3 存储桶中创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用这个 link 在亚马逊 S3 中创建一个存储桶.

我使用以下代码创建了一个存储桶:

I used the following code to create a bucket :

resource "aws_s3_bucket" "b" {
    bucket = "my_tf_test_bucket"
    acl    = "private"
}

现在我想在存储桶内创建文件夹,比如 Folder1.

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

我找到了用于创建 S3 对象的链接.但这有一个强制性参数source.我不确定这个值是什么,因为我的目的是在 S3 存储桶内创建一个文件夹.

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.

推荐答案

对于在 Mac 或 Linux 上运行 terraform,以下将做你想做的

For running terraform on Mac or Linux, the following will do what you want

resource "aws_s3_bucket_object" "folder1" {
    bucket = "${aws_s3_bucket.b.id}"
    acl    = "private"
    key    = "Folder1/"
    source = "/dev/null"
}

如果您使用的是 Windows,则可以使用空文件.

If you're on windows you can use an empty file.

虽然人们对 s3 没有文件夹会很迂腐,但有许多操作可以让键前缀(也称为文件夹)的对象占位符使生活更轻松.例如 s3 同步.

While folks will be pedantic about s3 not having folders, there are a number of operations where having an object placeholder for a key prefix (otherwise called a folder) make life easier. Like s3 sync for example.

这篇关于如何使用 terraform 在亚马逊 S3 存储桶中创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆