1
null_resource
を使用してマップ変数をtriggers
に列挙し、この列挙の結果を別のリソースに使用しようとしています。null_resourceとトリガーを使用してマップ変数を列挙する
resource "null_resource" "dummy" {
count = "${length(var.file_map)}"
triggers {
filename = "${element(keys(var.file_map), count.index)}"
content = "${var.file_map[element(keys(var.file_map), count.index)]}"
}
}
variable "file_map" {
type = "map"
default = {
"foo.txt" = "foo"
"bar.txt" = "bar"
}
}
出力:
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:
+ null_resource.dummy[0]
id: <computed>
triggers.%: "2"
triggers.content: "bar"
triggers.filename: "bar.txt"
+ null_resource.dummy[1]
id: <computed>
triggers.%: "2"
triggers.content: "foo"
triggers.filename: "foo.txt"
Plan: 2 to add, 0 to change, 0 to destroy.
をしかし、私は別のリソースに列挙の結果を使用しようとすると、それは失敗します。
これは動作します
resource "local_file" "some_files" {
content = "${null_resource.dummy.triggers.content}"
filename = "${null_resource.dummy.triggers.filename}"
}
resource "null_resource" "dummy" {
count = "${length(var.file_map)}"
triggers {
filename = "${element(keys(var.file_map), count.index)}"
content = "${var.file_map[element(keys(var.file_map), count.index)]}"
}
}
variable "file_map" {
type = "map"
default = {
"foo.txt" = "foo"
"bar.txt" = "bar"
}
}
出力:
Error running plan: 1 error(s) occurred:
* local_file.some_files: 1 error(s) occurred:
* local_file.some_files: Resource 'null_resource.dummy' not found for variable
'null_resource.dummy.triggers.content'
動作させる方法はありますか?
うわー、ちょうどうわー。どうもありがとうございます。私は[splat hack](https://github.com/hashicorp/terraform/issues/11566#issuecomment-289417805)を使用しようとしていましたが失敗しました。今はすべて理にかなっています。 – beatcracker