Skip to content
cdkd

cdkd rollback internals

The rules behind the cases that cdkd rollback, cdkd rollback: failed operations and cdkd rollback: limitations summarise: when an operation is skipped or refused, how cdkd decides that a resource a failed CREATE left behind is safe to delete, and how a replacement is reversed.

An operation cdkd cannot address

An operation whose resource cdkd cannot address is skipped with a warning (exit 2): its state record's physicalId (for a rolled-back CREATE, the journaled one) is absent, empty, whitespace-only or not a string. Only a hand-edited or torn state.json or journal has that shape. Nothing is sent to AWS for it, and the resource and its record are left as they are; repair the record's physicalId (cdkd state show) and re-converge with cdkd deploy. A failed CREATE that no state record holds is named for manual attention instead, since the journal entry was its only record. A nested stack's record is exempt, since its child is found by name, unless it is recorded on Cloud Control. A replacement whose new copy is kept (UpdateReplacePolicy: Retain) sends nothing by that id and is reverted as usual. One case fails instead of skipping (exit 1, journal kept): re-adopting a retained old resource, which only the journal names. When the journal holds a usable id for the replacement's new resource, the message prints it: repair the record to that id and re-run the rollback (any other id stops the revert and drops the journal's only record of the retained old resource). When the journal holds none, the re-run deletes whatever resource the repaired record names as the new copy, so name the right one. When the journal's id is present but unusable too, or the record holds a different id, nothing proves which resource is the new copy, so it is not deleted and no repair makes the re-run succeed. Check both resources by hand. Re-running with the --orphan command the message prints leaves it as it is, but also drops the journal's only record of the retained old resource, so note the old id the message names first. The same applies to --revert-failed and to the automatic rollback.

--revert-failed, per failed operation

Failed operation With --revert-failed
UPDATE Force-reverted to its pre-deploy properties. The journal records the attempted properties, so patch-based providers generate a real undo diff.
UPDATE that was a replacement whose new resource was made and then failed (journaled beside it, see below) Never force-reverted: the update applied nothing to the old resource. When the replacement created first, the old resource is untouched and nothing is done. When it deleted the old resource first, the old one is re-created (next row); a journal written without that fact only warns (exit 2) that the resource state records is gone, and a cdkd destroy drops the record. The new resource's own entry is acted on, and this one is cleared with it on every path, so a later --revert-failed never sees it alone.
UPDATE that was a replacement which deleted the old resource before its create failed: a type CloudFormation replaces delete-first (an AWS::EC2::EIPAssociation, SubnetRouteTableAssociation or VPCGatewayAttachment), or any type a delete-first route replaced (--replace for a custom name, --recreate-via-*, the update-unsupported fallback) Re-created from its recorded properties under the same name, with or without --revert-failed, as the automatic rollback does; state records the re-created resource. Its data does not come back. A new copy still there holds the re-create back: kept in the journal while its delete is retried, a warned skip when it is retained.
UPDATE that changed the resource's Type Skipped with a warning; it was a replacement in flight, and there is no in-place revert of one.
UPDATE whose state record has no usable physicalId (a cdkd deploy refusal over a hand-edited record still journals the op) Skipped with a warning (exit 2); nothing is sent. See An operation cdkd cannot address.
CREATE that recorded a physical id, which state still records Deleted, honouring its DeletionPolicy — see DeletionPolicy on a rolled-back CREATE.
CREATE that made its resource and then failed (the provider proved its create call returned, e.g. a Kinesis stream whose retention follow-up AWS rejected) Deleted, honouring the template's DeletionPolicy as journaled — this entry is the only record of that resource. Under Retain it is left in AWS with no rollback-orphan record (it was never in state), so a later deploy cannot re-adopt it. Deleted only while nothing later can own it. It is skipped with a warning naming the physical id (exit 2), since the resource may still exist untracked and need manual attention, when a NEWER journal segment holds an operation of its type naming its physical id or previous physical id, or a completed CREATE of its type; when a later segment's removal superseded its logical id; or when a rollback-orphan record holds its logical or physical id. Otherwise state decides: a state resource under its logical id with the same physical id, or one of its type holding that physical id under another logical id, tracks it and the skip is silent; a different physical id under its logical id warns (exit 2), unless that record is the resource a replacement was replacing (see below). When the entry is one a successful fix-forward deploy kept (a delete that failed, or an S3 bucket it never empties), cdkd rollback and cdkd destroy first ask the provider again whether that record is another resource, and the preview shows the answer: proven, the entry is deleted while its creation identity still matches, or dropped when the resource is already gone; unproven, it is warned about as above. A redeploy whose create only collided with its name does not stop the delete. Roll the stack back before redeploying: a redeploy that re-creates the same name, or under --no-rollback completes any CREATE of its type, makes the newer entry decide, and this one is then only warned about. SDK providers whose create makes a follow-up call after their create call returned prove it where the id is known and the create made the resource (an adopted or pre-existing resource is never marked), unless their own cleanup already deleted it (AWS::IAM::Policy instead removes its own writes and warns when that fails).
CREATE that recorded a physical id, with no state record left Nothing to do — already cleaned up (a re-run).
CREATE that recorded a physical id other than the one state now records under its logical id (not the record a replacement was replacing — see below) Skipped with a warning (exit 2); nothing is deleted. The resource it recorded may still exist, untracked: the plan line names it (recorded <its physical id>, which is not the resource state tracks under this id; not reverted, needs manual attention). Reached when another resource took the id without an import mark, such as a cdkd import by an older cdkd, or when a newer segment's reverted replacement re-created the resource under a new physical id (the recorded one is then usually already gone); a marked import is reported as in Interaction with cdkd import.
CREATE that recorded no physical id Skipped with a warning; there is nothing addressable to act on. A CREATE cdkd refused before anything was applied (another resource already holds its explicit name) is not journaled at all.
CREATE that recorded no physical id, which AWS refused because its name is already taken, held by another record of this stack in the same scope (a construct renamed with an explicit name) Nothing to do: the create made nothing. Reported at info, not counted as a skip (exit 0). The line says nothing was created, names the record that holds the name, and says not to delete or import that resource. The deploy's rollback and cdkd rollback's plan print the same advice, and the plan suggests no --revert-failed.
CREATE that recorded no physical id, which AWS refused because its name is already taken, with no holder among this stack's records Skipped with a warning (exit 2). The warning asks to confirm who holds the name before deleting it: the holder may be a resource an earlier attempt of this create made before its response was lost. A journal written by an older cdkd keeps the generic "if it was partially created in AWS, delete it manually" advice.
DELETE Nothing to do — the resource is still in place.

The action only engages when AWS actually provisioned the resource: it requires a recorded physical id and either a matching state record or the provider's proof that its create call returned, so the policy is never applied to a resource that never existed. The physical id a failed create's error names is not such proof on its own: it is also the name of a resource the create collided with.

Failed CREATEs that made their resource

A CREATE whose provider proved the resource was made before the failure (the table row above) has no state record. The rollbacks, cdkd destroy and a successful deploy act on its journal entry before they drop it, as CloudFormation's rollback deletes a failed CREATE:

Path What happens to the resource
Automatic rollback Deleted before the completed operations are reverted, per its DeletionPolicy.
--no-rollback failure Nothing is deleted; the journal keeps the entry for a later cdkd rollback.
cdkd rollback, with or without --revert-failed Deleted, per its DeletionPolicy. Other failed operations still need the flag.
cdkd destroy Deleted first, per its DeletionPolicy, before the journal is removed with the state. A journal destroy cannot read is warned about and removed with the state, and nothing it records is deleted.
A later successful cdkd deploy Deleted, per its DeletionPolicy, before the deploy removes the journal, but only when, after the deploy, no state record sits under its logical id and the deploy completed no operation under it (or the record under it holds a resource that a live read proves is a different one, see below), no record of the stack holds a resource of its type under its physical id, and no resource or rollback-orphan record of any other stack under the same state prefix does. A record of the stack holding that very resource tracks it, and the entry is dropped silently. Otherwise it is not deleted: the deploy warns, naming its physical id so you can delete it if it is not that record's resource, removes the entry with the journal, and exits 2. A fix-forward that keeps the logical id under another name puts a new resource there: for an AWS::Kinesis::Stream, the deploy reads both streams live and deletes the earlier one when it is proven a different stream (never when it shares the record's name, when the record's stream is not found, or when a read fails; an earlier stream already gone is named at info and nothing is deleted), and a read proving it the same resource tracks it, silently. An AWS::EC2::NatGateway or AWS::EC2::EIP is compared the same way, by its nat- id or eipalloc- allocation id; an earlier one already gone (or a NAT gateway its create left failed) is still sent the delete, which finds it gone or removes it. An AWS::RDS::DBCluster or AWS::RDS::DBInstance is compared by its resource id (DbClusterResourceId / DbiResourceId); an identifier that differs from the record's only in case names the same resource, since RDS identifiers are case-insensitive. An AWS::DocDB::DBCluster or AWS::DocDB::DBInstance is compared the same way; an identifier now held by an RDS or Neptune resource, which share the namespace, is never read as the DocumentDB one, so it lands in the warning above. An AWS::Neptune::DBCluster or AWS::Neptune::DBInstance is compared the same way; an identifier now held by an RDS or DocumentDB resource is never read as the Neptune one, so it lands in the warning above. An AWS::S3::Bucket is compared by name: bucket names are global and cannot be changed, so two names are two buckets, once the record's bucket reads back in the stack's region. An AWS::DynamoDB::Table is compared by its TableId, which AWS generates and never gives a later table, once the record's table reads back in the stack's region; table names are case-sensitive, so two names differing only in case are read as two tables. An AWS::DynamoDB::GlobalTable is compared the same way, by the TableId of its table in the stack's region. An AWS::Lambda::Function is compared by name: function names are unique per account and region and cannot be changed, so two names are two functions, once the record's function reads back in the stack's region; two names differing only in case are never compared, and land in the warning above. An AWS::IAM::Role is compared by its RoleId, which IAM generates at create and never gives a later role, once the record's role reads back; role names are unique per account regardless of case and cannot be changed, so a record holding the earlier role's name in another case holds that very role: it tracks it, and the entry is dropped silently. An AWS::IAM::User or AWS::IAM::Group is compared by its UserId or GroupId, which IAM generates at create and never gives a later user or group, once the record's user or group reads back; user and group names are unique per account regardless of case, so a record holding the earlier name in another case holds that very user or group, and is tracked silently too. An AWS::IAM::InstanceProfile is compared the same way, by its InstanceProfileId. An AWS::IAM::ManagedPolicy is compared by its PolicyId, once the record's policy reads back; its physical id is the policy ARN, and an ARN that differs from the record's only in case names that very policy and is tracked silently, while two ARNs whose policy names are equal ignoring case but whose paths differ are never compared, and land in the warning above. An AWS::Logs::LogGroup is compared by name: log group names are unique per account and region and cannot be changed, so two names are two log groups, once the record's log group reads back in the stack's region; two names differing only in case are never compared, and land in the warning above. An AWS::Pipes::Pipe is compared by name the same way: pipe names are unique per account and region and cannot be changed. An AWS::IAM::AccessKey is compared by its access key id, and an AWS::ServiceDiscovery::PrivateDnsNamespace, PublicDnsNamespace, HttpNamespace or Service by its ns- or srv- id: AWS generates each and never gives it to a later resource, so two ids are two resources, once the record's key, namespace (of the record's kind) or service reads back. A bucket a failed CREATE left behind is never emptied on any of these paths, even when its template declared autoDeleteObjects: one that is not empty (something wrote to it after that create) is kept, named in a warning, and stays in the journal. An RDS or Neptune cluster or instance, or a DynamoDB table or global table, that Cloud Control provisioned is never compared, and lands there too. Every other type, and any read that cannot prove either way, lands in the warning above, so the earlier attempt's resource is left for you to delete. On either path, before the delete, a type whose physical id is a name (most types) must also prove that the resource now answering to that name is the one the failed CREATE made, since you may have deleted it and something else may have reused the name: the failed deploy records the provider's identity for it (for an AWS::Kinesis::Stream, its ARN and creation time; for an RDS, DocumentDB or Neptune cluster or instance, its resource id; for an AWS::S3::Bucket, its name, region and the CreationDate this account's ListBuckets reports; outside us-east-1 S3 moves that date on a later versioning, tagging, encryption or policy change, which leaves the bucket in the warning above; for an AWS::DynamoDB::Table or AWS::DynamoDB::GlobalTable, the TableId its CreateTable returned; for an AWS::Lambda::Function, its ARN and the LastModified its CreateFunction returned, which a later code or configuration update moves, leaving the function in the warning above; for an AWS::IAM::Role, the RoleId its CreateRole returned; for an AWS::IAM::User or AWS::IAM::Group, the UserId or GroupId its CreateUser or CreateGroup returned; for an AWS::IAM::InstanceProfile, the InstanceProfileId its CreateInstanceProfile returned; for an AWS::IAM::ManagedPolicy, the PolicyId its CreatePolicy returned; for an AWS::ECR::Repository, the createdAt its CreateRepository returned, in whole seconds; for an AWS::Logs::LogGroup, its ARN and the creationTime DescribeLogGroups reports, read when the failure is journaled, since CreateLogGroup returns neither; for an AWS::Pipes::Pipe, its ARN and CreationTime in whole seconds, from CreatePipe's answer, else read when the failure is journaled; a pipe a live read finds DELETING returns no identity, which leaves it in the warning above), and the deploy deletes it only when a live read returns the same identity; one a live read reports gone is named at info, nothing is deleted, and its entry is dropped. With no recorded identity (a provider without one, a read that failed, or a journal an older cdkd wrote), or a different one, it lands in the warning above. Types whose physical id AWS generates and never reuses (an EC2 vpc- / nat- / sg- id, an EFS or FSx file system, a KMS key, an ELBv2 ARN, and similar), an AWS::SQS::QueuePolicy / AWS::SNS::TopicPolicy, whose delete compares the policy it finds, and a nested stack, whose id only cdkd mints, need no recorded identity. A top-level deploy does the same for each nested stack's journal, judged by that stack's record. A journal the deploy cannot read is warned about and removed, and nothing it records is deleted.

