I have a nested stack in AWS CloudFormation whose parent stack is a root stack. I want to import an existing resource into the nested stack. But when I try to import the resource in the root stack, I get the error “This template does not include any resources to import.”
Short description
When the nested stack's parent stack is the root, it's a best practice to modify only the root stack.
Note: The following resolution is for importing a resource into a nested stack whose parent stack is the root stack.
Important: Always run drift detection on stacks after an import operation to verify that the imported resource isn't drifted.
Resolution
To import resources into a nested stack, follow these steps:
- Update the root template with a Retain DeletionPolicy on the nested AWS::CloudFormation::Stack resource to detach the stack from the root stack without deleting it.
- Update the root stack by removing AWS::CloudFormation::Stack from the template.
Note: After you update the root stack, the nested stack is still marked as Nested.
- Perform an import operation on the detached nested stack to import the existing resource.
Note: Because the stack is still considered Nested, a warning appears that recommends you to update the root stack instead. Ignore it and continue to update the nested stack. Don't modify any other resources during the import.
- Move the detached nested stack out of IMPORT_COMPLETE status by updating it again with an easily removable change, such as adding outputs or tags.
- Perform an import operation on the root stack to add the nested stack back into its nested hierarchy.
Note: Make sure that the root template includes a reference for the nested stack's updated template so that it contains the newly imported resource.
Related information
CloudFormation Workshop: Nested stacks lab