Files
floci/docs
lex00 9280369b64 feat(cloudformation): provision ApiGateway::Account, AutoScaling::LifecycleHook, and EC2::FlowLog (#2003)
* feat(cloudformation): provision ApiGateway::Account, AutoScaling::LifecycleHook, and EC2::FlowLog

Three small provisioners over existing services: Account records
metadata (physical id only), LifecycleHook maps onto
AutoScalingService.putLifecycleHook, FlowLog onto
FlowLogService.createFlowLog (newly injected into the provisioner).

Fixes #2002

* feat(cloudformation): per-service provisioners for ApiGateway::Account, AutoScaling::LifecycleHook, and EC2::FlowLog

The three resource types land in the extracted provisioner structure rather
than the switch in CloudFormationResourceProvisioner, one class per service:

- ApiGatewayAccountCfnProvisioner writes CloudWatchRoleArn into the API
  Gateway account settings, so GET /account reflects what the template asked
  for instead of the resource being recorded as a bare physical id.
- AutoScalingLifecycleHookCfnProvisioner puts the hook on its group and
  removes it again when the stack is deleted.
- Ec2FlowLogCfnProvisioner creates the flow log and deletes it when the stack
  is deleted.

Both deletes close the cleanup gaps raised in review: flow logs and lifecycle
hooks no longer outlive their stack. The delete path only holds a physical id,
and a hook's physical id is its name, so AutoScalingService gains
deleteLifecycleHookByName to find the hook whichever group owns it, including
groups that outlive the stack. API Gateway has no DeleteAccount operation and
its account settings are regional rather than stack-owned, so that provisioner
keeps the default no-op delete.

CloudFormationResourceProvisioner is byte-identical to main again: no switch
arms, no FlowLogService injection, and the two constructor-arg test edits are
reverted.

Tests: three isolated provisioner unit tests (one mocked service each) plus
the integration test, extended to cover deletion of the hook and the flow log
against a group created outside the stack.

* fix(cloudformation): delete a lifecycle hook on its own group, not by name alone

A lifecycle hook name is unique within an Auto Scaling group, not within a
region, but the CloudFormation delete path only had the physical id — the hook
name — so it removed every hook with that name in the region. Two groups using
the same hook name meant deleting or rolling back either stack stopped the
other group's lifecycle action.

CfnResourceProvisioner gained a delete overload that receives the whole
StackResource, defaulting to the existing id-only form, and the dispatcher
calls it for extracted provisioners. It sits after the EKS Nodegroup and IAM
policy special cases so extracting one of those later cannot bypass them.

The hook provisioner records its AutoScalingGroupName at create time and
deletes through the group-scoped API. Resources provisioned before that still
fall back to the by-name form: leaving the hook behind is worse, since it can
sit on a group that outlives the stack.

* fix(cloudformation): a stack update reuses its flow log and lifecycle hook

Ec2FlowLogCfnProvisioner called createFlowLog unconditionally, so every
UpdateStack created a second flow log and orphaned the first. The orphan then
outlived the stack, since delete only knows the id recorded last. It now reuses
the log this stack already made and creates only when that one is absent, on a
first execution or after removal out of band.

AutoScalingLifecycleHookCfnProvisioner had the same shape, but only when
LifecycleHookName is omitted: a freshly generated name each update left the
previous hook on the group, still firing, with nothing referencing it. An
unnamed hook now keeps the name its first execution generated. A declared name
needed no change, since putLifecycleHook is idempotent on it.

Both follow EcsCapacityCfnProvisioner. Neither surfaced in CI because no test
here ran an UpdateStack, so each provisioner now has one that does.

* fix(cloudformation): a createOnly change on a flow log or lifecycle hook is reported

Both provisioners reuse the resource the stack already made, so a change to a
property AWS treats as createOnly was being absorbed instead of surfaced.

The flow log reported the stack complete while DescribeFlowLogs kept serving the
previous ResourceId, TrafficType, LogDestination, LogFormat or aggregation
interval. The lifecycle hook was worse, since changing LifecycleHookName or
AutoScalingGroupName created the new hook and overwrote the id delete uses,
leaving the previous hook on its group and still firing.

Both now report an unsupported replacement, matching how EcsCapacityCfnProvisioner
treats a changed Name. A property the template stops declaring, or one the stored
record never captured, is left alone rather than read as a change.

* docs(cloudformation): list ApiGateway Account, LifecycleHook and FlowLog in the resource-type table

* fix(cloudformation): dropping a flow log's createOnly property is a change

rejectIfChanged returned early whenever the template supplied no value, so
removing a previously explicit LogFormat or MaxAggregationInterval skipped
validation entirely and the stack reported complete while DescribeFlowLogs kept
serving the old one.

An absent stored value still means leave it alone, since that is not evidence of
a different one, but an absent requested value is now compared rather than
skipped. MaxAggregationInterval compares against its documented default of 600
when the template omits it, which is the value a create would have used.

* fix(cloudformation): a flow log's createOnly comparison uses effective values

Removing the early return on a blank request fixed the dropped-property case and
broke two others. createFlowLog defaults ResourceType, TrafficType and
LogDestinationType, so re-applying an unchanged template compared null against a
stored default and failed a no-op update, while adding a property to a log that
never had one still returned early on the stored null and was ignored.

Both sides are now the effective value, defaulting the requested side exactly as
createFlowLog does, so add, drop and change all read as changes and a re-apply
stays a no-op. The test helper stamps the same three defaults, since a stub
without them is not a flow log this provisioner could have created.
2026-08-16 20:41:41 -05:00
..
2026-03-15 17:43:56 -05:00