Terraform调用aws-cli时发生外部数据错误



尝试将aws cli调用作为terraformexternal data运行,但unmarshal string出现错误

Terraform:

data "external" "cognito" {
program = ["sh", "-c", "aws cognito-idp list-user-pool-clients --user-pool-id eu-west-xxx | jq '.UserPoolClients | .[] | select(.ClientName | contains("AmazonOpenSearchService")) | .ClientId'"] 
}

直接从bash运行命令返回:

"123456"

通过地形错误:

│ The data source received unexpected results after executing the program.
│ 
│ Program output must be a JSON encoded map of string keys and string values.
│ 
│ If the error is unclear, the output can be viewed by enabling Terraform's logging at TRACE level. Terraform documentation on logging: https://www.terraform.io/internals/debugging
│ 
│ Program: /bin/sh
│ Result Error: json: │ The data source received unexpected results after executing the program.
│ 
│ Program output must be a JSON encoded map of string keys and string values.
│ 
│ If the error is unclear, the output can be viewed by enabling Terraform's logging at TRACE level. Terraform documentation on logging: https://www.terraform.io/internals/debugging
│ 
│ Program: /bin/sh
│ Result Error: json: cannot unmarshal string into Go value of type map[string]string

当使用Terraform外部数据源运行临时脚本时,您需要返回一个有效的json对象(文档中还提到了字符串的映射(,而"123456"不是。你需要'{"clientId":"123456"}'之类的东西。

如果你想完全避开剧本,马克B在上面的评论中建议的是最好的方法

相关内容

  • 没有找到相关文章

最新更新