HashiCorp Terraform 1.5 is now generally available, featuring a config-driven import workflow and a new language primitive for infrastructure validations.
We’re excited to announce that HashiCorp Terraform 1.5 is now generally available, ready for download, and available for use in Terraform Cloud. Terraform is the standard infrastructure as code tool for multi-cloud provisioning and automation at any scale. This release brings two significant new features: a config-driven import workflow and check blocks. Config-driven import is a new declarative workflow to add existing resources into Terraform state and solves the limitations of the existing import command. Checks are a new way to perform functional validation of provisioned infrastructure to ensure the real world matches expectations.
Bringing existing infrastructure under management by Terraform is a common task when onboarding new teams and applications into a Terraform-based workflow. This often occurs as part of a standardization effort or during mergers and acquisitions. Until now, the only way to do this was with the terraform import
command. But this command has limitations:
With Terraform 1.5, we have introduced a completely new config-driven import mechanism. A new top-level import
block allows import operations to be defined in code. This means that import operations can be executed in bulk and are now part of the standard plan and apply cycle. Import is now a plannable operation, not a state operation, which eliminates the risk of unexpected state modification.
Better yet, Terraform 1.5 also introduces automatic code generation for imported resources. This dramatically reduces the amount of time you need to spend writing code to match the imported resources. As one of our customers put it, “this is going to save us weeks and weeks of work.”
The import block takes two parameters: the ID of the cloud resource to be imported and the HCL address for the new resource block. Here’s an example of an import block for an Amazon EC2 instance:
Once import blocks are added to your Terraform code, execute a plan with the new -generate-config-out
parameter to automatically create the matching resource blocks in a file you specify (example: terraform plan -generate-config-out=generated_resources.tf
). After reviewing the generated code, simply run a normal apply operation to complete the import to state.
Follow the updated Import Terraform Configuration tutorial to get hands-on with the new import workflow and learn more in the documentation.
A common challenge for Terraform users and module authors is having confidence that the provisioned infrastructure is functioning as expected. Terraform 1.2 added preconditions and postconditions which allow you to codify custom validations with contextual error messages in Terraform configurations. These conditions exist at a data source or individual resource level, and they will stop a plan or apply operation if they fail.
These custom conditions are great for validating assumptions and guarantees for individual data sources, resources, and outputs. But we’ve also heard from the community and our customers that there is a need for more holistic functional validation after infrastructure is provisioned.
With Terraform 1.5 we are introducing a new validation mechanism to address these needs: the check
block. Checks are a new top-level construct which gives Terraform practitioners and module authors additional flexibility to define assertions within Terraform code. While there is overlap between the use cases for postconditions and checks, the check block has several notable differences:
In following example, a scoped data source is defined within the check block to validate the status of a provisioned web application:
Learn more about check blocks and assertions in the Terraform language documentation, and check out the new tutorial, Use checks to validate infrastructure to try it yourself.
For more details and to learn about all of the enhancements in Terraform 1.5, please review the full HashiCorp Terraform 1.5 changelog.
As always, this release wouldn't have been possible without all of the great community feedback we've received via GitHub issues and from our customers. Thank you!
Terraform Enterprise now supports more flexible deployment options for self-hosted environments, including cloud-managed Kubernetes services.
Assigning agents at the organization level provides a faster, more consistent, and scalable approach to agent pool configuration.
Learn how creating a golden image pipeline can help unify and streamline your imaging and provisioning workflows throughout your infrastructure estate.