infrablocks.terraform_pkl_type_gen 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- infrablocks/terraform_pkl_type_gen/__init__.py +3 -0
- infrablocks/terraform_pkl_type_gen/pkl_generator.py +56 -0
- infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/LICENSE +21 -0
- infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/LICENSE.md +21 -0
- infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/METADATA +32 -0
- infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/RECORD +7 -0
- infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from typing import Dict, List
|
|
2
|
+
|
|
3
|
+
from tfparse import load_from_path
|
|
4
|
+
|
|
5
|
+
type_mapping: Dict[str, str] = {
|
|
6
|
+
"string": "String",
|
|
7
|
+
"number": "Number",
|
|
8
|
+
"bool": "Boolean",
|
|
9
|
+
"list of dynamic": "Listing",
|
|
10
|
+
"list(any)": "Listing",
|
|
11
|
+
"list of string": "Listing<String>",
|
|
12
|
+
"list of number": "Listing<Number>",
|
|
13
|
+
"list of bool": "Listing<Boolean>",
|
|
14
|
+
"map of dynamic": "Mapping<String, Any>",
|
|
15
|
+
"map of string": "Mapping<String, String>",
|
|
16
|
+
"map of number": "Mapping<String, Number>",
|
|
17
|
+
"map of bool": "Mapping<String, Boolean>",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
indent = " "
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def map_type(terraform_type: str) -> str:
|
|
24
|
+
"""Map Terraform type to Python type."""
|
|
25
|
+
return type_mapping[terraform_type]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def generate_pkl_type(chdir: str, type_name: str) -> str:
|
|
29
|
+
parsed = load_from_path(chdir)
|
|
30
|
+
root_variables = [
|
|
31
|
+
variable
|
|
32
|
+
for variable in parsed["variable"]
|
|
33
|
+
if variable["__tfmeta"]["filename"] == "variables.tf"
|
|
34
|
+
]
|
|
35
|
+
output: List[str] = []
|
|
36
|
+
|
|
37
|
+
output.append(
|
|
38
|
+
f"// This file is automatically generated based on the input variables in {chdir}/variables.tf"
|
|
39
|
+
)
|
|
40
|
+
output.append(f"class {type_name} {{")
|
|
41
|
+
|
|
42
|
+
for variable in root_variables:
|
|
43
|
+
output.append(
|
|
44
|
+
f"{indent}{variable['__tfmeta']['label']}: {map_type(variable['type'])}"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
output.append("}")
|
|
48
|
+
return "\n".join(output)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def write_pkl_type(chdir: str, target_file_path: str, type_name: str) -> None:
|
|
52
|
+
"""Generate and write the PKL type to a file."""
|
|
53
|
+
result = generate_pkl_type(chdir, type_name)
|
|
54
|
+
|
|
55
|
+
with open(target_file_path, "w") as file:
|
|
56
|
+
file.write(result)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 InfraBlocks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 InfraBlocks Maintainers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: infrablocks.terraform_pkl_type_gen
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Provides invoke tasks to interact with terraform
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Toby Clemson
|
|
7
|
+
Author-email: tobyclemson@gmail.com
|
|
8
|
+
Requires-Python: >=3.13,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Dist: infrablocks-invoke-factory (>=0.0.3a6,<0.0.4)
|
|
12
|
+
Requires-Dist: invoke (>=2.2.0,<3.0.0)
|
|
13
|
+
Requires-Dist: tfparse (>=0.6.16,<0.7.0)
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Terraform Pkl Type Gen
|
|
17
|
+
|
|
18
|
+
A library for creating Pkl types from Terraform variables definitions.
|
|
19
|
+
|
|
20
|
+
## Development
|
|
21
|
+
|
|
22
|
+
For the best developer experience make sure you have `direnv` and `asdf` installed.
|
|
23
|
+
|
|
24
|
+
Contributing
|
|
25
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/infrablocks/terraform_pkl_type_gen.
|
|
26
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
|
|
27
|
+
Contributor Covenant code of conduct.
|
|
28
|
+
|
|
29
|
+
License
|
|
30
|
+
Copyright © 2025 InfraBlocks Maintainers
|
|
31
|
+
|
|
32
|
+
Distributed under the terms of the MIT License.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
infrablocks/terraform_pkl_type_gen/__init__.py,sha256=6BUbl5mV5WI-x7xJK25xNTPCgPAGat1rE2rkwwk4-UY,174
|
|
2
|
+
infrablocks/terraform_pkl_type_gen/pkl_generator.py,sha256=yto6N63aTtTbVE_SgHQf8Ej7ehBzRqGUAn4_ylcPLjY,1601
|
|
3
|
+
infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/LICENSE,sha256=WD5BA4c-gO41QZ9AVOgLptp4llgk9d8aB-s4Mx8kMJY,1068
|
|
4
|
+
infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/LICENSE.md,sha256=BXVKHCGylFdgJpWHy_tEcjxE6ipBxacI3Ha7ISfHUOw,1082
|
|
5
|
+
infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/METADATA,sha256=gYyc4GLCLJ8lQARVs9UPvhj67L-jFJE5ztBp0DKdqig,1097
|
|
6
|
+
infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
7
|
+
infrablocks_terraform_pkl_type_gen-0.0.1.dist-info/RECORD,,
|