Terraform 1.5.0 update information

This is Matsuda (@msy_mtd_a5) from the Service Reliability Group (SRG) of the Technology Division.
#SRGThe Service Reliability Group primarily provides comprehensive support for the infrastructure surrounding our media services, focusing on improving existing services, launching new ones, and contributing to open-source software (OSS).
This article summarizes the update information for Terraform version 1.5. We hope it will be helpful in catching up.
 
 

Enhanced validation process using check blocks


 
This block displays an error message based 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 the plan is executed.
If a condition is met, Check Block only displays an error message; it does not have a function to cancel the plan or apply process.
 
If you want to cancel the process, use the Postcondition Block implemented in version 1.2.
 
The following is recommended regarding how to use Custom Conditions such as Postconditions and Check Blocks:
  • To verify the entire infrastructure, use Check Block.
  • If you want to guarantee a single resource based on the resource settings, use Postcondition
 
An example of using Check Block in AWS Providers is detecting unused IAM roles.
 

config-driven import using Import Block


It is now possible to define import processes that were previously handled by commands such as the `terraform import` command.
 
Define the resource block you want to import, and specify the resource in the `to` attribute of the import block.
You need to specify an import ID that uniquely identifies the resource in question. For example, for aws_instance, you would specify the instance ID.
 

Generate Terraform configuration for imported resources.


By using `terraform plan -generate-config-out`, it is now possible to generate Terraform configurations for imported resources.
 
You can define an import block and generate the configuration using `terraform plan -generate-config-out`.
 
 
However, when generating a resource setting that has options such as specifying only one of the attributes, defining both will result in an error, so it seems necessary to correct this beforehand.
 

Adding the plantimestamp function


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

Adding the strcontains function


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

In conclusion


Of all the updates in this release, the Import Block was the one I was personally most happy about.
 
SRG is looking for new team members. If you are interested, please contact us here.