DEV Community

Pedram Hamidehkhan
Pedram Hamidehkhan

Posted on

Collaborative Infrastructure as Code using Terraform Cloud - Publishing Modules Private Registries

I'd like to start this post with a great quote from The DevOps Handbook which says: "When new learnings are discovered locally, there must also be some mechanism
to enable the rest of the organization to use and benefit from that knowledge." Infrastructure as Code is not a new concept and it is already used in many projects. However, collaborating on IaC has not always been easy for developers. Many organization are struggling with sharing the knowledge and expertise of their developers with other teams. This is a difficult problem that private registries Terraform Cloud/Enterprise is aiming to solve.

In a previous post, we had a go on solving the cold starts for Lambda Functions. Now we want to help the next person in our team preventing them from reinvent the wheel again.

This tutorial assumes you already have a Terraform Cloud account, if you haven't opened up an account yet, please use the links bellow to open one.

https://cloud.hashicorp.com/products/terraform

So how do you go about creating a private registry?

We begin by creating the module that you'd like to publish. I am using this module. I personally prefer adding variables with smart defaults as much as I can. Of course, the consumer of this module is also going to need some of the outputs of this module to be used in their application, e.g. the ARN of the lambda function. so don't forget to add them in the output section.

After creating the module, we are ready to push it into Github. Please also be aware of the naming convention for your module, which follow the "terraform--" pattern.
Before we jump to terraform cloud, we need to build a release for our project in Github, follow this this to build the release, OR, click on releases on the right pane of your repository, click on "draft a new release" choose a tag for the release (should follow x.y.z versioning pattern), give it a title and click on publish, and we are good to go.

Now jump to Terraform Cloud, and click on registry, then click on modules, publish, modules. If you don't see your VCS provider, you need to connect it with Terraform cloud before proceeding, please visit this link to do so.

Choose your repository, and click on Publish module!

Congratulations on publishing your first Terraform Module.

In the next post, I will show you how to consume this module and integrate it into a bigger application.

The link to the Video: https://youtu.be/S5JTD3hWOug

Github repo: https://github.com/pedramha/terraform-aws-lambda

Top comments (0)