Terraform Set Binding Decision
Status: current
Last verified: 2026-03-31
Scope: generated provider bindings, schema-aware config normalization, and contributor guidance for Terraform set(...) types.
Decision
Represent Terraform set(T) values as Python list[T] in generated provider bindings.
Do not expose Terraform sets as Python set[T] in the public generated API.
At the runtime/config boundary, continue accepting Python set, tuple, and other sequence-like inputs as convenience forms, then normalize them to lists and deduplicate them when the Terraform schema says the target type is set.
Why
Terraform set semantics are not a good match for Python set semantics:
- Terraform sets are unordered and unique.
- Terraform commonly converts between list/tuple/set-like collection types.
- Converting a list or tuple to a Terraform set discards duplicates and loses ordering.
- Converting a Terraform set back to a list yields arbitrary ordering for non-string elements.
- Terraform sets can contain complex object values.
- Python
setrequires hashable elements, so it cannot represent common Terraform cases such as sets of object-like dictionaries.
That makes Python list[T] the safer generated surface:
- it can represent all Terraform set element shapes, including nested object values
- it works naturally with generated constructors and keyword arguments
- it keeps the API ergonomic for users who are already writing JSON/HCL-shaped Python data
- netherframe can still enforce Terraform set semantics during normalization by deduplicating and treating order as non-semantic
Fact Check
The current HashiCorp Terraform language docs define set(...) as a collection of unique values without ordering:
- Type Constraints:
set(...)is "a collection of unique values that do not have any secondary identifiers or ordering." - Type Constraints: converting a list or tuple to a set discards duplicates and loses ordering; converting a set back to a list yields arbitrary ordering, except that sets of strings are lexicographically ordered.
- toset: converting a list to a set removes duplicates and discards ordering.
The provider-side docs also model Terraform sets as collection types that are unique and unordered at the Terraform type-system level:
- Terraform Plugin Framework: Data types:
Setis an unordered, unique collection of a single element type. - Terraform Plugin Framework: Set types: framework APIs set and read set values through slice-based Go types such as
[]string, not Gomap-style or language-native set types.
There is one wording inconsistency in the plugin framework "Set types" page that says "ordered collection". That contradicts the Terraform language docs, the framework data types page, and the rest of the Terraform type system behavior. Treat that line as documentation drift rather than as the semantic contract.
Why Not Python set
Using Python set[T] in generated bindings would introduce avoidable mismatches:
- it rejects unhashable elements, but Terraform sets can contain object/nested-block values
- it suggests Python equality and hashing semantics are authoritative, but Terraform decides equality according to Terraform values and provider schema rules
- it suggests order is never observable, but netherframe still needs a stable list-shaped transport value during normalization, synthesis, and testing
- it makes nested generated types harder to use because users would need hashable wrapper objects for values that are naturally expressed as dict-like structures
netherframe Implementation
The repository already follows this decision:
- Generated Python types map Terraform
settolistinlibs/netherframe.generation/netherframe/generation/providers/codegen_support.py. - Schema normalization converts set-typed attributes and set-typed blocks to lists and deduplicates them in
libs/netherframe.core/netherframe/core/config/config_normalization.py. - Generic coercion accepts Python
setinputs and turns them into list-shaped values inlibs/netherframe.core/netherframe/core/config/normalization_coercion.py. - Generator tests assert
["set", "string"] -> list[str]inlibs/netherframe.generation/tests/test_code_generator.py. - Normalization tests assert that set inputs become lists and are deduplicated in
libs/netherframe.core/tests/test_config_normalization.pyandlibs/netherframe.core/tests/test_property_based_provider_config_normalization.py.
Generator Guidance
When extending or regenerating provider bindings:
- generate Terraform
set(T)aslist[T] - generate nested
set(object(...))shapes aslist[dict[...]]or the equivalent generated nested block/list shape - do not change generated signatures to
set[T] - keep normalization logic responsible for deduplication and set semantics
- keep tests focused on semantic equality for set-typed values rather than positional ordering
Working Rule
For netherframe, Terraform set means:
- Public API type: Python list
- Convenience inputs: list, tuple, set, and other sequence-like values
- Normalized transport shape: list
- Semantic behavior: uniqueness enforced, ordering treated as non-semantic