Terraform for Azure and AWS

Automate the deployment of infrastructure across multiple providers.

Basic Configurations

Provisioning infrastructure through software to achieve consistent and predictable environment. The infrastructure is in code and saved in repository, it can be versioned and must be Declarative and Imperative (Terraform is declarative language).

Terraform is Idemponent because it checks if the defined declarative infrastructure & configuration on the target platform exists, if it’s not existed then it will be created.

Terraform has a push mechanism because it push the infrastructure to the target environment.

The automation infrastructure deployment in Terraform is demonstrated in the following figure.

Automation Infrastructure Deployment

Terraform characteristics

Automated deploymentConsistent environment
Repeatable ProcessReusable components
Documented architecture

Terraform Components

Terraform executableTerraform filesTerraform PluginsTerraform State
– Self contained.
– Written in GO.
– Basically available for all OS.
– It must be only put in Path Variable.
– Only a single executable.
– Configurations, which are going to deploy will be contained in one or more Terraform files.
– file extension is .tf
– in case of multiple Terraform files in the directory, the Terraform will stitch the files together.
– Each provider like Azure, AWS has its own plugin. – Terraform picks track of what’s going on.
– For updating the target environment with Terrafform, it will first take look at the state file and compare with new changes and apply the difference.

Development components

VariablesFor prevent to define secret keys, access keys, even the AWS Region and this kind of information in Terraform File.
ProviderThe could provider like Azure, AWS

Define variables

  • Variables can be defined in .tf file
  • In .tfvars file

In .tf file

variable "aws_access_key" = "AWS ACCESS KEY"
variable "aws_secret_key" = "AWS SECRET KEY"
variable "private_key_path" = "C:\\YOURKeys.pem"
variable "key_name" = "KEY NAME"
variable "region" {
   default =   "us-east-1"

In .tfvars file

aws_access_key = "AWS ACCESS KEY"

aws_secret_key = "AWS SECRET KEY"

key_name = "KEY NAME"

private_key_path = "C:\\YOURKeys.pem"

How to execute the Terraform file?

  • First put Terraform in the Path.
terraformthis command in visual studio code displays the list of all possible arguments.
terraform versionthe installed version of the terraform.
terraform initto initialize the provider according to the configuration file. if it doesn’t exist then will be downloaded.
terraform plan out m3.tfplanlooks at the configuration file and load the variables either form .tf or .tfvars files.
The plan can be saved in a file via out parameter.
This step verifies the configuration and variable files and

Integrate multiple providers

Using abstraction and reusable components


%d bloggers like this: