Terraform
Plugin Testing
Write acceptance tests and unit tests with the terraform-plugin-testing Go module.
The testing framework for Terraform providers,terraform-plugin-testing
,
uses standard Go features such as the go test
command and the standard
library testing
package. In addition to this documentation, refer to the
generated Go
documentation.
This section introduces strategies for testing provider functionality with acceptance tests and unit tests.
Acceptance Tests
Acceptance tests for Terraform providers are a feature of the
terraform-plugin-testing
framework. The testing framework uses standard Go features such as the go
test
command. It runs a local Terraform binary to perform real plan, apply,
refresh, and destroy operations, and enables developers to make assertions
about what happens during those actions.
Refer to Acceptance Testing to learn more.
Unit Tests
Testing plugin code in small, isolated units is distinct from Acceptance Tests, and does not require network connections. Unit tests are commonly used for testing helper methods that expand or flatten API response data into data structures for storage into state by Terraform. This section covers the specifics of writing Unit Tests for Terraform Plugin code.
For a given plugin, Unit Tests can be run from the root of the project by using a common make task:
$ make test
Refer to Unit Testing to learn more.
Testing Patterns
Terraform developers are encouraged to write acceptance tests that create real resource to verify the behavior of plugins, ensuring a reliable and safe way to manage infrastructure. In Testing Patterns we cover some basic acceptance tests that almost all resources should have to validate not only the functionality of the resource, but that the resource behaves as Terraform would expect.