如何将两个模板文件连接成一个文件,并在terraform中传递到ECS容器任务定义

如何将两个模板文件连接成一个文件,并在terraform中传递到ECS容器任务定义,terraform,Terraform,我有两个模板文件。我想将这些模板文件合并为一个,并将它们传递到aws\u ECS\u task\u definition资源中的ECS属性container\u definitions 地形版本=>v0.14.9 nginx.tpl.json: [ { "name": "nginx", "image": "public.ecr.aws/nginx/nginx:latest",

我有两个模板文件。我想将这些模板文件合并为一个,并将它们传递到aws\u ECS\u task\u definition资源中的ECS属性container\u definitions

地形版本=>v0.14.9

nginx.tpl.json:

 [
    {
        "name": "nginx",
        "image": "public.ecr.aws/nginx/nginx:latest",
        "portMappings": [
            {
                "containerPort": 80,
                "hostPort": 80,
                "protocol": "tcp"
            }
        ]
    }
 ]
 [
    {
        "name": "redis",
        "image": "public.ecr.aws/peakon/redis:6.0.5",
        "portMappings": [
            {
                "containerPort": 6379,
                "hostPort": 6379,
                "protocol": "tcp"
            }
        ]
    }
 ]
redis.json.tpl:

 [
    {
        "name": "nginx",
        "image": "public.ecr.aws/nginx/nginx:latest",
        "portMappings": [
            {
                "containerPort": 80,
                "hostPort": 80,
                "protocol": "tcp"
            }
        ]
    }
 ]
 [
    {
        "name": "redis",
        "image": "public.ecr.aws/peakon/redis:6.0.5",
        "portMappings": [
            {
                "containerPort": 6379,
                "hostPort": 6379,
                "protocol": "tcp"
            }
        ]
    }
 ]
当像下面这样手动组合两个模板文件时,它会工作。但在地形上或是出错

 [
    {
        "name": "nginx",
        "image": "public.ecr.aws/nginx/nginx:latest",
        "portMappings": [
            {
                "containerPort": 80,
                "hostPort": 80,
                "protocol": "tcp"
            }
        ]
    },
    {
        "name": "redis",
        "image": "public.ecr.aws/peakon/redis:6.0.5",
        "portMappings": [
            {
                "containerPort": 6379,
                "hostPort": 6379,
                "protocol": "tcp"
            }
        ]
    }
 ]

错误:
查找对象键字符串开头的无效字符“}”


有人能帮我一下吗?

更新

从文件中删除括号

    {
        "name": "nginx",
        "image": "public.ecr.aws/nginx/nginx:latest",
        "portMappings": [
            {
                "containerPort": 80,
                "hostPort": 80,
                "protocol": "tcp"
            }
        ]
    }


然后将其替换为“%s%s”
。似乎您缺少逗号:
“[%s,%s]”

如果您手动执行,它会工作吗?因此,问题只在于自动连接?@Marcin,是的。如果我手动操作,它会工作。你能显示手动加入的文件吗?@Marcin,文件“[{”name:“nginx”,“image:“public.ecr.aws/nginx/nginx:latest”,“portMappings:[{”containerPort:“80”,“hostPort:”80,“protocol:“tcp”}]},{“名称”:“redis”,“图像”:“public.ecr.aws/peakon/redis:6.0.5”,“端口映射”:[{“containerPort”:6379,“主机端口”:6379,“协议”:“tcp”}]}]“你能用格式正确的例子来编辑你的问题吗?”我试着用逗号。不适合我。它对您有用吗?@Jwary逗号是您在示例中使用的。我在手动组合两个JSON模板文件时使用了逗号。但是使用
“%s,%s”
没有帮助。@Jwary我更新了答案。它起作用了。非常感谢。

    {
        "name": "redis",
        "image": "public.ecr.aws/peakon/redis:6.0.5",
        "portMappings": [
            {
                "containerPort": 6379,
                "hostPort": 6379,
                "protocol": "tcp"
            }
        ]
    }