Boxy
Boxy

Reputation: 345

One CloudFormation stack or divide into multiple stacks using Export & ImportValue?

I have created a stack for our Multi-AZ RDS setup within same region. The stack creates VPC, Subnets, IGW, Route Tables, SecGroups, EC2, RDS EC2 etc and currently about 200+ lines.

I was not aware of Export Parameter and Fn::ImportValue where we can do the cross-stack reference. I have also just learned that a stack can't be deleted if it has Exported some of its parameters and other stack are referencing it.

My question to CloudFormation experts is it more practical/professional to keep one Stack (so deletion of all the resources is easy) OR should we split our IAC into multiple inter-related stacks?

Appreciate your input as I have prepared this template for a Demo that I am giving to my team, either I should leave it as it is or split it up.

Created one Stack that setup the infrastructure and also create all the resources in one-go.

Upvotes: 4

Views: 1056

Answers (2)

Boxy
Boxy

Reputation: 345

Thanks, I have splitted into two stacks, first is the core-infrastructure that only creates network Skelton i.e VPC, IGW, Subnets, Routes. This stack emits output parameters with each of these resources's export names.

The second stack rds-resources just reference above and create EC2, RDS, SG.

Thanks again for the useful information.

Upvotes: 1

Kristijan Iliev
Kristijan Iliev

Reputation: 4987

There are probably many correct answers, therefore I would try to help you narrow down the one that would be best for you.

  1. You can delete such stack, but it will warn you because of having stacks that depend on resources inside the stack that is about to be deleted (but I don't see a reason doing that)
  2. The max num of resources per stack is 200, the number may have changed in the meantime - we had this issue having to many resources, therefore we split in nested stacks architecture
  3. Deleting resources manually will drift the stacks - that's not a good thing
  4. Deleting resource should be done by removing it from the template(s) and updating the stacks correspondingly - this implies that having a one stack only is easier to maintain, but then again it depends on your use case.

I hope this helped you come up to a decision. If not, share more information.

Upvotes: 1

Related Questions