Index
pyvider.hcl.parser
¶
HCL parsing module.
This module provides HCL parsing functionality with CTY type integration.
Functions¶
auto_infer_cty_type
¶
Automatically infer CTY type from raw Python data.
This function takes Python data structures (typically from HCL parsing) and automatically infers appropriate CTY types using pyvider-cty's canonical inference implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_data
|
Any
|
Python data structure to infer types for |
required |
Returns:
| Type | Description |
|---|---|
CtyValue[Any]
|
CTY value with inferred types |
Example
data = {"name": "test", "count": 5} result = auto_infer_cty_type(data) isinstance(result.type, CtyObject) True
Note
This delegates to pyvider.cty.conversion.infer_cty_type_from_raw() which provides sophisticated type inference including: - List element type analysis (e.g., [1,2,3] → list(number)) - Object attribute inference - Type unification for mixed collections - Caching and cycle detection
Source code in pyvider/hcl/parser/inference.py
parse_hcl_to_cty
¶
Parse HCL directly into validated CtyValues using pyvider.cty types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hcl_content
|
str
|
HCL string to parse |
required |
schema
|
CtyType[Any] | None
|
Optional CTY type schema for validation |
None
|
Returns:
| Type | Description |
|---|---|
CtyValue[Any]
|
Parsed and validated CTY value |
Raises:
| Type | Description |
|---|---|
HclParsingError
|
If parsing or validation fails |
Example
hcl = 'name = "example"' result = parse_hcl_to_cty(hcl) result.value["name"].value 'example'
Source code in pyvider/hcl/parser/base.py
parse_with_context
¶
Parse HCL content with enhanced error context.
This function parses HCL content and provides rich error context if parsing fails. It returns the raw parsed data (dict/list), not CTY values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
HCL content string to parse |
required |
source_file
|
Path | None
|
Optional source file path for error reporting |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Raw parsed data (typically dict or list) |
Raises:
| Type | Description |
|---|---|
HclParsingError
|
If parsing fails, with source location information |
Example
content = 'name = "example"' data = parse_with_context(content) data['name'] 'example'