Compare CloudFormation Stacks
# Compare CloudFormation Stacks
CloudFormation stacks are a way to guarantee that your different environments stay the same. Putting your code into IaC, whether it be Terraform, Ansible, Serverless Framework, Serverless Stack, Pulumi, or CDK all compiles down to CloudFormation. This is the description of what your stack is on the AWS system.
There is a concept of drift in a stack, but that just tells you if a current stack has drifted. What if you want to compare your staging and production stacks on two different AWS accounts? Or if you are using LocalStack and deploying your infrastructure there before deploying to AWS, what if you want to compare them after you merge your code?
# CloudFormation Stack Compare
Up until now, this was a very difficult task. You might have to compare 1000's of lines of a template file, or maybe open up two different browsers with different AWS logins. But, now you can do this easily within Commandeer. Simply click the 'Stack Compare' button in the top right of the apps home dashboard, and you will be taken to the tool.
Once, in the tool, you can see that you are presented with some selection boxes to select account 1's stack, and account 2's stack.
# 🙌 A successful comparison
Below you can see that we are now going to compare our dev and staging environments. Technically, these are in the same AWS account, but running in different regions. But, in Commandeer, I have set them up as two separate accounts. They both have the same keys, but have different regions set. Our dev account is running in the Oregon data center, and our staging is running in the Ohio data center. Our production account however is in a complete separate AWS account. This is a pretty good way to handle it, as it makes you only have to manage two AWS accounts. Though, you can also just as easily set it up with a different account entirely for dev and staging. But, just please, don't have your production system intertwined with any other environments.
On the left hand side, you can see the accounts and stacks selected. Pressing the 'Compare' button then brings back results about the stacks. If the resources all match, then it will be considered successful. You can also see comparisons about the status of the stack, the template type, tags, and then a detailed breakdown by service.
If you need to examine the stacks further, you can go to the resources tabs, and lookup a resource. Below you can see the list of Lambda's for stack 1.
# 😿 A failed comparison
Sometimes, your stacks might be out of sync. This is when the tool can be really helpful. Now you can do analysis on your stacks in-depth. In the below example, we have a dev environment from a long time ago that we had deployed to our staging region. When we compare it to our real dev environment, you can see that there is a lot missing.
Using IaC and CloudFormation stacks is a crucial step in building out automated infrastructures. Now, you can rest easy, knowing that your stacks are in fact the same between not only different AWS environments, but also between your LocalStack and AWS environments.