OpenTofu Test

v0.1.0
io.github.ogormans-deptstack/opentofu-test Checked 20 hours ago Published 1 month ago

MCP 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.

ParameterTypeDescription
topicstringa 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.

ParameterTypeDescription
dir *stringpath to an initialized module directory
binarystringoverride the CLI binary (tofu or terraform, or an absolute path)
providerstringrestrict output to this provider source or local name; empty emits all providers
resourcestringrestrict 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.

ParameterTypeDescription
dir *stringpath to an initialized module directory containing tests
binarystringoverride the CLI binary (tofu or terraform, or an absolute path)
filterstringrestrict 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.

ParameterTypeDescription
dir *stringpath to the module directory to scaffold a test for
commandstringthe run command to use: plan (default) or apply
mockbooleanalso 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.

ParameterTypeDescription
contentstringraw .tftest.hcl content to validate instead of a path
pathstringpath to a .tftest.hcl file to validate