Deployments using a CloudFormation StackSet in an Organization
Published: 2022-03-08 09:36:00

This is a short article to share my experience with CloudFormation StackSets across the Organization. This is not a duplication of any documentation. Instead it shares my notes on ease of use, intuitiveness, gotchas and any other benefit that I perceive. These are just my opinions and has no bearing on the underlying product or AWS in general.

### The StackSet Journey

#### 1. The Setup:
I am going to use a CloudFormation script that creates a 3 tier network from scratch. Feel free to reuse my script (that can found in the resources section below) or use anything that works for you. My sample is not very complicated but takes a few minutes to deploy, when it’s directly applied in an account using a stack.

#### 2. Enable trusted access
Only administrators can enable this setting. With this setting you can deploy across the organization. There’s a concept of delegated administrator accounts but I didn’t try that out. Instead I logged into the management account (the first account that enabled aws organizations) with a user having admin access.

![Enable Trusted Access](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zi6ofgf8lmv6062ss60o.jpeg)

If you want to try out registering delegated admin accounts try the [guide here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-delegated-admin.html).

#### 3. Creating the StackSet
Here, I plan to cover just the salient points of creating the stackset. I did the minimal to move forward. So this article doesn’t go through explanations of each field and what it accepts. Feel free to check the [guide](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-getting-started-create.html) for more details if that interests you.

The create stackset screens start similar to creating a stack where you say the template is ready and you can provide a template from an s3 bucket or from your computer. I chose to upload my own file. 

![Step 1: Choosing a template](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/swh1uqj9ni1og45r1ilo.png)

![Step2: Specify StackSet details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bw4cn7opddrcq87ypo2.png)

I left all options as default except for the Execution configuration I set as **active**, under deployment options I chose all accounts in organization and finally the region was scoped to us-east-1. I left the concurrency options as is and let the stackset rip.

![Step 3: Configure StackSet details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ad7ilpg7x8wp78y3t9ye.png)

![Step 4 : Set Deployment Options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqga374s8wwi9r6uiiwx.png)


![Step 4: Concurrency Details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nvvja9ln2paiuep3dsze.png)

##### Observations:
* Under the operations tab it said running against the stackset.

![running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t6iq4cdfly20cp6wyovh.png)

* Under stack instances tab, each account that executed got a stack id assigned to it.

* All accounts started with an OUTDATED status

![All Outdated](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sqejxgbzmf86gpris377.png)
_here you see all accounts are outdated_

![1st account processing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxwx619ly7jvmyg6w1a1.png)
_first account initiated and got an id_

![2nd account processing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ow2us1cg1zjtxjv3vsa0.png)
_first account completed and changed status to CURRENT and second account started processing_

![all accounts done](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/glmiwi6rl80zkbyk15ce.png)

![succeeded](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hgl4ay1i2bluo47uwvnx.png)
_finally all accounts updated_

* It was hard to say what was  what was happening within each account as there was no feedback or details about the processing. On one of my previous attempts the whole stackset FAILED status and I had to switch to each account to delete the stacks to revert back and restart.
* When a stack was successful, the status changed to CURRENT. The next account now received an id as the execution is sequential by default.
* When all stacks completed, the stackset went into SUCCEEDED status.

#### 4. Deleting the StackSet
While deleting the stackset I had to fill the same choices as in creation. I noticed I couldn’t delete the stackset until I delete all stacks within it and I had to know the organization ids to delete the stacks. This time I chose parallel execution and all of them got an id. Once done I could successfully delete the set.

![failed to delete stackset](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0ijjd4zzuucr3yfp4d6.png)
_attempt to delete stackset when stacks were not removed_

![Initiating Delete Stacks](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3zsbtim2lord533gqb3.png)

![parallel execution](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gjic0tzls932nxq6ava.png)

![delete queued](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iio21lnleg0zf35020m3.png)

![delete running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ykzx3j7dkrbncrcz727o.png)
_initiating delete stacks within the organization_

![stack instances outdated](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4yk5wql1bt779nclxexu.png)

![account deleted](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ehc6wowk6j5ods88xj7o.png)
_notice the account was deleted_

![delete stack completed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnmlwk0kp77axeow0bpt.png)


![delete stack](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fv5py3h1weo178jstj1j.png)


![ready to delete stackset](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ut37rkp0zmysxvhq05c6.png)
_finally account is ready to delete stackset_

#### My Suggestions 
* If this is your first time using a stackset make sure your stack executes in one account successfully 
* Don’t make assumptions while executing stacksets. For example security group ids change across the accounts. So don’t hard code them.
* Add default values for things that are static. For example private cidr blocks to be assigned to a vpc or subnet 

#### Final Thoughts 
The stackset is not the most intuitive feature. With a little care you can be successful at it. There are alternatives within AWS to execute it against the organization [using systems manager](https://aws.amazon.com/blogs/mt/manage-aws-cloudformation-templates-and-stacks-aws-systems-manager/) or programmatically. You may also use Terraform to make your deployments. Either way by trying it you practice some best practice of cross account deployments.


#### Resources 
* 3 tier vpc network [cloud formation script](https://github.com/LionelPJ/MyAwsToolBox/blob/main/networking/3tierVpc.yml)

**[about Lionel Pulickal]**

_Lionel is a Cloud Engineer who has worked in the IT industry since 1997. He has all the 3 AWS associate level exams, the solution architect professional and networking specialty exams under his belt. He loves hands-on and always loves to share the knowledge he has gained over the years._