Migration from v1 to v2 - update the terraspace app.rb cache_dir value

Just a quick note to the community for people migrating from terraspace v1 to terraspace.
I didn’t see it on the blog post about terraspace v2 release but it’s important to highlight something you have mentioned on the git changelog for v2.0.0

"* Remove config.build.cache_root option"

When I started terraspace v1.1.5, I generate my first project with the command:

terraspace new project infra --plugin azurerm --examples

as mentioned on the documentation

It will generate something like this on the config file “app.rb”:

# Docs: https://terraspace.cloud/docs/config/reference/
Terraspace.configure do |config|
  config.logger.level = :info
  config.build.cache_dir = ":CACHE_ROOT/:ENV/:REGION/:BUILD_DIR"
end

But if you switch to terraspace v2, you should remove “:CACHE_ROOT/” otherwise you might get a very long strange path on your .terraspace-cache folder
example:

Building .terraspace-cache/mnt/c/Users/xxx/source/repos/yyy/zzz/DevOPS_IaC/.terraspace-cache/7/westeurope/stacks/app_resource_group
Created .terraspace-cache/mnt/c/Users/xxx/source/repos/yyyyyyyy/zzz/DevOPS_IaC/.terraspace-cache/7/westeurope/modules/app_key_vault/main.tf

No problem for using terraspace v2 after migration from v1 but important to note that you don’t need :CACHE_ROOT env var anymore

Thanks for pointing that out. :+1: Added a check to look for :CACHE_ROOT in config.build.cache_dir and automatically remove it and warn the user about it.

So hopefully users won’t have to jump through the same hoops. Appreciate the post. :confetti_ball:

1 Like