Files
floci/src/main/java/io/github/hectorvent
Hector Ventura 2541f1b68d refactor(cloudformation): move the ElasticLoadBalancingV2 types into ElbV2CfnProvisioner (#3115)
* refactor(cloudformation): move the ElasticLoadBalancingV2 types into ElbV2CfnProvisioner

AWS::ElasticLoadBalancingV2::LoadBalancer, TargetGroup, Listener and
ListenerRule leave the legacy switch together with the ELBv2-only helpers
(ELB-safe name generation, full-name derivation, matcher, certificates,
action and rule-condition parsing). The monolith no longer depends on
ElbV2Service; its constructor loses that parameter and CfnProvisionerFixture
passes one argument less.

Behaviour is unchanged except where the move fixes it. An unnamed load
balancer or target group keeps the name its first execution generated, read
back from the LoadBalancerName / TargetGroupName attribute since the physical
id is the ARN; the switch generated a fresh name on every pass and left the
previous resource behind. Listener and ListenerRule branch create-vs-update
on the provision context, and a listener moved to another load balancer or a
rule moved to another listener (both create-only properties) is created as a
replacement instead of being modified under the old parent; one removed out
of band is created again. A non-integer Port or Priority is a ValidationError
instead of an uncaught NumberFormatException. Deletes call the service
directly: it already returns silently for an unknown ARN, and its refusals
(ResourceInUse, OperationNotPermitted) must keep failing the stack delete.

Fn::GetAtt follows the registry schemas' readOnly properties. The five load
balancer attributes, ListenerArn, RuleArn and IsDefault are as before;
TargetGroup gains LoadBalancerArns (comma-joined, empty until a listener
forwards to the group), which the switch never set and the schema coverage
test now requires. CloudFormationIntegrationTest keeps asserting the stack
outputs end to end; ElbV2CfnProvisionerTest covers the four types against a
mocked ElbV2Service. The whole CloudFormation test package passes on this
tree apart from the pre-existing ACM schema-gap row.

* refactor(cloudformation): clean up the ELBv2 entity a replacing update displaced

Review found that a listener moved to another load balancer, or a rule moved
to another listener, was created anew while the displaced one kept running,
holding its target groups in use and never appearing in the stack's cleanup.
The same was true of a renamed load balancer or target group.

Every replacing update of the four types now enters the replacement-cleanup
lifecycle the engine already runs (UPDATE_COMPLETE_CLEANUP_IN_PROGRESS,
DELETE_IN_PROGRESS on the prior ARN, three attempts, UpdateReplacePolicy
Retain honoured). ReplacementCleanup is the plain bookkeeping for provisioners
without a rollback snapshot, beside the richer record PipesCfnProvisioner
keeps; the provisioner delegates the four interface hooks to it and deletes
through its own delete arm. The direct service deletes stay as they were:
ElbV2Service returns silently for an unknown ARN, so there is no already-gone
code for CfnDeletes.safeDelete to tolerate, and its refusals (ResourceInUse,
OperationNotPermitted) must keep failing the stack delete.

* refactor(cloudformation): roll an ELBv2 replacement back and clean up dependents first

Review found two gaps in the replacement handling. A replacement this
provisioner produces (a listener moved to another load balancer, a rule moved
to another listener, a renamed load balancer or target group) could not be
rolled back when a later resource failed the stack update: rollbackUpdate had
no implementation, so the engine reported "Rollback is not implemented", left
the replacement running and the stack in UPDATE_ROLLBACK_FAILED. And the
committed-update cleanup walked resources in creation order, so a target group
renamed in the same update as its listener was moved would be deleted while
the old listener still forwarded to it, fail ResourceInUse three times and be
left behind.

ReplacementCleanup now keeps the attributes the resource carried before the
provision alongside the prior physical id, and rollback() puts both back and
deletes the replacement through the provisioner's own delete arm, spending
the record before the delete so a failing delete cannot put the restored
prior on the next cleanup's list. The provisioner records once, in
provision(), and delegates rollbackUpdate. A load balancer or target group
without a record has nothing to put back, every property being create-only
and the update having only described the existing entity, so it rolls back as
complete; a listener or rule modified in place keeps the engine's existing
handling, as under the switch.

CloudFormationService's committed cleanup walks resources in reverse creation
order, as every other teardown walk does. CloudFormationElbV2ReplacementIntegrationTest
drives both through the engine: a renamed target group plus a moved listener
end with DELETE_COMPLETE events on both prior ARNs and neither entity left,
and a moved listener followed by a failing resource lands the stack in
UPDATE_ROLLBACK_COMPLETE with the prior listener restored and the replacement
gone.

* refactor(cloudformation): order replacement cleanup by the template and keep an orphaned replacement owed

Two gaps in the replacement lifecycle, both found in review. The committed
cleanup walked the resource map reversed, but the map is insertion order and
a resource a later update added sits after the resources that depend on it,
so a target group added after its listener would still be deleted first,
fail ResourceInUse three times and be left behind. The cleanup now walks
resourcesInCreationOrder reversed, the template's dependency order, exactly
as DeleteStack does; a resource the template no longer names sorts last.

And a rollback whose delete of the replacement failed forgot the replacement:
the record was cleared before the delete, so nothing could remove that
entity later even though UPDATE_ROLLBACK_FAILED is updatable here and both
the next committed update and DeleteStack run the cleanup first. The record
is now a list of every entity owed a delete: a replacement whose rollback
delete fails is listed in the prior's place, never retained (a failed update
created it), and the prior's own id and attributes are kept beside the list
only while this update's replacement can still be rolled back. Every listed
entity gets its attempt on every cleanup call, so one that keeps failing does
not leave the others untried.

The load balancer and target group rollback note now says what is true: this
provisioner never modifies an existing one, so an update that kept the name
has nothing to put back (in-place changes to their updatable properties are
not applied, as under the switch).

CloudFormationElbV2ReplacementIntegrationTest gains the appended-dependency
case: a target group added by a later update than its listener, then both
replaced, ends with both prior ARNs DELETE_COMPLETE.

* refactor(cloudformation): keep a displaced entity owed until its own attempts are used up

Review found that once any listed entity reached three failed deletes, the engine's give-up cleared the whole record, forgetting entities that still had attempts left. clearUpdate now drops only the entries that used up their attempts (and the rollback fields), and the cleanup result reports the lowest attempt count among what remains, naming that entity, so the engine keeps retrying until every remaining entity has had its own three attempts.

* refactor(cloudformation): tolerate the ELBv2 not-found codes on delete and name one entity per cleanup

The four ELBv2 deletes go through CfnDeletes.safeDelete with the not-found
code ElbV2Service defines for each type (LoadBalancerNotFound,
TargetGroupNotFound, ListenerNotFound, RuleNotFound), the convention every
other per-service provisioner follows. The service's delete paths return
silently on an unknown ARN today, so nothing changes in behaviour; its
refusals (ResourceInUse, OperationNotPermitted) are not in the list and keep
failing the stack delete.

The replacement cleanup picks the entity it works on through one rule, the
owed entry with the fewest attempts, for both the physical id it announces
(DELETE_IN_PROGRESS) and the one it reports on failure (DELETE_FAILED), so a
cleanup's progress and failure events name the same thing. The unused
parameter on the record's region lookup goes.
2026-09-07 09:17:32 -04:00
..