使用terraform本地从S3下载文件



我正试图将文件从s3存储桶下载到运行terraform的服务器,这可能吗?我试过下面的代码

data "aws_s3_bucket_objects" "my_objects" {
bucket = "examplebucket"
}
data "aws_s3_bucket_object" "object_info" {
key    = "${element(data.aws_s3_bucket_objects.my_objects.keys, count.index)}"
bucket = "${data.aws_s3_bucket_objects.my_objects.bucket}"
}
provisioner "local-exec" {
content = "${data.aws_s3_bucket_object.object_info.body}"
}

当我运行terraform plan时,我得到以下错误

Error: Unsupported block type
on s3.tf line 11:
11: provisioner "local-exec" {
Blocks of type "provisioner" are not expected here.

我是不是遗漏了什么?如有任何帮助,我们将不胜感激。

只需使用local提供程序

data "aws_s3_bucket_objects" "my_objects" {
bucket = "examplebucket"
//prefix = "your_prefix"
}    
data "aws_s3_bucket_object" "object_info" {
count  = "${length(data.aws_s3_bucket_objects.my_objects.keys)}"
key    = "${element(data.aws_s3_bucket_objects.my_objects.keys, count.index)}"
bucket = "${data.aws_s3_bucket_objects.my_objects.bucket}"
}
resource "local_file" "foo" {
count    = "${length(data.aws_s3_bucket_objects.my_objects.keys)}"
content  = "${data.aws_s3_bucket_object.object_info[count.index].body}"
filename = "/path/to/file-${count.index}"
}

PS:确保您的对象具有人类可读的Content-Typebody字段仅适用于此类对象。

provisioner "local-exec"必须在某个资源中,并且没有参数content。您可以只在那里执行一些命令行或自定义脚本。见纪念碑https://www.terraform.io/docs/language/resources/provisioners/local-exec.html#example-使用

相关内容

  • 没有找到相关文章

最新更新