claranet / jinjaform

Terraform wrapper with Jinja2 templates
MIT License
35 stars 8 forks source link

Remove .root symlink #8

Closed raymondbutcher closed 5 years ago

raymondbutcher commented 5 years ago

I think the .root symlink functionality can be replaced by using Direnv in a project to create an absolute symlink in the top directory. Jinjaform should copy it into the working directory and it will continue to point to wherever it was pointing to. Direnv should replace the symlink every time so that it works even if the project gets moved.

Project structure:

environments/
  main.tf
  modules --> /home/ray/myproject/terraform/modules
  dev/
    terraform.tfvars
  prod/
    terraform.tfvars
modules/
  my-module/
  other-module/

Contents of .envrc:

# Add Terraform modules symlink
ln -fs $(pwd)/terraform/modules $(pwd)/terraform/environments/modules 

Contents of .gitignore:

terraform/environments/modules

Contents of main.tf:

module "my_module" {
  source = "modules/my-module"
}

For this to work, Jinjaform will need to support symlinks. It currently ignores them when creating the workspace.

Making this change will make the projects neater (source = "modules/my-module" vs source = ".root/modules/my-module") and allow projects to name the symlink whatever they want. Fewer features in Jinjaform is good too, as one of the goals is to make it simple and as transparent as possible.

This pattern should be added to the example too.

raymondbutcher commented 5 years ago

Hooks #9 could also be used instead of Direnv to create the symlink.