DEV Community

Cover image for Terraform-CodeGen0: A Terraform Code Generator
Randika Madhushan Perera
Randika Madhushan Perera

Posted on

Terraform-CodeGen0: A Terraform Code Generator

This is a submission for the GitHub Copilot Challenge : New Beginnings

What I Built

When we are deploying an application, especially in a cloud environment, we often need to manage the various infrastructure components, such as VPC, Servers, Databases, CDN, etc. Doing this manually is somewhat time-consuming and challenging. To overcome this, we can use terraform.

Terraform allows the development of the architecture that deploys the application in a cloud environment.

But writing the terraform is also somewhat time-consuming we need to create those codes manually, plus we need to know the terraform.

Using this Terraform-CodeGen0 you can easily generate the terraform codes. All you need to input the VPC name, Subnets, Route Tabels, IGW, and NAT details into this application. This Terraform-CodeGen0 provides your terraform code.

Demo

Repo

GitHub logo RandiakM / Terraform-CodeGen0

GitHub Copilot 1-Day Build Challenge: This is a Terraform Code generation application for VPC

VPC Terraform Generator

Introduction

The VPC Terraform Generator is a tool designed to generate Terraform code for AWS infrastructure components such as VPCs, Subnets, Route Tables, Internet Gateways (IGWs), and NAT Gateways. This project uses a microservices architecture and is hosted on Netlify, with MongoDB as the database.

How to Use

The VPC Terraform Generator allows users to generate Terraform code for various AWS components through a web interface. Users can input the necessary details for each component, and the application will generate the corresponding Terraform code.

Installation Steps

  1. Clone the repository:
git clone https://github.com/your-repo/vpc-terraform-generator.git
cd vpc-terraform-generator
  1. Install backend dependencies:
cd api
npm install
  1. Install frontend dependencies:
cd ../frontend
npm install
  1. Set up environment variables: Create a .env file in the api directory with the following content:
MONGODB_URI=your_mongodb_connection_string
  1. Start the backend server:
cd ../api
npm run dev
  1. Start the frontend server:
cd ../frontend
npm start

Netlify Hosting Steps

  1. Create a…

Copilot Experience

So for the initial start, I have used the below prompt to get an idea of this project.

Build a Terraform code generator for AWS infrastructure components (VPCs, Subnets, Route Tables, IGWs, NAT, etc.) using a microservices architecture. The application will be hosted on Netlify, and MongoDB will be used as the database.
Enter fullscreen mode Exit fullscreen mode

Starting project structure:

Starting project structure

Terraform Code Generation:

Ask to implement the utility functions to generate Terraform code-based user inputs for each resource type.

image 01

Edits:

image 02

Auto Complete:

For this code auto-completion, I provide the description as a comment and start to create the function, then Copilot starts suggesting the code sections that are related to my task.

auto complete

Documentation Creation:

Used the below prompt:

@workspace create a README with the below details:

1. Introduction 
2. How to use 
3. Installation Steps 
4. Netlify Hosting Steps 
5. User guide
Enter fullscreen mode Exit fullscreen mode

Conclusion

Through this challenge and the journey, Copilot was an AI pair programmer who helped me build this application. From the start and even from the ending of this project Copilot was really helped me.

Copilot reviewed the codes and provide alternative solutions to overcome some issues when developing this application.

With the help of Copilot I was able to create this amazing application within just 24 hours, Wihtout copilot help this may take long.

Top comments (0)