HashiCorp Terraform 0.12 新特性抢鲜看:可靠的JSON语法

AUG 23 2018    MARTIN ATKINS

This is the eighth post of the series highlighting new features in Terraform 0.12.

As part of the lead up to the release of Terraform 0.12, we are publishing a series of feature preview blog posts. The post this week is on bringing a clear 1:1 mapping between JSON and HCL.

Terraform has accepted JSON as configuration in addition to HCL since version 0.1. However, the implementation of this prior to version 0.12 had many shortcomings. The HCL improvements in Terraform 0.12 include a clear 1:1 mapping between HCL and JSON, including much clearer error messages and support for comments!

These improvements make it easy to work with Terraform using HCL, JSON, or both.

HCL and JSON

Terraform has supported JSON as an alternate configuration format since its initial release in Terraform 0.1. Further, Terraform has supported mixingJSON and HCL configurations within the same module since version 0.1, as well. Both JSON and HCL are important first-class configuration formats for Terraform.

The JSON mapping in prior versions of Terraform had many shortcomings. In some cases, it felt as though JSON didn't feel like a first class solution in the tool. We have always considered JSON a first class input to Terraform and continue to do so, so a big part of Terraform 0.12 was having a clean 1:1 mapping between HCL and JSON, and ensuring every feature of HCL is supported in JSON.

Terraform 0.12 achieves these goals. In future versions of Terraform, we will also support native tooling to convert HCL to JSON and JSON to HCL cleanly (including comments). This gives additional tooling more power in working with Terraform configurations and also enables people to author configurations in whichever language they feel comfortable.

Error Message Improvements

In versions prior to 0.12, the configuration mapping to JSON was only weakly specified in documentation, there were many counter-intuitive mapping behaviors, and there was a tendency to silently ignore misshapen constructs that made debugging difficult.

Terraform 0.12 includes a new JSON configuration implementation that is more robust than prior versions to address these limitations. In particular, the JSON-based configuration decoder produces errors in any cases where the input cannot be mapped exactly onto the expected configuration structure.

The example below shows an invalid configuration the error produced in Terraform 0.12:

转载于:https://blog.51cto.com/13883466/2163793

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值