A replacement whose new resource was made before the failure is journaled the same way, beside the replacement's failed UPDATE, and every path above acts on it. The state record under its logical id is then the resource the replacement was replacing; while that record still names the same resource, it does not count as an owner of the new one, and acting on the new one leaves it in place. A record naming anything else still skips the new resource with a warning.

Wherever a path above asks whether a record holds the resource under its physical id, a type whose identifiers AWS matches regardless of case compares them that way: a record holding mycluster (a cdkd import that spelled it so, say) holds the cluster the journal names MyCluster, and the resource is kept. These are RDS, DocumentDB and Neptune DB clusters, DB instances and subnet groups, ElastiCache cache clusters and subnet groups, IAM roles, users, groups, instance profiles and managed policies, and a Glue table (ASCII letters only). Every other type compares the id exactly.

An AWS::SQS::QueuePolicy or AWS::SNS::TopicPolicy that wrote its policy to some queues or topics and then failed is journaled under exactly those queues or topics. When any path above deletes it, each queue is cleared, and each topic reset to SNS's default policy, only while its policy still matches, by content, the document the failed create attempted (secret references in it are resolved first). A topic already on its default policy needs nothing. A queue or topic whose policy was replaced by a different policy is left as it is, with a warning naming it, and the rollback or deploy exits 2; cdkd destroy warns only. A successful deploy also leaves, the same way, a queue or topic that one of its own policies just wrote, because the service can still return the old policy for a while (SQS documents up to 60 seconds). A queue or topic that reads back with no policy at all is cleared. The comparison treats some IAM-equivalent spellings as equal (a bare account id and its root ARN, a one-element list and its value, a "*" principal and {"AWS": "*"}): SQS stores a bare account-id principal as arn:aws:iam::<id>:root. When the document is missing or masked, or a secret it references does not exist or cdkd refuses it for good, nothing is cleared, the warning lists every queue or topic to check by hand, and the entry is settled with exit 2. Any other failure to read a policy or resolve a secret (credentials, access, throttling, the network, an ambiguous reference region in a nested stack's replay) keeps the entry, and the delete counts as failed, for a re-run once that is fixed.

