Skip to content

[FEATURE] lets-block for bundles #2299

@cwe1ss

Description

@cwe1ss

Is your feature request related to a problem? Please describe.
It would be great to have a block within my bundles where I can write reusable logic and that I can reference within my component calls and exports. Right now I have to duplicate the logic for every call.

This would allow me to e.g. calculate values from multiple inputs, lookup a different bundle instance using tm_bundle(...), load file content, etc., and reference those variables from multiple locations within my bundle.

Describe the solution you'd like
Support a define bundle lets-block, which works the same way as the lets-block within e.g. the generate_hcl-block. It should allow me to use any terramate function, and it should allow me to reference the bundle inputs.

I should then be able to reference variables from the lets-block via bundle.let.{variable} in my define bundle stack-blocks and define bundle export-blocks.

Example:

define bundle lets {
  # Call any terramate function
  cluster = tm_bundle("example.com/cluster", bundle.input.cluster.value)
  # Reference another variable in the same block
  region = let.cluster.export.region.value
  # store some reusable logic
  service_name = tm_join("-", [cluster.export.name.value, bundle.input.name.value])
}

# Reference a let-variable in an export
define bundle export "service_name" {
  value = bundle.let.service_name
}

# Reference the variable in a bundle stack
define bundle stack "service" {
  metadata {
    tags = [
      "region/${bundle.let.region}",
    ]
  }
  component "service" {
    source = "/components/service"
    inputs = {
      cluster = bundle.let.cluster.export.name.value
      region = bundle.let.region
    }
  }
}

Describe alternatives you've considered
Duplicate the necessary logic in every usage.

Additional context
none

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions