【问题标题】:Json parsing error when running 'aws stepfunctions update-state-machine' via Terraform通过 Terraform 运行“aws stepfunctions update-state-machine”时出现 Json 解析错误
【发布时间】:2021-05-02 10:10:27
【问题描述】:

我正在关注this question 中的答案,我尝试启用 X 射线并且它有效,我使用的代码:

resource "null_resource" "enable_step_function_logging" {
  triggers = {
state_machine_arn = aws_sfn_state_machine.sfn_state_machine.arn
  }
provisioner "local-exec" {
  command = "aws stepfunctions update-state-machine --state-machine-arn ${self.triggers.state_machine_arn} --tracing-configuration enabled=true"
  }
}

现在我想启用 cloudwatch 日志记录 '--logging-configuration=xxx' 部分,但我不断收到错误消息。这是我尝试过的:

resource "null_resource" "enable_step_function_logging" {
  triggers = {
    state_machine_arn = aws_sfn_state_machine.sfn_state_machine.arn
    logs_params       = <<PARAMS
      {
        "level":"ALL",
        "includeExecutionData":true,
        "destinations":[
            {
                "cloudWatchLogsLogGroup":{
                    "logGroupArn":"${aws_cloudwatch_log_group.sfn_cloudwatch_log_group.arn}:*"
                    }
                }
            ]
            }
    PARAMS
  }
  provisioner "local-exec" {
    command     = "aws stepfunctions update-state-machine --state-machine-arn ${self.triggers.state_machine_arn}  --tracing-configuration enabled=true --logging-configuration='${self.triggers.logs_params}'"
  }
}

然后当我在 Terraform 中申请时,它给了我错误:

Error: Error running command 'aws stepfunctions update-state-machine --state-machine-arn arn:aws:states:us-east-1:xxxxxxxxx:stateMachine:xxxxxxxxstate-machine  --tracing-configuration enabled=true --logging-configuration='      {
        "level":"ALL",
        "includeExecutionData":true,
        "destinations":[
            {
                "cloudWatchLogsLogGroup":{
                    "logGroupArn":"arn:aws:logs:us-east-1:xxx:log-group:/aws/vendedlogs/states/xxxxxxx-Logs:*"
                    }
                }
            ]
            }
'': exit status 252. Output:
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

Unknown options: {

这是抱怨aws命令的格式无效,我在网上找不到任何示例,有人可以帮忙吗?

【问题讨论】:

  • 将 terraform 和更多的输出视为文本会很有帮助。
  • 嗨@thekbb 我更新了我的问题,我设法让“启用 X 射线”工作,但在“启用日志记录”部分有问题,好像它在抱怨 json 格式?

标签: terraform git-bash terraform-provider-aws aws-step-functions aws-xray


【解决方案1】:

从来没有在 windows 上使用过 terraform 我有点不清楚,但我怀疑 local-exec 正在使用 cmd 而不是 bash 来运行 aws-cli。事物的转义和解释方式可能有所不同?尝试告诉 terraform 使用 bash:

  provisioner "local-exec" {
    command     = "aws stepfunctions update-state-machine --state-machine-arn ${self.triggers.state_machine_arn}  --tracing-configuration enabled=true --logging-configuration='${self.triggers.logs_params}'"
    interpreter = ["bash", "-c"]
  }

【讨论】:

  • 你测试过吗?它给了我错误'这里不需要一个名为“解释器”的参数。'
  • 你知道我需要传递什么json格式给'--logging-configuration',我相信是json问题
  • 奇怪.. 在示例中我确实有一些奇怪的间距。您使用的是什么版本的 terraform?解释器在文档中是正确的:terraform.io/docs/language/resources/provisioners/…
  • 我正在使用 terraform v0.13.4
  • 我无法使用bash,它会给我一些错误,例如找不到bash,它正在使用CMD
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-01
  • 1970-01-01
  • 2023-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多