Amazon web services 如何在Terraform中启用CloudWatch日志记录和X-ray for stepfunction?

Amazon web services 如何在Terraform中启用CloudWatch日志记录和X-ray for stepfunction?,amazon-web-services,terraform,terraform-provider-aws,aws-step-functions,aws-xray,Amazon Web Services,Terraform,Terraform Provider Aws,Aws Step Functions,Aws Xray,在AWS控制台中,我们可以轻松地为step function statemachine启用cloudwatch日志记录和X射线,但我希望我的资源完全由Terraform管理,从以下页面: 看起来Terraform目前不支持这一点(另请参见:) 有人知道是否有任何解决办法来实现这一点吗?我真的希望能够从Terraform启用cloudwatch日志和X射线。我找不到这方面的太多信息。有人能帮忙吗?非常感谢。更新:这是最近发布的功能 相应的文档链接: 您可以将用于启用日志记录的命令包装在链接的问题中

在AWS控制台中,我们可以轻松地为step function statemachine启用cloudwatch日志记录和X射线,但我希望我的资源完全由Terraform管理,从以下页面:

看起来Terraform目前不支持这一点(另请参见:)


有人知道是否有任何解决办法来实现这一点吗?我真的希望能够从Terraform启用cloudwatch日志和X射线。我找不到这方面的太多信息。有人能帮忙吗?非常感谢。

更新:这是最近发布的功能

相应的文档链接:

您可以将用于启用日志记录的命令包装在链接的问题中,如下所示:

先决条件:

aws cli/2.1.1
之前


{
“StateMachiner”:“arn:aws:states:us-east-1:1234567890:stateMachine:mystatemachine”,
“名称”:“我的状态机”,
“状态”:“活动”,
“定义”:“{\n\”注释\“:\”使用AWS Lambda函数的Amazon州语言的Hello World示例\“,\n\”StartAt \“:”HelloWorld \“,\n\”州\“:{\n\”HelloWorld \“:{\n\”类型\“:”通过\“,\n\”结束\“:真\n}\n}\n}\n}\n}\n”,
“roleArn”:“arn:aws:iam::1234567890:role/service role/StepFunctions-MyStateMachine-role-a6146d54”,
“类型”:“标准”,
“creationDate”:1611682259.919,
“日志配置”:{
“关卡”:“关”,
“includeExecutionData”:错误
}
}

目前,这仍然是Terraform上正在进行的功能请求,您可以在此github上跟踪状态。

嘿,谢谢@Samcubble,启用X射线怎么样?我们是否有相应的命令,或者我们可以使用CloudFormation?@Cecilia根据aws cli,您可以传递各种选项,包括启用x射线的
--跟踪配置
。我的答案是告诉您如何使用terrafrom
null\u resource
解决这个问题谢谢,这只是一个关于
${state machine arn}
的后续问题,如果我在
locals
中指定了状态机名称,我应该使用
${local.statemachine name.arn}
?为什么我们需要
设置-euo pipefail
?@Cecilia这是变革公关@Cecilia我想你的麻烦已经解决了。
resource "aws_sfn_state_machine" "sfn_state_machine" {
  name     = "mystatemachine"
  role_arn = "arn:aws:iam::1234567890:role/service-role/StepFunctions-MyStateMachine-role-a6146d54"

  definition = <<EOF
{
  "Comment": "A Hello World example of the Amazon States Language using an AWS Lambda Function",
  "StartAt": "HelloWorld",
  "States": {
    "HelloWorld": {
      "Type": "Pass",
      "End": true
    }
  }
}
EOF
}

resource "aws_cloudwatch_log_group" "yada" {
  name = "/aws/vendedlogs/states/myloggroup"
}

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.yada.arn}:*"
                    }
                }
            ]
            }
    PARAMS
    }
  provisioner "local-exec" {
    command = <<EOT
set -euo pipefail

aws stepfunctions update-state-machine --state-machine-arn ${self.triggers.state_machine_arn}  --tracing-configuration enabled=true --logging-configuration='${self.triggers.logs_params}'

EOT
    # interpreter = ["bash"]
  }
}