Terraform 1.5.0, released on June 12, 2023, unveils a suite of exciting features, enhancements, and necessary upgrades. As a top Infrastructure as Code (IaC) tool, Terraform consistently rolls out updates to improve user experience and enable efficient infrastructure management. Let's delve into the details of this update.

Terraform 1.5

New Features Terraform 1.5.0

1. Check Blocks for Validating Infrastructure


The new check blocks feature allows module and configuration authors to write standalone blocks to validate assertions about their infrastructure. These independent check blocks need to include at least one assert block, with the option for multiple. Each assert block contains a condition expression and an error_message expression that aligns with Custom Condition Checks.

In addition, check blocks can optionally load a scoped data source, which resembles existing data sources but is only referenceable within their check block. In comparison to precondition and postcondition blocks, Terraform will not stop execution if the scoped data block fails, or if an assertion fails. This feature empowers practitioners to continually validate the state of their infrastructure outside the usual lifecycle management cycle.

2. Import Blocks for Importing Infrastructure


With the introduction of import blocks, root module authors can now inform Terraform of their intent to take over an existing resource. Import is now a plannable, configuration-driven action, integrated into a normal plan. Running `terraform plan` will provide a summary of the resources that Terraform intends to import, alongside any other plan changes. The existing `terraform import` CLI command remains unaffected.

This feature is an early version of the import block functionality and user feedback is actively encouraged for future development. Please note that the import block currently doesn't support interpolation in the `id` field, which needs to be a string.

3. Generating Configuration for Imported Resources

This new feature simplifies the process of creating configuration templates when importing existing resources into Terraform. It adds a new flag `-generate-config-out=PATH` to `terraform plan`. When this flag is used, Terraform generates HCL configuration for any resource within an import block that lacks associated configuration, writing it to a new file at the specified path. Always review the generated configuration and make necessary edits before applying.

4. Additional Functionalities


Two new functions have been added: `plantimestamp` and `strcontains`. The `plantimestamp` function gives the timestamp at plan time, similar to the `timestamp` function which gives the timestamp at apply time. The `strcontains` function checks if a specific substring exists within a given string.

Upgrade Notes Terraform 1.5.0

This version marks the end of official support for macOS 10.13 High Sierra and 10.14 Mojave, as well as Windows 7, 8, Server 2008, and Server 2012. Future versions of Terraform may not work properly on these older versions of macOS and Windows.

For Linux users (and other non-macOS Unix platforms), Terraform will now recognize the trust-ad option in /etc/resolv.conf. If set, outgoing DNS requests will have the "authentic data" option enabled, aligning with the behavior of the GNU libc resolver.

Enhancements

Terraform CLI's local operations mode will now try to store state snapshots to the state storage backend periodically during the apply step. This reduces the potential for lost data if the Terraform process is abruptly terminated.

If Terraform CLI receives SIGINT during the apply step, it will immediately try to save the most recent state snapshot to the state storage backend.

The pg backend now supports the PG_CONN_STR, PG_SCHEMA_NAME, PG_SKIP_SCHEMA_CREATION, PG_SKIP_TABLE

_CREATION, and PG_SKIP_INDEX_CREATION environment variables.

Bug Fixes

The `terraform init` command has been fixed to avoid crashing with an invalid blank module name. Additionally, a typo in the error message raised when using `-target` to exclude a moved object has been corrected.

This update underlines Terraform's commitment to providing a robust and user-friendly IaC tool. The new features are poised to improve infrastructure validation, streamline resource import, and enhance overall operational efficiency. The next version is anticipated to carry on this trend with more improvements and enhancements. Stay tuned for the next updates and happy Terraforming!

Conclusion 

In conclusion, the release of Terraform 1.5.0 is a significant leap forward, not only introducing useful new features but also refining the existing capabilities. The ability to continually validate the state of infrastructure and easily import resources into Terraform expands the tool's capacity for infrastructure management. The improvements to the CLI's local operations mode and the introduction of the new functions bring additional convenience and possibilities. As we look forward to future updates, it's crucial to keep up with these changes to make the most of what Terraform has to offer. The future of Infrastructure as Code continues to be bright and dynamic with tools like Terraform leading the charge.