How I created terraform module releases for AWS projects

David Essien Avatar
Screenshot of terraform module releases for AWS projects

Introduction (How I created terraform module releases for AWS projects)

Over the past two weeks, I have been working on some projects. One of them is the famous AWS 3-tier architecture design. There is an unspoken commandment that every cloud engineer must be familiar with this architecture. Since I will be working on several projects in the future, I decided to create my own AWS Terraform modules.

In this post, I am sharing some challenges I faced while creating my module releases and the strategies I used to overcome them.

The Problem

I will be working on many AWS projects. It didn’t make sense for me to write new modules anytime I wanted to work on a project. I also did not want to use existing modules, so I needed to create my module releases.

The solutions

Solution 1: Host my modules on the terraform registry

First, I wanted to host my modules on the Terraform registry. However, I found that each module requires a repository. This was not a good fit, as I didn’t want to create multiple repositories.

Solution 2: Create a single GitHub repository and host all my modules there

The next step I took was to host my modules on GitHub using releases. However, I found that each release packages the entire code in the repository, and there was no way to exclude the source code. So each time I imported a module, it copied the entire repository into that module’s directory. This was too much replication and a waste of space.

Solution 3: Host the modules in a GitHub repository, but separate the modules into their branches

Image for github actions creating releases

Finally, I decided to adopt the following approach:

  • Each module will have its own branch
  • Every branch will contain only a single module for the branch. The master branch contains the code for all the modules.
  • Each branch contains the generic GitHub action workflow file.
  • The Github action is triggered using tags that match a specific pattern. “*-v*. Example: “vpc-v1.0.0”
  • The beginning part of the tag matches a specific directory in the module. So VPC matches the VPC directory, and lb_listener-v1.0.2 will match the lb_listener directory. That is how the action knows which module to create a release from.

conclusion

Overall, it was an interesting project. There are probably still improvements to be made or better ways to handle this, but it solved my problem for the time.

Please let me know how you would have handled this or if you have faced a similar issue.

You can find the code for my modules here. I will be making changes that update the overall nature of the modules as I work on more projects.

By the way, you can find my article on the AWS projects I worked on here.

David Essien Avatar

Please share