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) is a group that mainly provides cross-sectional support for the infrastructure of our media services, improving existing services, launching new ones, and contributing to OSS.
This article summarizes the update information for Terraform version 1.5. We hope it will help you catch up.
 
 

Strengthening validation processing 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 met, Check Block simply displays an error message and does not have the functionality to stop plan or apply.
 
If you want to abort it, use the Postcondition Block implemented in 1.2.
 
The following are recommended ways to use 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 the resource configuration
 
An example of using Check Block with AWS Provider is the detection of 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.
 
Define the resource block you want to import and specify the resource in the to field in the import block.
You must specify an import ID that can uniquely identify the resource. For example, if you are using aws_instance, specify the instance ID.
 

Generate Terraform configuration for the imported resource


You can now generate Terraform configuration 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 specify only one of the attributes, both will be defined, which will result in an error, so it seems that you will need to correct this in advance.
 

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.
 

Add strcontains function


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

Conclusion


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