What Is New in Terraform 0.8
Terraform 0.8 brings foundational improvements to state management and introduces new ways to handle environment-specific configurations. This release focuses on making complex infrastructure setups more manageable and less error-prone.
| Category | Key Changes |
|---|---|
| New Features | Environment-aware state, Interpolation in backend config |
| Improvements | Enhanced backend configuration, Better state isolation |
| Backwards Incompatibilities | Legacy remote state behavior changes |
How does environment-aware state work?
The new environment-aware state feature fundamentally changes how Terraform handles multiple environments like staging and production. Instead of a single state file, Terraform now automatically manages separate state files for each named environment.
You create and switch between environments using the new terraform env commands. This approach prevents accidental changes to the wrong environment's infrastructure, a common operational headache. Each environment maintains its own state file, variables, and resource definitions.
What changed with backend configuration?
Backend configuration received significant enhancements, most notably the ability to use interpolation within the backend block. This allows for dynamic backend configuration based on variables and other Terraform expressions.
In practice, this means you can now reference variables like var.environment to determine your state storage path. For example, you can dynamically set an S3 bucket key based on the environment name, making your backend configuration much more flexible and DRY.
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "environments/${var.environment}/terraform.tfstate"
region = "us-east-1"
}
}
Are there any breaking changes I should know about?
Yes, the legacy remote state behavior has been modified in ways that might affect existing setups. The old method of handling remote state via the terraform remote command has been replaced by the new backend system.
If you were using the legacy remote state configuration, you'll need to migrate to the new backend configuration. The upgrade process is straightforward but requires explicit action - Terraform provides commands to help migrate your existing state to the new backend format.
FAQ
How do I create a new environment in Terraform 0.8?
Use terraform env new <name> to create a new environment and terraform env select <name> to switch between them. Each environment gets its own isolated state file.
Can I use variables in my backend configuration now?
Yes, this is a major enhancement. You can now use interpolation syntax like ${var.environment} within your backend block to dynamically configure state storage locations.
What happens to my existing remote state setup?
You'll need to migrate it to the new backend system. Use the terraform init command with your backend configuration defined, and Terraform will prompt you to migrate existing state.
Does this affect how modules work with different environments?
Modules work the same way, but now you can more easily parameterize them per environment using the environment-specific variables and state isolation.
Can I have different backends for different environments?
While possible, it's not the intended pattern. The backend configuration is typically defined once in your root module, but you can use interpolation to vary settings like state file paths based on environment.