我正试图将文件从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-Type
,body
字段仅适用于此类对象。
provisioner "local-exec"
必须在某个资源中,并且没有参数content
。您可以只在那里执行一些命令行或自定义脚本。见纪念碑https://www.terraform.io/docs/language/resources/provisioners/local-exec.html#example-使用