Modules and outputs
Group declarations in a module when you want to reuse them with different inputs. The calling project supplies the inputs and reads results through named outputs.
On this page
Modules#
module "calc" {
source = "./modules/sum"
a = 2
b = var.start
}
module "greet" {
source = "./modules/greet"
for_each = ["Ann", "Bob"]
name = each.value
}A module is a folder of .st files. Its variables are inputs; its output blocks are read as module.calc.total. count = N (with count.index) and for_each (with each.value) make copies. Modules nest.
Outputs#
In the nested modules example, the outer module exposes its text as an output.
output "said" {
value = var.text
}The calling project uses the module name and output name together.
ability "print" "Done" {
message = "outer says ${module.outer.said}"
depends_on = [module.outer]
}Reading module.NAME.out makes the reader run after module NAME, wherever the reader is written. This holds for an ability, a function body and a module input, so a reader does not need depends_on = [module.NAME] for it. If module NAME itself waits for an ability that reads its output, the two wait for each other and structop validate stops with dependency cycle involving ...; remove one of the two dependencies.
See counted modules to follow each copy from its declaration to the generated program.