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. When I try to import the resource in the root stack, I get the following error: "This template does not include any resources to import."
Resolution
When the nested stack's parent stack is the root, it's a best practice to modify only the root stack.
Important: Always run drift detection on stacks after an import operation to verify that the imported resource isn't drifted.
To import resources into a nested stack whose parent is the root stack, complete the following steps:
- To detach the stack from the root stack without deleting it, update the root template with a Retain DeletionPolicy on the nested AWS::CloudFormation::Stack resource.
- Remove AWS::CloudFormation::Stack from the template in the root stack.
Note: After you update the root stack, the nested stack is still listed as Nested.
- To import the existing resource, perform an import operation on the detached nested stack.
Note: Because the stack is still considered Nested, you receive a warning that tells you update the root stack instead. Continue to update the nested stack. Don't modify any other resources during the import.
- To move the detached nested stack out of IMPORT_COMPLETE status, update the stack again with an easily removable change. For example, add outputs or tags.
- To add the nested stack back into its nested hierarchy, perform a resource import operation on the root stack.
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
AWS CloudFormation Workshop: Nested stacks