addModule<T extends ModuleCall> method

T addModule<T extends ModuleCall>(
  1. T call
)

Register a module "<localName>" { ... } call. Returns the same instance, so the call site can read the module's outputs from it:

final sa = addModule(ModuleCall(
  'sa_bff',
  source: '../modules/service_account',
  inputs: {'account_id': .literal('app-bff-sa')},
));
addOutput('bff_member', sa.output<String>('member'));

Throws DuplicateModuleError when a call of the same ModuleCall.localName is already registered — Terraform addresses both as module.<localName>.

Implementation

T addModule<T extends ModuleCall>(T call) {
  _checkLocalName(call.localName, call.tfAddress);
  if (_modules.containsKey(call.localName)) {
    throw DuplicateModuleError(call.localName);
  }
  _modules[call.localName] = call;
  return call;
}