Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#2831·opentofu

Validation of Output Types

Author: siegenthalerrogerCreated May 21, 2025Updated Sep 29, 2026
Labelsenhancementacceptedcore-team

Community note

[!TIP] Hi there, OpenTofu community! The OpenTofu team prioritizes issues based on upvotes. Please make sure to upvote this issue and describe how it affects you in detail in the comments to show your support.

OpenTofu Version

bash
1.9.1

The problem in your OpenTofu project

I'd like to have a way to ensure that my module's outputs conform to a certain type (preferably I'd like to grab that type from a provider schema, separate issue -> https://github.com/opentofu/opentofu/issues/2704).

Ideally this should be possible statically, without requiring actual infrastructure to be spun up in order to validate.

Attempted Solutions

  • Using tofu test is not possible as the type of a variable cannot be checked.

Proposal

I'm not entirely sure how to do this but here's some ideas that I had:

  1. Allow the definition of a type property on output blocks. This would allow static validation that the value conforms to this type.
  2. Allow the usage of the tofu console's type() function in run "test" blocks (not a great fan as this requires actual infrastructure to be spun up).

Workarounds and Alternatives

  • Using a separate "type validation" module that takes the module's outputs as inputs that have the type defined on them. This requires having a second module that seems independent but isn't. Changes have to be applied in multiple locations and the error messages are cryptic as they target the validation-module's inputs instead of the feature-module's outputs.
  • Using an external testing framework that supports checking the type of an output. Complexity through additional tooling and necessity to define types in non-HCL syntax.

References

  • https://github.com/hashicorp/terraform/issues/30579

Source: opentofu/opentofu

View original on GitHubView discussion on GitHub