Terraform 使用 Consul 键/值存储中的内容将文件推送到 github

问题描述 投票:0回答:1

我正在尝试获取 Consul 上的密钥内容(这是一个 json 对象)以转换为我需要使用 Consul-Terraform-Sync 推送到 Github 的文件内容。 Consul 上的路径由 UUID 组成,该 UUID 作为触发服务的元变量提供。

data "consul_keys" "json_file_key" {
  for_each = var.services

  key {
    name    = "json_file"
    path    = "path/with/${lookup(each.value.meta, "uuid")}/to/json_file"
  }
}

resource "github_repository_file" "repo_on_github" {
  for_each = var.services

  repository          = "my-repo"
  branch              = "main"
  file                = "path/to/json/on/github/repo"
  content             = jsondecode(data.consul_keys.json_file_key[each.key].id)
  commit_message      = "Managed by Terraform - UUID: ${lookup(each.value.meta, "uuid")}"
}

产生错误:

Call to function "jsondecode" failed: unexpected EOF.

我错过了什么?

git github terraform devops consul
1个回答
0
投票

我认为问题出在您尝试检索的 Consul 密钥的内容上。错误消息“unexpected EOF”通常意味着被解析为 JSON 的内容格式不正确。

为了调试这个,我建议打印 Consul 密钥的内容以确保它确实是一个有效的 JSON 对象。在 github_repository_file 资源之前添加此代码块:

output "json_content" {
  value = data.consul_keys.json_file_key[each.key].id
}
© www.soinside.com 2019 - 2024. All rights reserved.