Terraform
Terraform SDKv2 Best Practices
Tip
This best practices section only contains guidance for plugins built with Terraform Plugin SDK. More generic best practices that apply to both SDK and Terraform Plugin Framework can be found in the Plugin Development Best Practices section.
A key feature of Terraform is its plugin system, which separates the details of specific vendor APIs from the shared logic for managing state, managing configuration, and providing a safe plan and apply lifecycle. Plugins are responsible for the implementation of functionality for provisioning resources for a specific cloud provider, allowing each provider to fully support its unique resources and lifecycles and not settling for the lowest common denominator across all provider resources of that type (virtual machines, networks, configuration management systems, et. al). While each provider is unique, over the years, we accumulated recommended patterns that help ensure a consistent user experience when using Terraform for any given provider. This page describes best practices that generally apply to most Providers built with the legacy SDK, with a brief description of each, and link to read more.
Deprecations, Removals, and Renames
Over time, remote services evolve and better workflows are designed. Terraform's plugin system has functionality to aid in iterative improvements. In Deprecations, Removals, and Renames, we cover procedures for backwards compatible code and documentation updates to ensure that operators are well informed of changes ahead of functionality being removed or renamed.
Enabling beta features
As a provider, you might want to enable new resources that are still in beta.
Those resources might change later on.
As a general practice, you can enable your provider to support those beta features
by using a environment variable such as PROVIDERX_ENABLE_BETA
.
Once your resources are out of beta and reach a stable status, you can use those
resources by default without requiring an environment variable.
Detecting Drift
Terraform is a declarative tool designed to be the source of truth for infrastructure. In order to safely and predictably change and iterate infrastructure, Terraform needs to be able to detect changes made outside of its configuration and provide means of reconciliation. In Detecting Drift, we cover some best practices to ensure Terraform's statefile is an accurate reflection of reality, to provide accurate plan and apply functionality.