Reputation: 575
I have a monolith cloudformation stack in every microservices creating the same kind of resource, I want to make it modular by breaking it into the nested stack and reusing them in each service. My understanding of nested stack is that you can use them as reusable units to create bundled resources. I am aware about the importing existing resource by setting the deletion policy to retain and importing in another stack. I am having trouble understanding how I can use the existing resources in the nested stack and also keeping it reusable. If I have import logic in the nested stack then it cannot be reused?
For example, let's say you create an EC2 instance along with cloudwatch alarms in each stack. I would like to modularize it by putting all the related resources into a nested stack called MyEC2Stack
. I can then use MyEC2Stack
in the parent stack to create as many resources as I want. Now my usecase is to use MyEc2Stack
to create the resources that existed before as well as a new set of resources. How can I achieve that?
Upvotes: 0
Views: 1390
Reputation: 238727
I would look into doing this in two stages:
Create standalone stacks with the imported resources. You already indicated that you are aware of this. But you also should be aware that not all resources can be imported.
In your parent stack import the stacks from step 1 as nested stacks. This could be possible, because you can import existing stack as a nested stack as described Nesting an Existing Stack
Importing existing resources into CFN, is not easy. It probably will require trail-and-see approach to get it right Thus, better to practice on some tests stacks and resources in stead you start changing production templates.
Upvotes: 1