简体   繁体   中英

CloudFormation: Deleting an entire nested stack

I have a CloudFormation stack which is made up of 3 nested stacks:

Resources:
  ParamsSetup:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: a-params.yaml          
  ResourcePrep:
     Type: AWS::CloudFormation::Stack
     Properties:
       TemplateURL: b-prep.yaml
  Services:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: c-service.yaml

I realized the ResourcePrep nested stack was unnecessary, so I moved the only important resource in that stack into the Services stack and removed the stack from my main template:

Resources:
  ParamsSetup:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: a-params.yaml     
  Services:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: c-service.yaml

Now I have a problem. CloudFormation updates fail because the resource in Services already belongs to ResourcePrep , but ResourcePrep shouldn't exist anymore.

I had expected that CloudFormation would be smart enough to delete the removed stack, but it isn't. The removed stack is still there, and I don't know how to get rid of it. Everything I've read says you should never delete a nested stack manually.

You have a couple options here, none of which are particularly elegant like what your hoping.

  1. Delete out the stack and leave the resource you want commented out (or deleted) for the cloudformation update/rebuild. After successfully updating with the stack removed, readd the resource you wanted/uncomment.
  2. If the resource needs to be persisted, add a deletion retain parameter onto the resource, run the update, then delete the entire stack. After update complete re-add/reassociate the existing resource with the stack of your choosing.
  3. Create an identical resource in the stack of your choosing with a different name and delete the odd stack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM