Terraform
Terraform is an infrastructure as a code that allows you to build, change & version infrastructure safely and efficiently.
Terraform Architecture
Main Commands in Terraform
Example of Terraform Configuration file
terraform
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
}
}
required_version = ">= 1.2.0"
}
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "app_server" {
ami = "ami-08d70e59c07c61a3a"
instance_type = "t2.micro"
tags = {
Name = "ExampleAppServerInstance"
}
}
{
Components of Terraform:
provider "aws"
region = "us-west-2"
access_key = "ACCESS_KEY"
secret_key = "SECRET_KEY"
}
{
Recommended by LinkedIn
provider "aws"
region = "us-west-2"
access_key = "ACCESS_KEY"
secret_key = "SECRET_KEY"
}
{
variable "instance_type" { default = "t2.micro" }
terraform { backend "s3" { bucket = "my-bucket" key = "terraform.tfstate" region = "us-east-1" } }
provisioner "remote-exec" { inline = ["sudo apt-get update", "sudo apt-get install -y nginx"] }
terraform { backend "consul" { address = "127.0.0.1:8500" } }
module "web" { source = "git::https://example.com/vpc.git" }
ata "aws_ami" "ubuntu" { most_recent = true owners = ["099720109477"] filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } }
Installation of Terraform in different Operating Systems:
🔗 https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli
For more info check out the below link
🔗 https://developer.hashicorp.com/terraform/docs