Skip to content

Commit ebd5ba2

Browse files
author
Phil Dier
committed
Adds support for module_path key in Terrafile
1 parent 8c50211 commit ebd5ba2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ pterrafile [path]
2020

2121
If `path` is provided, it must be the path to a `Terrafile` file, or a directory containing one. If not provided, it looks for the file in the current working directory.
2222

23+
Add a `module_path` key to the Terrafile to specify the module destination
24+
path relative to the Terrafile location, or an absolute path.
25+
2326
## Examples
2427

2528
```yaml
29+
module_path: modules
30+
2631
# Terraform Registry module
2732
terraform-aws-lambda:
2833
source: "claranet/lambda/aws"

terrafile/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ def get_terrafile_path(path):
5454
else:
5555
return path
5656

57+
def get_module_path(terrafile_path, terrafile):
58+
if "module_path" not in terrafile.keys():
59+
return os.path.dirname(terrafile_path)
60+
elif os.path.isdir(terrafile["module_path"]):
61+
return terrafile["module_path"]
62+
else:
63+
return os.path.join(os.path.dirname(terrafile_path), terrafile["module_path"])
5764

5865
def read_terrafile(path):
5966
try:
@@ -92,12 +99,14 @@ def is_valid_registry_source(source):
9299

93100
def update_modules(path):
94101
terrafile_path = get_terrafile_path(path)
95-
module_path = os.path.dirname(terrafile_path)
96-
module_path_name = os.path.basename(os.path.abspath(module_path))
97-
98102
terrafile = read_terrafile(terrafile_path)
99103

104+
module_path = get_module_path(terrafile_path, terrafile)
105+
module_path_name = os.path.basename(os.path.abspath(module_path))
106+
100107
for name, repository_details in sorted(terrafile.items()):
108+
if name == "module_path": continue
109+
101110
target = os.path.join(module_path, name)
102111
source = repository_details['source']
103112

0 commit comments

Comments
 (0)