Building a Cloud-Agnostic Test Environment with Terraform

0
4707

Terraform is a tool to safely and predictably create, change and improve infrastructure. Terraform is cloud-agnostic and can use a single configuration to handle multiple cloud providers. It provides cost benefits, scalability, reliability, stability and tools for failure analysis, while enabling better collaboration and visibility.

Stable and reliable infrastructure is one of the most important factors for any test automation project as the ROI is achieved when automated suites are executed regularly in a controlled environment. Other factors are the ease of scaling the infrastructure to handle the increase in the volume of automated tests and how to reduce the total execution time.

The architecture proposed below describes one of the optimal solutions to address these challenges, leading to stability, reliability and cost benefits. This solution uses Infrastructure-as-a-Code to handle the dynamics of infrastructure creation, based on requirements at runtime on the selected configuration.

Why choose Terraform?
In the current business scenarios, it’s quite challenging to choose one cloud provider when there are multiple options, each with its own set of benefits. Also, from the deployment point of view, deploying multiple clouds increases the fault-tolerance of the system.

Terraform is cloud-agnostic, and allows a single configuration to be used to manage multiple providers and to even handle cross-cloud dependencies. In the present DevOps culture, automated tests are an integral part of deployment pipelines. Therefore Terraform is an obvious choice to simplify management and orchestration, helping operators build large scale multi-cloud infrastructures.

Figure 1: Jenkins build pipeline

The benefits
Listed below are some of the key benefits of using cloud infrastructure with Terraform to run automated test suites:

  1. A cloud-agnostic environment with Infrastructure-as-a-Code
  2. Cost benefits
  3. Stability
  4. Scalability
  5. Reliability
  6. Good quality execution videos for failure analysis
  7. Better collaboration and visibility

The components of the proposed architecture design
Figure 2 shows the proposed architecture design. The components of this design are described below.

CI tool (Jenkins): Jenkins is an open source, self-reliant automation server initially developed for the implementation of continuous integration (CI), a development practice. From Jenkins 2 onwards, this server has seen exceptional growth, providing hundreds of plugins to support building, deployment and automation in any project. It also has a Terraform plugin for Jenkins, which allows for the creation of test infrastructure before running the build, and its deletion after the build is completed.

Infrastructure-as-a-Code approach: Terraform is a cloud-agnostic tool for building, changing and versioning infrastructure safely and efficiently. It can manage existing and popular cloud service providers like AWS, Azure and GCP, as well as custom in-house solutions. It helps in modelling the complete cloud Infrastructure-as-a-Code, i.e., the infrastructure is described using a high-level configuration syntax. This allows a blueprint of the infrastructure to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and reused. This way the time required to manage the resources is reduced. There is no need to individually create and configure the cloud resources and figure out the relevant interdependencies. Terraform handles all of that.
This Terraform template will launch an EC2 instance running a custom Amazon Machine Image (AMI) in a public subnet within a virtual private cloud (VPC) with an attached Internet gateway. The route tables associated with the public subnet can be configured to be accessed only from the organisation’s public IP as a security precaution. The role required for the instance to upload data to the S3 bucket can also be defined within the template resources. The custom Amazon AMI has all the required software installed and configured to run the test suite and initiate the test execution. This saves setup time. Once the execution is complete the reports can be uploaded to an S3 bucket by placing the request via AWS CLI (command line interface).

Version control: Git is an open source distributed version control system. The latest code for the Katalon test suites is maintained in Git; this can be pulled once the EC2 instance is up and registered as a Jenkins node, after which you can initiate the suite execution on the latest code.

Automation tool — Katalon Studio: In the setup, we used Katalon Studio to automate the test suites. Katalon Studio is a free automation testing solution. It is built on top of the open source automation frameworks like Selenium and Appium, with a specialised IDE interface for the API, the Web and mobile testing. The test automation framework provided within Katalon Studio has been developed with a keyword-driven approach as the primary test authoring method, with data-driven functionality for test execution.

Figure 2: Proposed architecture design

Cloud storage service – AWS S3: After executing the automated test, the reports can be easily stored in any cloud storage service, depending on the service provider selected, e.g., Amazon S3, Microsoft Azure Blob Storage, or Google cloud storage.

In this use case, we have selected AWS; hence we have used S3 for storing the reports. Amazon S3 is an object storage service for storing large unstructured data with virtually unlimited scalability. With a low cost, easy data access and security of the buckets, S3 is a good choice to store date-based reports of the execution.

Once the complete suite is executed, the reports/recordings can be maintained under a date-based folder structure in an S3 bucket for any future references. Life cycle policies for the S3 bucket can be used to move objects from S3 buckets to cold/archival object storage, i.e., Amazon Glacier, to further reduce the cost.

Terraform is cloud-agnostic architecture for automated test execution. It is stable, reliable, scalable and has many cost benefits. Since the test environment is built and terminated dynamically at runtime, users only pay for what they use. Also, one is not tied to one cloud service provider because of the flexibility to evaluate and choose. Migration, too, is hassle-free. The ultimate goal is to design a solution that gives the maximum ROI on any test automation project and helps deliver a high quality product with agility.

LEAVE A REPLY

Please enter your comment!
Please enter your name here