Expansion in modules possible?


I am trying to use the terraspace expansion (variable replacement) inside a module, does someone know if this is possible?

It’s not clear if the Ruby remplatin only work on stacks, config and or tfvars

app → modules → common-tags → main.tf

locals {
  tags = {
    ManagedBy = "terraform"
    Environment  = "<%= Terraspace.env %>"
    Stack        = "<%= expansion(':MOD_NAME') %>"
    StackType    = "<%= expansion(':TYPE') %>"
    Region       = "<%= expansion(':REGION') %>"
    Location     = "<%= expansion(':LOCATION') %>"
    Organisation = var.organisation
    Project      = "<%= expansion(':PROJECT') %>"
    App          = "<%= expansion(':APP') %>"

Just for reference for others.
After some testing, I can confirm that the Ruby EBR does not work on any files under app → modules

The ERB templating mainly works on the folders:

  • app → stacks
  • config

Note, there’s a config.build.copy_modules setting. It defaults to true. If you set it config.build.copy_modules = false, then ERB evaluation will also run on modules. However, since folks usually have a large number of module files, it slows down the compile phase.


1 Like

Thanks for the clarification, I figured it out the hard way :slight_smile:

1 Like