πŸš€ DevOps Certified Professional
πŸ“… Starting: 1st of Every Month 🀝 +91 8409492687 | 🀝 +1 (469) 756-6329 πŸ” Contact@DevOpsSchool.com

Terraform comparison and example code

DevOps

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Docker vs Ansible vs Terraform

  • Docker is particularly a container technology while Ansible are tools for configuration management.
  • Terraform, created by HashiCorp, provides a syntax to define infrastructure and services that can be hosted either on premises or in the cloud
  • ansible and terraform both are opensource.
  •  When it comes to Ansible, it’s very similar to Terraform in terms of what you can create with it. For example, you can also create the Azure Resource Group with Terraform.
  •  Terraform users define how to create, update, replace and delete resources with a programming language called HashiCorp configuration language (HCL). unlike Terraform, Ansible uses YAML
  • Ansible works with Python while Docker and Kubernetes work with Go
  •  Ansible and Terraform are complementary tools that are commonly used together.
  • Use Terraform to create resources and services. Then use Ansible to configure the resources Terraform created.

Terraform Sample code for creating a linux EC2 instance

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "3.49.0"
    }
    
  }
}


provider "aws" {
  region     = "us-west-2"
  access_key = "" #type access key
  secret_key = "" #type secret key
}


resource "aws_security_group" "allow_tls" {
  name        = "allow_tls"
  description = "Allow TLS inbound traffic"
  vpc_id      = aws_vpc.main.id


}


resource "aws_key_pair" "deployer" {
  key_name   = "deployer-key"
  public_key = "ssh-rsa email@example.com"
}