This article is an introduction to automated database deployments with Terraform.
Terraform is now one of the most interesting tools available to work with Infrastructure as Code (IaC), presenting a simple and readable structure. Thousands of companies adopted it, particularly because it supports the major cloud suppliers, such as Azure, AWS, GCP, and others.
A Few Words on IaC
Automated deployments are key to achieving continuous integration and continuous delivery (CI/CD). IaC tools are the means to automate the tasks, so we can consistently and predictably deploy infrastructure to different environments.
There are dozens of IaC tools available. Terraform gained a respectable share of this market because it is:
Declarative: you don't need to bother with so much detail
Idempotent: it identifies changes already applied to the environment and keeps the envinronment's consistency
Vendor agnostic: it can be used with different cloud providers
Open source: the basic version is free, although Hashicorp (the creator of this software) also offers an enterprise version.
Getting Started
The basic components to use are:
the Terraform executable
configuration files written in HCL (Hashicorp Configuration Language) or JSON
provider(s) to specific environments (in the examples below, we will use the Azure provider, AzureRM)
state data, which guarantees the consistency of any deployment.
If you intend to try the following examples by yourself, please remember to install the most recent versions of Terraform, AzureRM provider, and Azure CLI.
Generally your project will involve several HCL files, like:
[main].tf : the "root" file for any project, that may contain providers and resources to be deployed.
variables.tf: where you attribute values to your variables
locals.tf: allows to create expressions based on variables (example: creating tags)
output.tf: allows to collect values generated during deployment, such as IDs.
custom files you use to better organize your project
As a first example, I present a Terraform version of the classic "Hello, World". It involves a single HCL file with fixed parameters (no variables) to create only one resource in Azure (a resource group). I refer to this code as "Example 1".
Creating an HCL File
Example 1 declares only 03 topics:
provider, in this case we use AzureRM. This declaration is mandatory.
required provider, where one specifies which provider version to use. Although it is an optional declaration, it is important to use it through the lifecycle of your environments, since provider syntax might vary depending on its version.
resources: in this example, only one resource is deployed, a Azure resource group.
Image 01 shows the code within HCL file "main.tf".
In this article, I will work you through the process of creating elastic jobs in Azure using PowerShell. The elastic jobs are similar to regular agents jobs in SQL Server although they add extra functionality like for example dedicated target groups that can be used in the job step level. Currently, the elastic jobs are […]
Introduction Developing predefined reports in addition to all the ad-hoc queries have been a part of my daily activities. Often I find my stakeholders asking me to prepare reports in which they want to know something that has never happened. It might sound strange, but yeah, that's what their point of concern is all about. […]