I have this directory structure, and I need to generate symlinks for common/provider.tf
in both environments/prod
and environments/prod/module
.
/
├─ common
│ ├─ provider.tf
├─ environments/
│ ├─ prod/
│ │ ├─ module/
I managed to do it this way:
if [ -e "../../../common/provider.tf" ]; then # I'm in environments/prod/module
ln -s ../../../common/provider.tf provider.tf
else # I'm in the root folder "/"
ln -s common/provider.tf $environment/provider.tf # $environment is /environments/prod
fi
But I realize that my code sucks and I can't come up with a better idea.
Any idea on how to do it better? Note: There are lots of environments and lots of modules, I'm using that code recursively.