By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How do I import existing resources into a nested stack whose parent is the root stack in CloudFormation?

2 minute read
0

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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

AWS OFFICIAL
AWS OFFICIALUpdated 3 months ago