首页 > 解决方案 > 如何在 Terraform 的 EMR 集群中将 JSON 文件分配为 STEP?

问题描述

我正在 Terraform 中构建一个 EMR 集群,并且在 STEP 参数中我想加载一个描述步骤列表的 JSON 文件。

我在我的 main.tf 中试过这个:

ressource "aws_emr" "emr" {
  ...
  ...
  step = "${data.template_file.steps.rendered}"
}

data "template_file" "steps" {
  template = "${file("${path.module}/steps.json")}"
}

这是 JSON 文件:

[
{
    "action_on_failure" : "CONTINUE",
    "name"              : "step_name",
    "hadoop_jar_step" : {
        "jar" : "command-runner.jar",
        "args" : [
            "spark-submit",
            "s3://mybucket/src/pyspark/script1.py",
            "1",
            "68465131321321",
            "s3://mybucket/parquet",
            "s3://mybucket/result",
            "321",
            "65165165468587",
            "654"
        ]
    }
}
]

但是当我这样做时,terraform plan我得到了这个错误:

属性“step”的值不合适:需要的对象列表。

有什么问题 ?

谢谢你的帮助。

标签: amazon-web-servicesterraformamazon-emr

解决方案


好的,我在另一个网站上找到了解决方案,我会在这里发布,也许有一天它会对某人有所帮助

   resource "aws_emr_cluster" "cluster" {
  ...
  dynamic "step" {
    for_each = jsondecode(templatefile("steps.json", {}))
    content {
      action_on_failure = step.value.action_on_failure
      name              = step.value.name
      hadoop_jar_step {
        jar  = step.value.hadoop_jar_step.jar
        args = step.value.hadoop_jar_step.args
      }
    }
  }
  ...
}

因此,可以使用 JSON 文件作为 EMR 资源中步骤的源。


推荐阅读