boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
674 stars 46 forks source link

improve tfvars lookup location to include config/stacks/demo/tfvars #336

Closed tongueroo closed 11 months ago

tongueroo commented 11 months ago

This is a 🙋‍♂️ feature or enhancement.

Summary

Add additional tfvars lookup path at config/stacks/demo/tfvars.

❯ tree config/stacks
config/stacks
└── demo
    └── tfvars
        └── dev.tfvars

Layering is performed in this order:

config/terraform/tfvars/dev.tfvars
app/stacks/demo/tfvars/dev.tfvars
config/stacks/demo/tfvars/dev.tfvars <= NEW

So config/stacks/demo/tfvars/dev.tfvars will take the highest precedence and win.

This allows tfvars config to be decoupled from the stacks. The idea is that stacks can optionally ship with default tfvars files. And users can completely override them without touching the stack code.

This PR also changes terraspace seed so it'll generate the tfvars starter file in config/stacks/demo/tfvars

❯ terraspace seed demo
Seeding tfvar files for demo
      create  config/stacks/demo/tfvars/dev.tfvars

Additionally, found this it easier to see what stacks have been deployed by simply running tree config/stacks

❯ tree config/stacks
config/stacks
└── demo
    └── tfvars
        └── dev.tfvars

How to Test

Just do a sanity check and make sure terraspace works.

Move Script

Here's a useful move-tfvars.rb script that you can use to quickly move your tfvars files from app/stacks to config/stacks.

Also relevant docs: https://terraspace.cloud/docs/layering/tfvars-location-thoughts/

Version Changes

Patch