【发布时间】:2021-03-26 15:05:17
【问题描述】:
我想动态生成一个文件,将其压缩并使用 terraform 将其上传到 s3。以下是我目前所拥有的。
#Setup a local variable with docker container information
locals {
file_content = jsonencode({
"AWSEBDockerrunVersion" : "1",
"Image" : {
"Name" : "${var.aws_account_id}.dkr.ecr.${var.aws_region}.amazonaws.com/vin-${var.application}-api:${var.environment}",
"Update" : "true"
},
"Ports" : {
"ContainerPort" : 80,
"HostPort" : 80
}
})
}
#Generate the Dockerrun.aws.json with the container information and environment tag
resource "local_file" "docker_container_info" {
content = local.file_content
filename = "./${var.service_name}-${var.environment}-Dockerrun.aws.json"
}
#Zip the file
data "archive_file" "source" {
type = "zip"
source_dir = "./${var.service_name}-${var.environment}-Dockerrun.aws.json"
output_path = "./${var.service_name}-${var.environment}-Dockerrun.aws.json.zip"
depends_on = [
local_file.docker_container_info
]
}
/*
#Upload the zip file to s3 bucket under DockerRunFiles folder
resource "aws_s3_bucket_object" "file_upload" {
bucket = var.run_file_bucket
key = "${var.bucket_name}/${var.service_name}-${var.environment}-Dockerrun.aws.json.zip"
source = "${data.archive_file.source.output_path}"
}
*/
variable "aws_region" {
default = "us-east-1"
}
variable "environment" {
default = "lab"
}
variable "aws_environment" {
default = "lab"
}
variable "service_name" {
default = "service_name"
}
variable "application" {
default = "application_name"
}
variable "aws_account_id" {
default = "1234567890"
}
variable "bucket_name" {
default = "my_bucket"
}
我看到service_name-lab-Dockerrun.aws.json 文件正确生成,其中包含 json。但我得到的错误是Error: error archiving directory: could not archive directory that is a file: ./service_name-lab-Dockerrun.aws.json。 terraform data archive_file 是否只能压缩文件夹而不能压缩 json 文件?感谢帮助
版本详情:
Terraform v0.12.28
+ provider.archive v2.0.0
+ provider.local v2.0.0
【问题讨论】:
标签: amazon-web-services terraform terraform0.12+