Retain keeps the resource in AWS and Snapshot takes the final snapshot, as in the table above, and the same ownership checks skip it with a warning. A delete that fails keeps the entry: the automatic rollback keeps its full segment, and cdkd destroy keeps the state and the journal for a re-run. A successful deploy keeps the entry only when it could not act on it (a delete that failed, an interrupt, or a state record it could not read, or a legacy record with no region, anywhere under the state prefix); it keeps the journal (reduced to that entry where it can), warns, and exits 2 (--allow-unaddressed exits 0), and the next successful deploy retries it.

Reversing a replacement

A replacement is undone by reversing it: the old resource is re-CREATEd from its journaled pre-deploy state (a create-first old resource whose delete was still deferred is still in AWS, so it is re-adopted instead), and the new resource is deleted unless its own UpdateReplacePolicy: Retain says otherwise (see below). A custom resource whose Update handler answered a new physical id is the exception: its old id was never deleted, so the rollback sends the new id an Update with the old properties instead, as CloudFormation does, and once the rollback has completed deletes the id the handler moved it off. A journal written by an older cdkd lacks the mark that says so and keeps the re-create. The default order is create-first; when a user-supplied physical name is still held by the new resource, cdkd falls back to delete-new-first with a bounded name-release retry.

A deferred old resource is re-adopted after the rollback reads AWS for it, and no snapshot of it is taken: under UpdateReplacePolicy: Snapshot its snapshot belongs to the deferred delete, pre-delete snapshot types (an EBS volume, a Redshift cluster, an ElastiCache replication group) included. When that read cannot answer (the type has no read, or the read fails), the automatic rollback still re-adopts it, since that deploy sent no delete. A later cdkd rollback re-adopts it only while state still lists it as awaiting its delete, and otherwise refuses, since a later deploy may have sent the delete since. The deferred delete of a custom resource or nested stack that needs a NoEcho value is never in state, so when its read cannot answer, a later cdkd rollback refuses it.

