resourceBlock static method

Map<String, dynamic> resourceBlock(
  1. Resource r, {
  2. bool devModeInjectDeletionProtection = false,
})

JSON for one resource block: argMap + optional depends_on + optional lifecycle + optional timeouts.

When devModeInjectDeletionProtection is true and the resource exposes supportsDeletionProtection == true and its argMap does not already contain deletion_protection, false is injected so dev stacks can be torn down without manual overrides.

Implementation

static Map<String, dynamic> resourceBlock(
  Resource r, {
  bool devModeInjectDeletionProtection = false,
}) {
  // `@protected` on the Resource getters expresses subclass-only contract
  // intent; the synth pipeline is the privileged in-library consumer that
  // reads them. `ignore` is the standard escape hatch for this case.
  final argMap =
      devModeInjectDeletionProtection &&
          // ignore: invalid_use_of_protected_member
          r.supportsDeletionProtection &&
          !r.argMap.containsKey('deletion_protection')
      ? <String, TfArg<dynamic>?>{
          ...r.argMap,
          'deletion_protection': const TfArgLiteral<bool>(false),
        }
      : r.argMap;
  final out = encodeArgMap(argMap);
  final provider = blockProvider(r);
  if (provider != null) out['provider'] = provider;
  final deps = r.dependsOn;
  if (deps != null) {
    final dep = dependsOn(deps);
    if (dep != null) out['depends_on'] = dep;
  }
  final lc = r.lifecycle;
  if (lc != null) {
    final life = lifecycleBlock(lc);
    if (life != null) out['lifecycle'] = life;
  }
  final timeouts = r.timeouts?.toTfJson();
  if (timeouts != null) out['timeouts'] = timeouts;
  return out;
}