Comprehensive documentation and best practices for building Terraform providers with terraform-plugin-framework (v1.17.0). Covers providers, resources, schemas, types, validators, testing, and common pitfalls.
Overall
score
97%
Follow Terraform provider testing conventions for terraform-plugin-framework code.
All resources and data sources MUST have acceptance tests using resource.Test from terraform-plugin-testing. This is the standard convention across all major Terraform providers.
Do NOT unit test resource CRUD methods with mock API clients.
TestAcc<Resource>_basic -- create and readTestAcc<Resource>_update -- create then updateTestAcc<Resource>_import -- import state verificationProtoV6ProviderFactories for provider setupCheckDestroy to verify cleanupresource.ComposeAggregateTestCheckFunc for assertionsfmt.SprintfUnit tests are appropriate for:
Use testify/require for assertions (not assert -- require stops on failure).
Provider functions MUST have unit tests that directly call the Run method. Construct function.RunRequest with function.NewArgumentsData and function.RunResponse with function.NewResultData, then assert the result:
func TestParseIdFunction_ValidInput(t *testing.T) {
f := NewParseIdFunction()
req := function.RunRequest{
Arguments: function.NewArgumentsData([]attr.Value{
basetypes.NewStringValue("resource:my-thing"),
}),
}
resp := &function.RunResponse{
Result: function.NewResultData(basetypes.StringType{}),
}
f.Run(context.Background(), req, resp)
require.Nil(t, resp.Error)
var result string
resp.Result.Get(context.Background(), &result)
require.Equal(t, "my-thing", result)
}Always test both valid inputs and invalid/error inputs in separate test functions.
TestAcc<Resource>_<scenario> for acceptance, Test<Function>_<scenario> for unitSee Testing for complete examples, config helpers, and CheckDestroy patterns.