当前位置:主页 > 资料 >

Terraform 0.12 Releasing This Summer With for Loops and Firs
栏目分类:资料   发布日期:2018-08-03   浏览次数:

导读:本文为去找网小编(www.7zhao.net)为您推荐的Terraform 0.12 Releasing This Summer With for Loops and First-Class Expressions,希望对您有所帮助,谢谢! HashiCorp will be releasing later this summer. This release include

本文为去找网小编(www.7zhao.net)为您推荐的Terraform 0.12 Releasing This Summer With for Loops and First-Class Expressions,希望对您有所帮助,谢谢! 内容来自www.7zhao.net



HashiCorp will be releasing later this summer. This release includes a number of new, heavily requested improvements to Terraform based on community feedback and input. Most notably among the changes are: first-class expressions, the for expression, and conditionals. Upgrading to the new version may cause breaking changes for some users of Terraform. 本文来自去找www.7zhao.net

First-class expressions will simplify writing Terraform scripts and also add additional benefits to the language. In the current version, expressions need to be wrapped in double quotes and are treated as interpolation sequences. With the release of 0.12, expressions are now a native part of the language and can be written directly:

欢迎访问www.7zhao.net

variable "ami" {}

# Terraform 0.11 and earlier
resource "aws_instance" "example" {
   ami = "${var.ami}"
}

# Terraform 0.12
resource "aws_instance" "example" {
   ami = var.ami
} 
内容来自www.7zhao.net

This change also allows the usage of list and map syntax via [...] and {...} directly within expressions. Coupling this with the new for expression will allow for dynamic filtering and transformations of lists and maps within your configurations. An optional if clause can be included to allow for filtering of the result: 内容来自www.7zhao.net

# Terraform 0.12

output "instance_public_ip_addresses" {
   value = {
      for instance in aws_instance.example:
         instance.id => instance.public
         if instance.associate_public_ip_address
   }
} 

本文来自去找www.7zhao.net

While the conditional operator ( … ? … : …) has been in Terraform for some time, its use was limited as both portions of the return value would always be evaluated. With the upcoming release, that has been corrected and the conditional operator now behaves as you would expect. The other major improvement is that the conditional operator can be leveraged with any type. 内容来自www.7zhao.net

# Terraform 0.12

locals {
   first_id = length(azurerm_virtual_machine.example) > 0 ? azurerm_virtual_machine.example[0].id : ""
} 欢迎访问www.7zhao.net 

In current versions of Terraform the above example would fail as both return values are evaluated regardless of what the expression resolves to.

内容来自www.7zhao.net

Introducing these changes into Terraform required a reworking of the underlying configuration language. While the Terraform Core Team states they have worked to minimize breaking changes, an has been prepared to assist with the move to version 0.12. It is recommended that you in your scripts ahead of the release. They feel that the focus on configuration changes for this release will minimize breaking changes going forward as well as allow for quicker turnaround on future features. They are  and are  regarding these and future improvements.

copyright www.7zhao.net

www.7zhao.net


本文原文地址:http://www.infoq.com/news/2018/08/terraform-improvements

以上为Terraform 0.12 Releasing This Summer With for Loops and First-Class Expressions文章的全部内容,若您也有好的文章,欢迎与我们分享! 本文来自去找www.7zhao.net

Copyright ©2008-2017去找网版权所有   皖ICP备12002049号-2 皖公网安备 34088102000435号   关于我们|联系我们| 免责声明|友情链接|网站地图|手机版