Amazon web services 将字符串列表传递到模块中,然后创建阵列地形
我目前正在创建一个Terraform模块,用于创建一些ECS任务。我希望能够传递命令列表,以便为特定任务指定命令字段 我目前将我的列表传递到我的模块中,如下所示:Amazon web services 将字符串列表传递到模块中,然后创建阵列地形,amazon-web-services,terraform,amazon-ecs,Amazon Web Services,Terraform,Amazon Ecs,我目前正在创建一个Terraform模块,用于创建一些ECS任务。我希望能够传递命令列表,以便为特定任务指定命令字段 我目前将我的列表传递到我的模块中,如下所示: module "test" { source = "git@github.com:test/deploy.git" task_count = 3 entryPoints = [ "run, -c, /app/node/node_0, --bootnode, tru
module "test" {
source = "git@github.com:test/deploy.git"
task_count = 3
entryPoints = [
"run, -c, /app/node/node_0, --bootnode, true",
"run, -c, /app/node/node_1",
"run, -c, /app/node/node_2",
]
}
然后我想在这里将每个命令传递到它的任务中:
data "template_file" "test" {
template = file("${path.module}/templates/test.json.tpl")
count = var.task_count
vars = {
entryPoint = split(",", element(var.entryPoints, count.index)),
}
}
我希望元素(var.entryPoints,count.index)
意味着它将传入的第一个任务
“run”、“-c”、“/app/node/node\u 0”、“-bootnode”、“true”
然后进行第二项任务
“run”、“-c”、“/app/node/node_1”
等
但是,我收到了一个错误:
Error: Incorrect attribute value type
on .terraform/modules/test/ecs_task_definition.tf line 5, in data "template_file" "test":
5: vars = {
12: entryPoint = split(",", element(var.entryPoints, count.index)),
15: }
Inappropriate value for attribute "vars": element "entryPoint": string
required.
maint.tf
variable "entrypoints_list" {
default = [
"run, -c, /app/node/node_0, --bootnode, true",
"run, -c, /app/node/node_1",
"run, -c, /app/node/node_2",
]
}
locals {
entryPoints = [for key in var.entrypoints_list : split(",", key)]
}
data "template_file" "container_definition" {
count = length(local.entryPoints)
template = file("${path.module}/templates/container-definition.json.tpl")
vars = {
entryPoint = jsonencode(element(local.entryPoints,count.index))
}
}
output "container-definition" {
value = data.template_file.container_definition[*].rendered
}
container definition.json.tpl
{
"entryPoint": ${entryPoint}
}
地形图
+容器定义=[
+jsonencode(
{
+入口点=[
+“跑”,
+“-c”,
+“/app/node/node_0”,
+“--bootnode”,
+“真的”,
]
}
),
+jsonencode(
{
+入口点=[
+“跑”,
+“-c”,
+“/app/node/node_1”,
]
}
),
+jsonencode(
{
+入口点=[
+“跑”,
+“-c”,
+“/app/node/node_2”,
]
}
),
]
根据您的需求,您可以在模块中移动代码