Terraform 1.5.0 update information

This is Matsuda (@msy_mtd_a5) from the Service Reliability Group (SRG) of the Technology Headquarters.
#SRG(Service Reliability Group) mainly provides cross-sectional support for the infrastructure of our media services, improving existing services, launching new ones, contributing to OSS, etc.
This article summarizes the updates for Terraform version 1.5. I hope it will help you catch up.
 
 

Improved verification process with Check Block


 
This block can display an error message depending on the attributes of the specified resource.
In the following example, if https://www.terraform.io returns a status_code other than 200, the message "https://www.terraform.ioreturned an unhealthy status code" will be displayed after plan execution.
If the conditions are matched, Check Block simply displays an error message and does not have the functionality to stop plan or apply.
 
If you want to abort the operation, use the Postcondition Block implemented in 1.2.
 
The following is a recommended way to distinguish between Custom Conditions such as Postconditions and Check Blocks.
  • Check Block to validate your entire infrastructure
  • Postconditions: If you want to guarantee a single resource based on a resource configuration
 
An example of using Check Block in AWS Provider is to detect unused IAM roles.
 

Config driven imports with Import Block


It is now possible to define import processes that were previously performed using the terraform import command, etc.
 
Define the resource block you want to import and specify the resource in the to section of the import block.
You need to specify an import ID that can uniquely identify the resource. For example, if you want to use aws_instance, specify the instance ID.
 

Generate Terraform configuration for imported resources


You can now generate Terraform configurations for imported resources by using terraform plan -generate-config-out.
 
You can define an import block and generate the configuration with terraform plan -generate-config-out.
 
 
However, when generating a resource setting that has an option where you can only specify one of the attributes, it seems necessary to correct this in advance, as both will be defined and an error will occur.
 

Add plantimestamp function


A plantimestamp function has been added that returns the date and time when the plan was executed in RFC 3339 format.
It can be used in combination with Check Block to check for certificate expiration, etc.
 

Added strcontains function


The strcontains function has been added, which checks whether a string contains a specified string.
The following is quoted from Terraform Configuration Language Functions strcontains
 
 

Conclusion


Import Block was the update I was most happy about in this update.
 
SRG is looking for people to work with us. If you are interested, please contact us here.