Latest in branch 1.7
1.7.5
Released 13 Mar 2024
(2 years ago)
SoftwareTerraform
Version1.7
Status
End of life
Initial release1.7.0
17 Jan 2024
(2 years ago)
Latest release1.7.5
13 Mar 2024
(2 years ago)
End of security fixes26 Jun 2024
(Ended 1 year, 11 months ago)
Release noteshttps://github.com/hashicorp/terraform/blob/v1.7/CHANGELOG.md
Source codehttps://github.com/hashicorp/terraform/tree/v1.7
Documentationhttps://developer.hashicorp.com/terraform/docs
Downloadhttps://releases.hashicorp.com/terraform/
Terraform 1.7 ReleasesView full list

What Is New in Terraform 1.7

Terraform 1.7 introduces config-driven import, a powerful new testing framework, and several enhancements to the language and provider ecosystem. This release focuses on improving the day-to-day workflow for infrastructure management.

Category Key Changes
New Features Config-driven import, Terraform test
Language & Core Optional object type attributes, moved block validation
Provider Dev Provider-defined functions, terraform_data behavior
CLI & UX terraform show JSON output, cloud block validation
Bug Fixes Various fixes across core and backends

How does config-driven import change infrastructure management?

Config-driven import is the headline feature, allowing you to declare import operations directly in your configuration. You write an import block specifying the ID of existing infrastructure and the Terraform resource address to adopt it.

Running terraform plan will show a proposed import operation. This is a game-changer for bringing existing resources under Terraform management because it formalizes the process and makes it repeatable. You can version control your import intentions alongside the resource definitions themselves.

import {
  to = aws_instance.example
  id = "i-abcd1234"
}

What can I do with the new testing framework?

Terraform 1.7 introduces a native testing framework, letting you write unit and integration tests in HCL. You create .tftest.hcl files that contain run blocks to execute and validate plans and applies.

This is a significant step up from previous workarounds. You can now assert conditions on plan output, state values, and command exit statuses. In practice, this means you can build a test suite to verify module behavior without external tooling, making your configurations more robust.

run "test_instance" {
  command = plan

  assert {
    condition = aws_instance.example.ami == "ami-12345678"
    error_message = "Incorrect AMI ID"
  }
}

Are there new ways to structure data with optional object attributes?

Yes, object types now support optional attributes. When you define an object type, you can mark certain attributes as optional using the optional modifier. This provides more flexibility for module input variables.

This matters because it lets you create complex object structures where certain fields can be omitted. The try() function can then be used to safely access these potentially absent values without causing plan errors, simplifying conditional logic in your configurations.

variable "settings" {
  type = object({
    name    = string
    enabled = optional(bool, true)
    tags    = optional(map(string))
  })
}

How do provider-defined functions work?

Provider-defined functions allow providers to expose custom functionality directly to Terraform configurations. Providers can now implement their own functions that you can call alongside built-in functions like length() or lookup().

This opens up new possibilities for data manipulation and resource configuration that was previously impossible or required complex workarounds. For example, a cloud provider might offer a function to generate a pre-signed URL or to perform specialized encryption.

What improvements were made to the terraform_data resource?

The terraform_data resource, introduced as a replacement for null_resource, now triggers replacement on any change to its input value. This behavior makes it more predictable for orchestrating provisioners and other side-effects.

In practice, this means if you change the input to a terraform_data resource, it will be destroyed and recreated, along with any resources that depend on it. This gives you explicit control over when provisioners should re-run based on changing data.

FAQ

Can I use the new import blocks to import multiple resources at once?
Yes, you can define multiple import blocks in your configuration. When you run terraform plan, Terraform will generate a plan to import all the specified resources in the correct order based on their dependencies.

Do I need to rewrite my existing tests for the new testing framework?
No, the new testing framework is additive. Existing methods using external testing tools or complex module structures still work. The .tftest.hcl format is a new option specifically for testing Terraform configurations natively.

What happens if I don't specify an optional attribute in an object?
If you don't provide a value for an optional attribute, Terraform will use the default value you defined in the type constraint. If no default was specified, the attribute's value will be null within the object.

Are provider-defined functions available for all providers immediately?
No, provider-defined functions must be implemented by each provider. You'll need to check if your specific provider version has been updated to support this feature after upgrading to Terraform 1.7.

How does the new moved block validation work?
Terraform now validates that the source address in a moved block actually exists in the state. This prevents typos and configuration errors that previously would have silently created new resources instead of moving existing ones.

Releases In Branch 1.7

VersionRelease date
1.7.513 Mar 2024
(2 years ago)
1.7.421 Feb 2024
(2 years ago)
1.7.308 Feb 2024
(2 years ago)
1.7.231 Jan 2024
(2 years ago)
1.7.124 Jan 2024
(2 years ago)
1.7.017 Jan 2024
(2 years ago)
1.7.0-rc211 Jan 2024
(2 years ago)
1.7.0-rc120 Dec 2023
(2 years ago)
1.7.0-beta213 Dec 2023
(2 years ago)
1.7.0-beta106 Dec 2023
(2 years ago)
1.7.0-alpha2023113030 Nov 2023
(2 years ago)
1.7.0-alpha2023110808 Nov 2023
(2 years ago)
1.7.0-alpha2023102525 Oct 2023
(2 years ago)