0

我正在使用 terraform 来管理 ibm 云资源。我正在为 api 网关方式创建 api。

但是,资源需要一个 json 文件及其路径。我必须为所有不同的环境和地区修改 json 文件。

resource "ibm_api_gateway_endpoint" "endpoint"{
    service_instance_crn = ibm_resource_instance.apigateway.id
   open_api_doc_name    = "${path.module}/${var.environment}-api-definitions.yaml"
}

它以这种方式与 yml(或 json)文件一起工作。如果我对 open_api_doc 使用 jsonencode 或 tempfile,我会收到一个错误,指出 open_api_doc_name 需要 json,yml 文件。有没有办法将 jsonencode 转换为文件路径?

4

1 回答 1

0

open_api_doc_name资源中的属性ibm_api_gateway_endpoint不接受文件作为字符串。它只接受文件路径/位置如果你想使用jsonencode,可能你可以利用local_file资源来创建一个文件并在端点资源中使用该文件。有些东西喜欢..

resource "local_file" "test" {
    content     = jsonencode({"key"="value"})
    filename = "${path.module}/test.json"
}
resource "ibm_api_gateway_endpoint" "file_endpoint" {
  service_instance_crn = ibm_resource_instance.apigateway.id
  name                 = var.endpoint_name
  managed              = true
  open_api_doc_name    = local_file.test.filename
  type                 = var.action_type
}
于 2021-03-22T07:30:31.637 回答