Closed byron70 closed 2 years ago
Took some time to think about this one. Here's some review:
config/app.rb
Terraspace.configure do |config|
config.layering.names = {
"111111111111" => "dev-account",
}
config.layering.mode = "namespace" # simple, namespace, or provider
end
$ export TS_SHOW_ALL_LAYERS=1
$ terraspace build demo 2>&1 | grep config
config/terraform/tfvars/base.tfvars
config/terraform/tfvars/dev.tfvars
config/terraform/tfvars/us-west-2.tfvars
config/terraform/tfvars/us-west-2/base.tfvars
config/terraform/tfvars/us-west-2/dev.tfvars
config/terraform/tfvars/dev-account.tfvars # <= ALL OK
config/terraform/tfvars/dev-account/base.tfvars
config/terraform/tfvars/dev-account/dev.tfvars
config/terraform/tfvars/dev-account/us-west-2.tfvars
config/terraform/tfvars/dev-account/us-west-2/base.tfvars
config/terraform/tfvars/dev-account/us-west-2/dev.tfvars
$
config/app.rb
Terraspace.configure do |config|
config.layering.names = {
"111111111111" => "dev",
}
config.layering.mode = "namespace" # simple, namespace, or provider
end
$ export TS_SHOW_ALL_LAYERS=1
$ terraspace build demo 2>&1 | grep config
config/terraform/tfvars/base.tfvars
config/terraform/tfvars/dev.tfvars
config/terraform/tfvars/us-west-2.tfvars
config/terraform/tfvars/us-west-2/base.tfvars
config/terraform/tfvars/us-west-2/dev.tfvars
config/terraform/tfvars/dev.tfvars # <= DUPLICATED
config/terraform/tfvars/dev/base.tfvars
config/terraform/tfvars/dev/dev.tfvars
config/terraform/tfvars/dev/us-west-2.tfvars
config/terraform/tfvars/dev/us-west-2/base.tfvars
config/terraform/tfvars/dev/us-west-2/dev.tfvars
$
It was a bit of a struggle. Think it's better to remove the duplicated layer like you've done. Think the namespace layer is less used and so it's more expected that config/terraform/tfvars/dev.tfvars
essentially takes higher precedence. Thanks for the PR and explanation.
The second config/terraform/tfvars/dev/base.tfvars
is removed.
$ export TS_SHOW_ALL_LAYERS=1
$ terraspace build demo 2>&1 | grep config
config/terraform/tfvars/base.tfvars
config/terraform/tfvars/dev.tfvars
config/terraform/tfvars/us-west-2.tfvars
config/terraform/tfvars/us-west-2/base.tfvars
config/terraform/tfvars/us-west-2/dev.tfvars
config/terraform/tfvars/dev/base.tfvars
config/terraform/tfvars/dev/dev.tfvars
config/terraform/tfvars/dev/us-west-2.tfvars
config/terraform/tfvars/dev/us-west-2/base.tfvars
config/terraform/tfvars/dev/us-west-2/dev.tfvars
$
Also updated the docs with a note https://terraspace.cloud/docs/layering/friendly-names/ Also note, in Terraspace 2.0 layering was tweaked. It was simplified.
This is a 🐞 bug fix.
bundle exec rspec
to verify this)Summary
Removes duplicate entries from layering paths that occur when you add a layer name mapping that matches
TS_ENV
.Eventually this leads to tfvar files with duplicated variables -
1-sbx.auto.tfvar
2-sbx.auto.tfvar
.Context
This really extended from my improper use of layer name mappings. It was a simple fix once I tracked it down (in the config), but thought it could warrant a fix anyway to prevent user frustration in the future.
How to Test
TS_SHOW_ALL_LAYERS=1
was showing duplicate entries when runningTS_ENV=sbx terraspace build mystack
. See output below.I tracked this back to namespace mappings where I had added to
config/app.rb
, see below.Please feel free to reject this fix if you feel it is not necessary due to the improper use of mappings.