将 JSON 字符串解码为地形图 [英] Decoding JSON string to terraform map

查看:20
本文介绍了将 JSON 字符串解码为地形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 HTTP 数据源从中检索数据内部服务.服务返回 JSON 数据.

I'm using the HTTP data source to retrieve data from an internal service. The service returns JSON data.

我无法插入返回的 JSON 数据并在其中查找数据.

I can't interpolate the returned JSON data and look up data in it.

例如:

模块 A

data "http" "json_data" {
    url = "http://myservice/jsondata"

    # Optional request headers
    request_headers {
       "Accept" = "application/json"
    }
}

output "json_data_key" {
    value = "${lookup(data.http.json_data.body, "mykey")}"
}

main.tf

provider "aws" {
   region = "${var.region}"
   version = "~> 0.1"
}

module "moduleA" {
   source = "../../../terraform-modules/moduleA"
}

resource "aws_instance" "example" {
    ami = "ami-2757f631"
    instance_type = "${module.moduleA.json_data_key}"
}

查找函数将无法提取 JSON 数据中的键.

The lookup function will fail to extract the key within the JSON data.

有没有办法将 JSON 数据解码为地形图?

Is there any way to decode the JSON data into a terraform map ?

推荐答案

好的,看来这样做的方法是使用外部数据,因为它返回一个 map一个json响应.https://www.terraform.io/docs/providers/external/data_source.html

Ok, so it seems to be that the way to do the is by using the external data, as it return a map from a json response. https://www.terraform.io/docs/providers/external/data_source.html

terraform 版本 v0.10.6

terraform version v0.10.6

这篇关于将 JSON 字符串解码为地形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