CloudFormation Nested Stacks With Git Sync & a GitLab Pipeline Complete Overview

This post follows on from the previous post, CloudFormation Nested Stacks With Git Sync & a GitLab Pipeline. This post will detail all the steps now they have been fully worked out and tested using GitLab and CloudFormation.

GitLab Pipeline Overview

Changes are made to the files
Changes are pushed to repo
Pipeline for merge request creation is automatically run
Merge request is manually approved for anything that does not begin with aws-sync-
A new pipeline for S3 sync of all files in repo is uploaded to S3 bucket named ntwklab-cloudformation2

This pipeline works for branches that are new or have been reused. Both will get a new merge request that needs to be approved.
Once the merge request has been approved, all the files in the repo are then uploaded to the S3 bucket ntwklab-cloudformation2.

Branches that begin with aws-sync- are created by CloudFormation for a new parameter file. If used, they are automatically merged with the main branch.

CloudFormation Overview

CloudFormation is using Git Sync, so all my files are stored in GitLab can be accessed by CloudFormation. In the case of a nested stack (as in this example), CloudFormation needs to access the child files from S3. This is the reason the repo is sync’d with S3.

CloudFormation creates the stack from git-deployment template
Deployment template references S3 where the templates are all stored
CloudFormation creates the stack

git-deployment.yaml

deployment.yaml

Creating a Nested Stack

This nested stack will use the GitLab pipeline as a full demonstration. If the files do not require any changes, and all that’s needed is to deploy the CloudFormation template, then that process would start with CloudFormation at step 6.

Step 1: Make a new branch

Step2: Make a change, commit and push the new branch up to the repo

Step 3: Check GitLab pipeline for merge request creation

Step 4: Review and approve merge request

Step 5: Review second GitLab pipeline for s3 sync

Step 6: Create stack in CloudFormation

That’s the complete process for using a GitLab pipeline and a CloudFormation template. Now the foundations have been laid, more work can be carried out with CloudFormation.

Leave a Comment

Your email address will not be published. Required fields are marked *