Terraform

You noticed there are relative paths in some of your modules and you would like to change that. What can you do and why is that a problem in the first place?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

Relative paths usually work fine in your own environment as you are familiar with the layout and paths used, but when sharing a module and making it reusable, you may bump into issues as it runs on different environments where the relative paths may no longer be relevant.

A better approach would be to use path reference like one of the following:

  • path.module: the path of the module where the expression is used
  • path.cwd: the path of the current working directory
  • path.root: the path of the root module