Terraform

ยท

3 min read

Infrastructure as code provides the means to deploy or run applications, with the ultimate goal of utilizing laptops and computers. When we combine RAM, CPU, hard disks, switches, routers, and GPUs together and place them in one area, that area is called a data center. A data center is an infrastructure.

So, when we want to deploy an app, we need infrastructure, which can be obtained from virtualization, OpenStack (private cloud), or public clouds (such as AWS, GCP, Azure). There are other methods of infrastructure provisioning, such as containerization with Docker, Kubernetes, and OpenShift.

Three different ways that help in running an app are:

  1. Virtualization

  2. Containerization

  3. Cloud

The choice of platform depends largely on your management and team preferences. Your company may already be using AWS, Azure, Kubernetes, or Docker.

One criterion for choosing may be the cost. In many cases, AWS charges more than Azure. For instance, launching a Windows server in AWS can cost up to 5 times more than in Azure

But cost is not the only criterion; for instance, Azure may not offer as much reliability as desired, as it experiences downtime on occasion. The criteria for selecting a platform may vary. Nowadays, cloud customers are more intelligent and using both clouds simultaneously. This is the Multi Cloud .

In some scenarios, there may be a need to utilize OpenStack at times and AWS at other times. For instance, there could be data that cannot be stored in a public cloud due to privacy concerns. In such cases, the data might be stored in an OpenStack private cloud.

In today's world, multi-cloud and hybrid cloud environments are prevalent. To truly understand the capabilities of Terraform, one needs to work within these multi-cloud or hybrid cloud setups.

If you use any platform or infrastructure provider like AWS, you'll find three methods of interaction available: web UI, CLI, and API. All three of these methods are considered somewhat monotonous, not particularly intelligent, and can be challenging in terms of management. The CLI approach of AWS resembles a scripted method of specifying what to do and how to do it, which is considered an older approach.

One way to build infrastructure is by putting all the commands in one file, typically a script or program file. Automation, on the other hand, utilizes code with a declarative approach, where you specify what needs to be done rather than how it should be done. There is a service called CloudFormation in AWS, which employs a declarative approach. In Azure, there is Azure Resource Manager (ARM), and in GCP, there is Deployment Manager, both of which also use a declarative approach. In OpenStack, there is a service called Heat, which similarly utilizes a declarative approach.

If your company only utilizes AWS or Azure, and you aim to implement automation while sticking with their respective automation services like CloudFormation or Azure Resource Manager, in Terraform, you write the infrastructure code in a program file. This program file is referred to as a manifest in Terraform.

Terraform code is more look like a JSON which is called as HCL ( HashiCorp configure language)

Terraform internally uses a dedicated provider for each platform. There is an individual provider for AWS, Azure, Kubernetes, and so on.

Terraform providers: https://registry.terraform.io/browse/providers

how can we tell that which provider we use just click on the provider you want to use their it given a source code

click on the use provider. Their you got the code through which you will tell the terraform using code.

or to see the keyword https://developer.hashicorp.com/terraform/language/providers/configuration

terraform { required_providers { mycloud = { source = "mycorp/mycloud" version = "~> 1.0" configuration_aliases = [ mycloud.alternate ] } } }

ย