Index
pyvider.hcl.factories
¶
Factory functions for creating Terraform CTY structures.
Classes¶
HclFactoryError
¶
Bases: ValueError
Custom exception for errors during HCL factory operations.
HclTypeParsingError
¶
Bases: ValueError
Custom exception for errors during HCL type string parsing.
Functions¶
create_resource_cty
¶
create_resource_cty(
r_type: str,
r_name: str,
attributes_py: dict[str, Any],
attributes_schema_py: dict[str, str] | None = None,
) -> CtyValue[Any]
Create a Terraform resource CTY structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_type
|
str
|
Resource type (e.g., "aws_instance") |
required |
r_name
|
str
|
Resource name |
required |
attributes_py
|
dict[str, Any]
|
Resource attributes as Python dict |
required |
attributes_schema_py
|
dict[str, str] | None
|
Optional type strings for attributes |
None
|
Returns:
| Type | Description |
|---|---|
CtyValue[Any]
|
CTY value representing Terraform resource structure |
Raises:
| Type | Description |
|---|---|
HclFactoryError
|
If validation fails |
Example
resource = create_resource_cty( ... r_type="aws_instance", ... r_name="web", ... attributes_py={"ami": "ami-123", "instance_type": "t2.micro"}, ... attributes_schema_py={"ami": "string", "instance_type": "string"} ... )
Source code in pyvider/hcl/factories/resources.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
create_variable_cty
¶
create_variable_cty(
name: str,
type_str: str,
default_py: Any | None = None,
description: str | None = None,
sensitive: bool | None = None,
nullable: bool | None = None,
) -> CtyValue[Any]
Create a Terraform variable CTY structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variable name (must be valid identifier) |
required |
type_str
|
str
|
HCL type string (e.g., "string", "list(number)") |
required |
default_py
|
Any | None
|
Optional default value |
None
|
description
|
str | None
|
Optional description |
None
|
sensitive
|
bool | None
|
Optional sensitive flag |
None
|
nullable
|
bool | None
|
Optional nullable flag |
None
|
Returns:
| Type | Description |
|---|---|
CtyValue[Any]
|
CTY value representing Terraform variable structure |
Raises:
| Type | Description |
|---|---|
HclFactoryError
|
If validation fails |
Example
var = create_variable_cty( ... name="region", ... type_str="string", ... default_py="us-west-2" ... )
Source code in pyvider/hcl/factories/variables.py
parse_hcl_type_string
¶
Parse HCL type string into CTY type.
Supports: - Primitives: string, number, bool, any - Lists: list(element_type) - Maps: map(element_type) - Objects: object({attr=type, ...})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_str
|
str
|
HCL type string (e.g., "list(string)", "object({name=string})") |
required |
Returns:
| Type | Description |
|---|---|
CtyType[Any]
|
Corresponding CTY type |
Raises:
| Type | Description |
|---|---|
HclTypeParsingError
|
If type string is malformed |
Example
parse_hcl_type_string("list(string)") CtyList(element_type=CtyString())