Files
floci/docs
Hector Ventura 895adce214 fix(cloudformation): provision CloudFront policies and origin access controls (#3228)
* fix(cloudformation): provision CloudFront policies and origin access controls

AWS::CloudFront::ResponseHeadersPolicy, CachePolicy, OriginRequestPolicy
and OriginAccessControl had no provisioner, so the dispatcher's stub arm
reported CREATE_COMPLETE with a synthetic id and a distribution that
referenced it failed with "The specified response headers policy does not
exist."

A new CloudFrontCfnProvisioner creates each type through CloudFrontService:
the physical id is the service id, Fn::GetAtt exposes Id and LastModifiedTime
(Id only for the origin access control, per the registry schemas), updates go
through the service's etag-guarded update, and deletes tolerate only the
type's own not-found code so an in-use policy fails the stack delete as on
AWS. The response headers configuration is reshaped into the flattened form
the service's codec stores through the new
ResponseHeadersPolicyConfigCodec.fromItemsTree.

Closes #2441

* fix(cloudfront): reject deleting a cache or origin request policy in use

DeleteCachePolicy declares CachePolicyInUse and DeleteOriginRequestPolicy
declares OriginRequestPolicyInUse, both 409 sender faults, and both are
documented as refusing the delete while the policy is attached to a cache
behavior. Floci checked only two of the four policy-shaped types:
deleteResponseHeadersPolicy and deleteOriginAccessControl raised their in-use
errors, while these two deleted unconditionally once the etag matched. A policy
still referenced by a distribution could be removed, leaving that distribution
pointing at something that no longer existed.

Both now raise the modeled error after the etag check, matching the ordering the
other two deletes already use. Cache, origin request and response headers
policies all hang off the same two places, a distribution's default cache
behavior and its ordered ones, so the three near-identical scans collapse into
one helper that differs only in which id it reads. The per-distribution
association count keeps its own entry point, since it asks about one config at a
time and can be handed a distribution with none.

Found while reviewing the CloudFormation provisioner in this PR, which was
already written for this: its delete tolerates only NoSuch<Type>, so it fails
the stack correctly now that the service raises the in-use error. The
CloudFormation integration test covers that end to end: it attaches both
policies to a distribution and still deletes the stack cleanly, because
CloudFormation removes the distribution before the policies it references.

Four tests: a cache policy attached to a default behavior and to an ordered one,
an origin request policy in use, and an unattached policy still deleting.

* test(cloudformation): parse stack outputs with XmlParser

The CloudFront policies integration test pulled Outputs out of the DescribeStacks
response with two regular expressions over <member> and <OutputValue> blocks.
XmlParser.extractPairs already does exactly this, and seventeen sibling
CloudFormation integration tests define the same one-line helper over it, so the
twelve-line version was reinventing a shared utility. It also matches the repo's
rule against parsing XML with regex.

Behaviour is unchanged, including the failure message that names the missing key.

* fix(cloudformation): roll back a recreated CloudFront policy on a failed update

When an update finds the prior policy or origin access control already deleted
out of band, the provisioner recreates it under a new physical id. If a later
resource then failed the stack update, the rollback left that new object behind:
the engine only deletes resources the update ADDED, inside the previous == null
branch of rollbackUpdatedResources, so an existing resource that merely acquired
a new physical id fell through to the "Rollback is not implemented" arm, which
deletes nothing.

ReplacementCleanup already models exactly this, and CognitoCfnProvisioner wires
it for the same situation, so the provisioner records the displaced entity after
each provision and delegates the cleanup hooks and rollbackUpdate to it. A
rollback now names the prior id again with the attributes it carried and deletes
the object the failed update created.

The physical id changes here only when the prior object was already gone, since
prior() returns the entity whenever the service still knows it, so the recorded
displaced entity is always one that no longer exists and its cleanup delete is a
no-op tolerated by the type's not-found code. The hooks are still needed, or a
recorded entity would stay owed a delete forever.

An in-place update keeps its physical id, so nothing is recorded and
rollbackUpdate answers false: putting a committed in-place change back needs a
configuration snapshot this provisioner does not keep, the same limitation
AWS::Cognito::UserPool has. A test pins that so it stays a decision.

Raised by the review on this PR. My first reply argued the finding did not hold,
generalising from the create path; that was wrong for this one, and the
correction is on the thread.
2026-09-09 09:32:52 -04:00
..
2026-03-15 17:43:56 -05:00