Json parsing error when running 'aws stepfunctions update-state-machine' via Terraform
Asked Answered
J

1

0

I'm following the answer in this question, I tried to enable x-ray and it works, code I used:

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"
  }
}

Now I want to enable cloudwatch logging ' --logging-configuration=xxx' part, but I keep getting errors. This is what I have tried:

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}'"
  }
}

Then when I apply in Terraform, it gave me error:

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: {

It's comlaining the invalid format of the aws command, I couldn't find any examples online, can someone help please?

Junco answered 28/1, 2021 at 13:48 Comment(2)
It would be helpful to see both the terraform and a bit more of the output as text.Charkha
Hi @Charkha I updated my question, I managed to get the 'x-ray enable' working, but have issue on the 'logging enable' part, seems like it's complaining about the json format?Junco
C
0

Having never used terraform with windows I'm a bit unclear, but i suspect local-exec is using cmd rather than bash to run the aws-cli. There may be differences in how things are escaped and interpreted? Try telling terraform to use 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"]
  }
Charkha answered 28/1, 2021 at 16:1 Comment(5)
Have you tested on your end? It's giving me error 'An argument named "interpreter" is not expected here.'Junco
Do you know what json format I need to pass to '--logging-configuration', I believe it's the json issueJunco
Odd.. I did have some weird spacing in example. What version of terraform are you using? interpreter is right in docs: terraform.io/docs/language/resources/provisioners/…Charkha
I'm using terraform v0.13.4Junco
I couldn't use bash it will give me error something like can't find bash, it's using CMDJunco

© 2022 - 2024 — McMap. All rights reserved.