Streamlined Web Application Management with Terraform

A developer working at a desk with a laptop and computer screen.

As an Insurtech startup, we are not just a company with great ideas, but we also have top-notch technology and talented technical members on our team. With this article, we are excited to give you a behind-the-scenes look.

We will take a look into the cloud infrastructure and management of web applications. The purpose is to give the reader an idea about what main components and steps are required for publishing a modern web application.

Furthermore, Terraform will be introduced - which is a powerful tool for managing cloud resources - that makes such web application deployment more convenient and maintainable.

Please note, that this document doesn’t cover every step in a detailed fashion, it is only supposed to provide you a basic picture of the topic.

Publishing an Application on the Web

Starting the beginning, if you want your website(s) available on the internet, first of all, you have to purchase the domain (i.e. from GoDaddy, Domain.com, or Google Domains). When you own a given domain, for example, mycompany.com then you can route the internet traffic of this domain and any subdomain - like app.mycompany.com - wherever your applications are hosted.

After having a domain, you can decide how to publish your site. You can use web-based builder tools like Webflow, Wix, or SquareSpace. These platforms are suitable for landing pages and business sites. This option is significantly simple since mostly no coding skills are required and you don’t need to deal with complex cloud configuration. However, if a more sophisticated site or application has to be built, you’re supposed to publish your web app in a custom way using frameworks like Angular or React and set up a cloud infrastructure that serves the app properly.

AWS Infrastructure

Amazon Web Services (AWS) is a cloud provider, offering hundreds of different services. In this section, we’ll cover the basic services used for web application hosting.

Simple Storage System (S3)

AWS S3 is an easy-to-use and highly scalable storage service. At S3 you can create a so-called bucket (essentially acts like a folder) where you can upload the web application-related HTML, CSS, Javascript files, and any web assets used by the site. When the application development is ready, you need to upload the content to the created bucket.

CloudFront

AWS CloudFront is a Content Delivery Network (CDN) service. The point of such CDN service is that the content is copied to multiple locations all over the globe so that the given resource is quickly available from anywhere in the world. This intermediate resource makes it possible for the fast serving of your application put onto the S3  service.

Route 53

AWS Route53 is a service for DNS record management. DNS records belong to one domain, and they are the means to route your domain's traffic. You can edit DNS records at the interface of the domain provider but there’s a way to redirect every traffic to AWS and handle the DNS setting there. It is quite useful because that way all the web application-related configuration will be in one place on AWS. At Route53 you need to create a CNAME record, that specifies that for instance, app.mycompany.com should point to the previously created CloudFront distribution.

Automation with Terraform

The mentioned AWS services have to be configured precisely to work together. Each instance has several different configurations, which can be set in the first place on the AWS console. However, clicking together such infrastructure is a tedious and error-prone process. It can be especially ineffective when the business requires different web application deployments frequently.

To overcome this limitation of manual deployment, a tool called Terraform can be used. Terraform allows you to define your cloud infrastructure as a code. The advantage of using such an approach is that you can deploy the same infrastructure with different parameters within minutes so you don’t even visit the AWS console and do a single click.

Example Code Snippet

Let's see a short example of what Terraform code looks like. Most of the entities created by Terraform are cloud resources, therefore most of the definitions start with the keyword ‘resource’. After that comes the type of the resource then the name, and finally the parameters.

The first three lines of the code for example create a new bucket in S3 with the name ‘app.mycompany.com’, while the resource aws_s3_bucket_policy makes this bucket’s content publicly available. Important to note that in the 6th line, the id of the bucket resource is referenced, which shows how the resource connections can be expressed through the Terraform language. You can find extensive documentation of the available resources at https://developer.hashicorp.com/terraform website.

Finally, when your infrastructure code is ready, you can do the deployment with one single terminal command.

Before deployment, each of the resources to be created is listed in the terminal, so you can double-check whether your code indeed represents the infrastructure you wanted.

Terraform can look intimidating at first glance and the beginning might be difficult, however after learning and deploying the first setup with it, you probably won’t be able to imagine life without it 😉