0

I'm creating a Terraspace project to build multiple stacks (about 14 in total) that share some vars. I will create multiple copies of this stack (about 20) so I don't want to have to manage multiple tfvars in each stack, that would be 280 in total. So I decided to put all the tfvars as global into the /configuration/terraform folder. I have one file per each environment with all the variables in it. This is working fine but the problem I have now is that all the stacks get all the vars, which is expected, but I'm getting lots of warnings from Terraform that make the console output difficult to read. I was hoping there is a way to have a filter or post-processor to be applied to the generated tfvars to remove unused variables. Something similar to the "seed" feature that analyzes the variables and generates a sample tfvar only with the existing variables. Is there any existing feature or plan for it?

thanks

1 Answers1

0

Unfortunately I am not aware of way to filter output other than modifying terraspace's handle_stdout function.

On other hand there is a way to organize code so that there is no need in superfluous variables passed to stacks or extra tfvar files. You can create dummy stack that only copies it's input variables to output. This will be bootstrap stack that has all the variables. Then in other stacks configure dependency on bootstrap stack and load only required variables from it with output() helper.

Here is example structure:

app/stacks/bootstrap/variables.tf

variable "foo" { type = string }
variable "bar" { type = string }

app/stacks/bootstrap/outputs.tf

output "foo" { value = var.foo }
output "bar" { value = var.bar }

app/stacks/bootstrap/tfvars/env_1.tfvars

foo = "foo"
bar = "bar"

app/stacks/stack1/tfvars/base.tfvars

# stack1 only requires foo
foo = "<%= output('bootstrap.foo') %>"

app/stacks/stack2/tfvars/base.tfvars

# stack2 only requires bar
bar = "<%= output('bootstrap.bar') %>"
Vladimir
  • 615
  • 5
  • 12