Skip to content

Adds support for module_path key in Terrafile #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ pterrafile [path]

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.

Add a `module_path` key to the Terrafile to specify the module destination
path relative to the Terrafile location, or an absolute path.

## Examples

```yaml
module_path: modules

# Terraform Registry module
terraform-aws-lambda:
source: "claranet/lambda/aws"
Expand Down
15 changes: 12 additions & 3 deletions terrafile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def get_terrafile_path(path):
else:
return path

def get_module_path(terrafile_path, terrafile):
if "module_path" not in terrafile.keys():
return os.path.dirname(terrafile_path)
elif os.path.isdir(terrafile["module_path"]):
return terrafile["module_path"]
else:
return os.path.join(os.path.dirname(terrafile_path), terrafile["module_path"])

def read_terrafile(path):
try:
Expand Down Expand Up @@ -92,12 +99,14 @@ def is_valid_registry_source(source):

def update_modules(path):
terrafile_path = get_terrafile_path(path)
module_path = os.path.dirname(terrafile_path)
module_path_name = os.path.basename(os.path.abspath(module_path))

terrafile = read_terrafile(terrafile_path)

module_path = get_module_path(terrafile_path, terrafile)
module_path_name = os.path.basename(os.path.abspath(module_path))

for name, repository_details in sorted(terrafile.items()):
if name == "module_path": continue

target = os.path.join(module_path, name)
source = repository_details['source']

Expand Down