Files
floci/tools
Anders Wasen bfa9c2fbcc feat(cloudformation): provision Application Auto Scaling targets and policies (#5407)
* feat(cloudformation): provision Application Auto Scaling targets and policies

AWS::ApplicationAutoScaling::ScalableTarget and ::ScalingPolicy had no
provisioner, so a template that scales an ECS service failed on those two
resources although the Application Auto Scaling service behind them, including
the ECS capacity adjuster, was already there. This wires the two together.

A scalable target has no name of its own: it is keyed by the triple of service
namespace, resource id and scalable dimension, and CloudFormation's Ref is those
three joined by a pipe. That composite is the physical id, which is also what a
policy's ScalingTargetId carries when a template points one at the other with
Ref, so the provisioner splits it back into the triple. A policy's Ref is its
ARN rather than its name, so deleting one resolves the ARN through
findPolicyByArn to recover the name and triple the service deletes by.

Because the target's id is derived from the triple, changing any part of it
replaces the target rather than updating it, so both types go through
ReplacementCleanup to deregister what they displaced. Deletes tolerate only
ObjectNotFoundException through CfnDeletes.safeDelete: a target takes its own
policies with it, so a stack teardown reaches an already-deleted policy by
ordinary ordering, while any other failure still surfaces as DELETE_FAILED.

The properties each schema marks required are enforced rather than defaulted.
MinCapacity and MaxCapacity on a target, and PolicyName and PolicyType on a
policy, would otherwise register a target that never scales or accept a template
CloudFormation itself rejects.

The two scaling configuration blocks are parsed by the same code the
PutScalingPolicy API path uses, extracted to ScalingConfigurationParser, since
CloudFormation spells their members exactly as the API does. One parser means a
template and an API call cannot disagree about what a policy means.

ScheduledActions on a target is logged rather than dropped silently: Floci does
not run scheduled scaling, and a template that scales on a clock should not look
fully provisioned when nothing is scheduled.

* fix(cloudformation): resolve intrinsics inside the scaling configuration blocks

Review on #5407: the two scaling configuration blocks and SuspendedState reached
the parser as raw template JSON, so an intrinsic inside one was never resolved.
That is worse than it sounds, because an intrinsic is still a non-null node:
hasNonNull passes and the value is read with asDouble, asText or asBoolean,
which answer 0, "" and false. A policy written as TargetValue: !Ref TargetCpu
registered as a policy targeting 0 percent rather than failing, a ResourceLabel
built with Fn::Join arrived empty, and a flag behind Fn::If read false.

Each block now goes through ctx.engine().resolveNode first, which is what
AutoScalingScalingPolicyCfnProvisioner already does with its own block. Only
nested objects were affected: the top-level properties were already read through
ctx.resolveOptional, which resolves.

A target's Tags were dropped as well, passed to the service as an empty map
rather than read with ctx.resolveTags.

ScheduledActions now carries a note in the generated resource-type table rather
than only a warning in the log, so the gap is visible before someone wonders why
their clock-based scaling never fires.

* test(cloudformation): make the SuspendedState intrinsic test fail without its fix

Review on #5407: anIntrinsicInsideSuspendedStateIsResolvedToo passed against the
previous commit too. REFS had no Suspend entry, so the flag resolved to an empty
string and read false either way, and assertNotNull held regardless because the
raw block was already an object. The test pinned nothing.

REFS now maps Suspend to true and the assertion is on
isDynamicScalingInSuspended(), so it fails with expected: <true> but was:
<false> when SuspendedState is read without resolveNode. The redundant copy of
the properties node is gone.
2026-10-11 12:19:25 -04:00
..