mirror of
https://github.com/floci-io/floci.git
synced 2026-11-29 00:21:51 -05:00
When a stack update sent a custom resource's handler an Update and the update then failed, Floci never told the handler. If a later resource failed, the rollback recorded "Rollback is not implemented for Custom::..." and the stack ended UPDATE_ROLLBACK_FAILED with the handler's change still applied. If the handler failed its own Update, Floci put the previous resource back in silence. In both cases CloudFormation sends the handler a second Update with the previous properties so it can undo the change. CustomResourceCfnProvisioner now snapshots the resource before an Update reaches its handler: the prior physical id, the old and the attempted properties, the region and the Data attributes, under the new CUSTOM_RESOURCE_UPDATE_SNAPSHOT_ATTR. A stale snapshot from an earlier update is dropped first, so an update that sends nothing needs no rollback. The ServiceToken is checked as Lambda's Invoke checks it before the snapshot is written, so an Update rejected before it reaches any handler is restored as before and sends no rollback request. While the snapshot is held, retainsFailedUpdateState answers true, so an Update the handler failed keeps its copy for the rollback walker instead of being restored over. Its rollbackUpdate spends the snapshot: - the physical id was kept: report UPDATE_IN_PROGRESS and send Update with the old properties as ResourceProperties and the attempted ones as OldResourceProperties, under the same physical id and stack id. On SUCCESS the Data attributes are replaced by the response's. A response naming another id is taken, and the id that was sent gets a best effort Delete with the attempted properties at once, since Floci has no rollback cleanup phase. - the handler replaced the resource: send a best effort Delete for the new id with the attempted properties and point the resource back at the old id and attributes, with no Update. CloudFormation sends this Delete in its cleanup phase; Floci sends it during the rollback. The old properties become the resource's own before the handler is called, as on AWS, which treats the rollback target as the resource's properties even when the handler fails it: a later DeleteStack sends them in its Delete and the next update sends them as OldResourceProperties. A FAILED answer throws with the handler's Reason, so the resource is UPDATE_FAILED and the stack UPDATE_ROLLBACK_FAILED, as on AWS, and the snapshot stays so a retry sends the same Update again.