OpenTofu Test
v0.1.0MCP server for the OpenTofu/Terraform native test framework: scaffold, mock, validate, run tests
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
tf_explain_test_schema
Explain the OpenTofu/Terraform native test framework grammar (.tftest.hcl / .tfmock.hcl). Call with an empty topic for an overview, or a topic like 'run', 'assert', 'mock_provider', 'expect_failures' for its block reference and an example.
| Parameter | Type | Description |
|---|---|---|
topic | string | a test-framework topic such as run, assert, mock_provider, mock_resource, expect_failures, tftest, tfmock; empty returns an overview |
tf_gen_mock_provider
Generate a mock_provider block for an initialized module directory by reading 'providers schema -json'. Pre-fills mock_resource defaults for computed attributes. The directory must have been initialized first.
| Parameter | Type | Description |
|---|---|---|
dir * | string | path to an initialized module directory |
binary | string | override the CLI binary (tofu or terraform, or an absolute path) |
provider | string | restrict output to this provider source or local name; empty emits all providers |
resource | string | restrict output to this resource type |
tf_run_tests
Run 'tofu test -json' in a module directory and return a condensed pass/fail summary with per-run status. Optionally filter to a single test file. Requires the directory to be initialized.
| Parameter | Type | Description |
|---|---|---|
dir * | string | path to an initialized module directory containing tests |
binary | string | override the CLI binary (tofu or terraform, or an absolute path) |
filter | string | restrict the run to a single test file, e.g. tests/main.tftest.hcl |
tf_scaffold_test
Generate a .tftest.hcl starter test for a module directory by reading its input variables and outputs. Produces a run block with assertions for each output and placeholders for required variables.
| Parameter | Type | Description |
|---|---|---|
dir * | string | path to the module directory to scaffold a test for |
command | string | the run command to use: plan (default) or apply |
mock | boolean | also emit empty mock_provider blocks for the module's providers |
tf_validate_test
Statically validate a .tftest.hcl file (by path or raw content) and report structural problems such as an invalid command, assert blocks missing condition/error_message, duplicate run names, or no run blocks. Does not run OpenTofu.
| Parameter | Type | Description |
|---|---|---|
content | string | raw .tftest.hcl content to validate instead of a path |
path | string | path to a .tftest.hcl file to validate |