Before re-adopting an old resource AWS still reports, the rollback compares the AWS-assigned id its old record carries, where its type has one (an IAM role's RoleId, a managed policy's PolicyId, a DynamoDB table's TableId, an RDS instance's DbiResourceId or cluster's DBClusterResourceId), or, for a log group, Step Functions state machine or ECR repository, the creation time cdkd records for it: a different value is refused, since another resource took the name. Where nothing can be compared (a type with no such id, a record written before cdkd kept it), the resource is re-adopted as before, with one ⚠ line saying cdkd could not prove it is the one it created and naming cdkd state orphan --resource <logicalId> to drop its record if it is not this stack's; that line leaves the exit code as it was. A recorded id that could not be compared (a redacted value, an identity read that failed or could not name the resource) takes the rule for a read that cannot answer, with its own wording: a deferred old resource still listed in state is re-adopted with the same kind of line, and every other case is refused, saying that only a failed read is worth re-running cdkd rollback for.

A deferred AWS::S3::Bucket is judged by who holds the old name, because bucket names are global and another party can take the name after an out-of-band delete. When the deploy defers the delete, it journals the bucket's CreationDate. Before the rollback replays any operation, it reads who holds each such name (ListBuckets and GetBucketLocation). Then:

  • Refused, whatever the existence read answered:
    • a bucket that is not in this account's ListBuckets, or is in another region;
    • a bucket that was absent when the rollback started and that AWS now reports, or whose current state cannot be read;
    • this account's bucket with a date other than the journaled one. In us-east-1 only a re-create moves the date, so it is refused as another bucket. Elsewhere a versioning, tagging, encryption or policy write also moves it, so it is refused with a message saying the bucket may have been re-created or modified.
  • Re-adopted when the dates match. Just before the re-adopt, who holds the name is read again. A bucket that is now another account's or in another region is refused, and so is a name that went free in between, since re-adopting would delete the new bucket for nothing. In us-east-1 that read's date must still match too.
  • Who holds the name could not be read (no s3:ListAllMyBuckets, or a throttle that outlasted cdkd's retries): re-adopted with a warning when AWS reports the bucket, and refused when the existence read did not answer either.
  • A date that could not be read takes the rule for a read that cannot answer: re-adopted only while state still lists the bucket as awaiting its delete.
  • A journal written by an older cdkd carries no date, and this account's bucket is re-adopted as before.

Each refusal sends nothing, keeps the journal, and prints the --orphan command, which keeps the new bucket in its place.

Known limits, each refusing rather than re-adopting:

  • Outside us-east-1, a cdkd rollback re-run after an earlier run wrote the old bucket (it reverted a bucket policy, then failed on another operation) finds a moved date and refuses with the re-created-or-modified message.
  • A rollback that re-created a deleted old bucket and then stopped before it saved state finds the re-created bucket's new date on the next run. Once state is saved, a re-run sees the operation already reverted and skips it.

On a stack with an instance id, a resource the template does not name is re-created under the generated name its OLD record held (that record's name generation), not the next-generation name the replacement created, so the two copies do not collide on a generated name. The restored record keeps its own generation and records the generation the replacement reached as nameGenerationHigh, read from the journal's nameGeneration on the completed or failed operation, so the next replacement moves past both names. --revert-failed raises it the same way. A journal written by an older cdkd carries no generation and leaves the record as it was.

A replacement that deleted the old resource BEFORE creating the new one (--recreate-via-cc-api, --recreate-via-sdk-provider, the update-unsupported fallback, --replace's delete-first fallback, or a resource lost with a parent that was re-created under the same id) is reversed in that order too (on a stack with an instance id, the first three create first for a resource cdkd names, since its next-generation name is free): the new resource is deleted first, then the old one is re-created. So a port or name that only one of them can hold, such as an ELBv2 listener's port, does not collide. If that delete fails or is skipped, state keeps naming the new resource and the journal is kept. If the re-create then fails, the resource is absent and the message says so; re-deploy to fix it forward. A journal written by an older cdkd, and a new resource kept by UpdateReplacePolicy: Retain, use the create-first order. So does a resource whose old properties name another resource the same deploy replaced or deleted, including one whose replacement failed after deleting it (a listener's old target group, replaced by a create-only change): the rollback may not be able to bring that resource back under the id they name, so deleting the new copy first could lose it. The rollback says so in a warning and does not delete the new resource to free a name either, so if the re-create fails, the new resource is kept.

Such a replacement counts even when the new resource got the SAME physical id as the old one (a fixed name): the id cannot tell the two apart, but an in-place revert could not undo the create-only change that forced the replacement. Whether it has already been reversed is read from the state record: it is done once every property the deploy changed holds its old value. When the record cannot say (every property the deploy changed is a secret redacted the same way before and after, or the journal holds no properties for the deploy), the rollback refuses that resource rather than skip it or delete it again. A resource that AWS stores other resources inside (a Lambda function's permissions, an SNS topic's subscriptions, an IAM role's inline policies) is refused instead when the stack records such a resource depending on it (one the same deploy created, or one --orphan names, does not count), since deleting it again would take that resource too and nothing re-creates it. Nothing is deleted and the journal is kept; deploy the previous template with cdkd deploy --replace to restore both, or orphan the resource.

What counts as a replacement is what the provider reported. An update applied in place is reverted in place even when it changed the physical id, as an SQS QueuePolicy update does when its first queue changes and an SNS TopicPolicy update does when its topics change. A journal written by an older cdkd does not record the provider's answer, so there a changed physical id still reads as a replacement. A Type change, and an equal id that names two resources (a Glue table whose recorded database differs, a Lambda permission on another function, a security group ingress rule from another source, an API Gateway stage on another API), stay replacements whatever the provider answered.

On the create-first order, cdkd deletes the new resource first only when it can show that the new resource holds the name the re-create collided on:

  • An explicit name matches when the new resource's state record has the same name property, spelled exactly alike (case is ignored only where the service ignores it, such as IAM and RDS names), under the same parent (such as the event bus of a rule or the database of a Glue table), or when its physical id names it. For a Route 53 record, the DNS name and hosted zone must match.
  • A name cdkd generates (the template names none) matches only through the new resource's physical id, and only for a type whose generated name cdkd knows exactly. That is the name a Cloud Control re-create sent, or one of the SDK providers checked to send cdkd's rule unchanged.
  • IAM roles, users, groups, instance profiles and managed policies, and ELBv2 load balancers and target groups turn even an explicit name into a different name before sending it: a stack-name prefix that --prefix-user-supplied-names controls, and a character rewrite. For these, cdkd works out the name this re-create actually sent (under the setting it chose, above) and matches it only against the new resource's physical id. A matching recorded name is not enough.

When the re-create itself fails after its provider made the resource, the rollback deletes what it made before reporting the failure, unless the old resource's DeletionPolicy is Retain or Snapshot; a resource it keeps, or cannot delete, is named in a warning for you to delete.

A collision with anything else (a resource an earlier failed attempt left behind, or one created outside the stack) fails the operation instead: nothing is deleted, the message names the colliding name, and the journal is kept. The same refusal applies when cdkd cannot tell. That happens when the re-create asked for no name cdkd can derive, the name is redacted or empty, the new resource's state record and its last read-back name it differently, the type has no name property cdkd knows, or a Type change pairs types cdkd does not know to share names. Remove or rename whatever holds the name, then re-run cdkd rollback. If the holder is the new resource itself, delete it by hand and re-run: the rollback then proceeds. Or pass --orphan <logicalId> to leave that resource alone.

When the replacing deploy left the old resource alive — it declared UpdateReplacePolicy: Retain at the time — the old resource is simply re-adopted instead of being re-created, a true clean revert. cdkd reads that verdict from what the deploy actually DID, recorded on the rollback journal, rather than re-deriving it from the previous state record: the two answers differ on the deploy that adds or removes the attribute, and either direction of the disagreement is destructive (adding it made the rollback re-create a resource that was still running; removing it made the rollback point state at a resource that had just been deleted).

When the deploy tried to delete the old resource but did not confirm it gone — the delete failed (including the retry cdkd makes after the rest of the deploy, or a deploy that failed before that retry), the provider skipped it, a provider that replaces the resource inside its own update (an ACM certificate whose ValidationMethod changes) could not delete the old one, or a failed UpdateReplacePolicy: Snapshot snapshot blocked it — the journal records that the old resource may still exist, and whether AWS refused the delete outright (access denied, a dependency) or the snapshot stopped it before it was sent. Before re-creating it, the rollback reads AWS for it through the resource type's drift read (an ordinary reverse replacement makes no such read). Reported gone, it is re-created as usual. Still there after an outright refusal that came before the delete changed anything, or a delete that was never sent, it is re-adopted as a retained one is, with a ⚠ warning (exit 2): check it with cdkd drift. The same advice is recorded on the rollback's event, so cdkd events keeps it. Still there after any other failure — a skip, a resource AWS reports in use (except an ACM certificate, whose in-use refusal leaves it whole and is re-adopted), a wait that gave up on a delete AWS had accepted, a refusal that came after the provider's delete had already stripped the resource (an IAM role's detached policies, an EventBridge rule's removed targets, a CloudFront distribution it disabled), or any refusal of an IAM role or managed policy that its provider replaced inside its own update — the operation fails instead (exit 1, journal kept, nothing sent): that delete may still be running, or may have stripped part of the resource before AWS refused it, and re-adopting a resource about to disappear would leave neither, while re-adopting a stripped one would keep it in place of the working new copy; once AWS reports it gone, re-running cdkd rollback re-creates it. A refused delete is not running, so waiting does not help there: delete the old resource by hand, then re-run cdkd rollback. The operation also fails when cdkd cannot tell — the type has no read, or the read fails or does not answer in time — since re-creating could duplicate the old resource or collide with it; a failed read is retried by re-running cdkd rollback. In every refusal, the --orphan command the message prints keeps the new resource in its place instead, and you delete the old one by hand if it still exists. CloudFormation never reaches this state, since it deletes old resources only after the stack update succeeds.

UpdateReplacePolicy: Retain also protects the NEW resource from the rollback. If the resource the replacement created declares it, the rollback does not delete that copy: it is left running and dropped from state, and the run reports it with a ⚠ warning and exits 2. The survivor's physical id is also recorded durably in the deployment events (cdkd events), which carry it as a field next to the layer that manages it — a rollback runs during an already-failing deploy, so the terminal is the least likely place the id still is, and state deliberately no longer names the resource. Note what that means for the re-adopt case above: the attribute that made the deploy retain the old resource is the same one recorded on the new resource, so a rollback that re-adopts the old copy never deletes the new one either — both survive, and state names the old one. This matches CloudFormation, which reports DELETE_SKIPPED for the new copy and orphans it out of the stack (DeletionPolicy has no effect here — only UpdateReplacePolicy does; both were measured against real CloudFormation, since the AWS documentation does not state it). One combination cannot be honoured and is refused instead: when the old resource's re-create collides with a physical name the retained new resource still holds, cdkd will not delete the pinned resource to free the name, so the operation fails with the conflict named and the journal is kept — delete the new resource yourself, or drop UpdateReplacePolicy: Retain, then re-run cdkd rollback.

IAM inline policy names moved between resources

An IAM inline policy name moved between resources on one role, group or user in the failed deploy (two AWS::IAM::Policy resources swapping names, or a policy renamed away from a name the role's own Policies took) is kept by each revert that would remove it once another revert of the same rollback has put it back. When one of the two is an AWS::IAM::RolePolicy, UserPolicy or GroupPolicy, the rollback reverses the other resource first. Re-creating the standalone policy's old name would otherwise be refused while the other resource still held it.

When a revert or delete removes a name another resource's state record still holds on that principal (a policy created under a name another policy still held, say), the rollback puts back the document that record holds in cdkd state (not a copy of what AWS held) at the end, logs Rollback: put back the inline policy <logicalId> records on its role, and records a ROLLBACK_RESOURCE_SUCCEEDED event for that logical id.

Nothing is put back, and the rollback warns, when the records holding the name disagree on its document, when the document or a name is redacted, or when that record's own rollback has not completed (it failed, or the rollback was interrupted first), since its record may still be the failed deploy's. The principal then lacks that policy until the resource next changes or cdkd drift --revert runs. A rollback killed between such a removal and the put-back also leaves the policy off: a re-run does not repeat the removal.

Last updated: