encodeArg static method

Object? encodeArg(
  1. TfArg arg
)

Encode a single TfArg into a JSON-serialisable value.

  • TfArgLiteral<T> → the raw T value (recursively walked in case the literal is a Map/List that itself contains TfArgs).
  • TfRef<T> → the ${...} interpolation string.
  • TfArgVariable<T> → the ${var.<name>} interpolation string.
  • TfArgExpression<T> → its template string, verbatim.

Implementation

static Object? encodeArg(TfArg<dynamic> arg) {
  final raw = arg.toTfJson();
  // Refs, variables and expressions produce final string forms (Terraform
  // templates). Only literals may still hold nested `TfArg` instances
  // inside Maps/Lists that need recursion.
  if (arg is TfRef || arg is TfArgVariable || arg is TfArgExpression) {
    return raw;
  }
  return _encodeLiteralValue(raw);
}