@ラムは正しいです。source_dir
とsource
を同じarchive_file
ブロック内で使用することはできません。
config_json.tpl
{"test": "${override}"}
テラフォーム 12.x
# create the template file config_json separately from the archive_file block
resource "local_file" "config" {
content = templatefile("${path.module}/config_json.tpl", {
override = "my value"
})
filename = "${path.module}/lambda/etc/config.json"
}
テラフォーム 11.x
data "template_file" "config_json" {
template = "${file("${path.module}/config_json.tpl")}"
vars = {
override = "my value"
}
}
# create the template file config_json separately from the archive_file block
resource "local_file" "config" {
content = "${data.template_file.config_json.rendered}"
filename = "${path.module}/lambda/etc/config.json"
}
次
# now you can grab the entire lambda source directory or specific subdirectories
data "archive_file" "lambdazip" {
type = "zip"
output_path = "lambda_launcher.zip"
source_dir = "lambda/"
}
テラフォームの実行
$ terraform init
$ terraform apply
data.template_file.config_json: Refreshing state...
data.archive_file.lambdazip: Refreshing state...
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ local_file.config
id: <computed>
content: "{\"test\": \"my value\"}\n"
filename: "/Users/user/lambda/config.json"
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
local_file.config: Creating...
content: "" => "{\"test\": \"my value\"}\n"
filename: "" => "/Users/user/lambda/config.json"
local_file.config: Creation complete after 0s (ID: 05894e86414856969d915db57e21008563dfcc38)
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
zip ファイルの内容
$ unzip -l lambda_launcher.zip
Archive: lambda_launcher.zip
Length Date Time Name
--------- ---------- ----- ----
21 01-01-2049 00:00 etc/config.json
22 01-01-2049 00:00 node_modules/index.js
--------- -------
43 2 files