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

A simple overview of Terraform

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!

Comparison between Ansible, Docker and Terraform

AnsibleDockerTerraform
Ansible is a configuration management toolDocker is a container toolTerraform is an Orchestration tool
It provides support for mutable infrastructureIt provides support for immutable infrastructureIt provides support for immutable infrastructure
It follows a procedural languageIt follows a declarative languageIt follows a declarative language
It provides complete support for packaging and templatingIt provides support for packaging and templatingIt provides partial support for packaging and templating
It does not have lifecycle managementIt follows lifecycleIt depends on lifecycle and state management

Write a terraform script where you create a linux EC2 instance with Security group and key defined so you should be able to use key to login to EC2 instance

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
}

# Configure the AWS Provider
provider "aws"  {
  region     = "us-west-2"
  access_key = "()"
  secret_key = "()"
}
resource "aws_key_pair" "deployer" {
  key_name   = "deployer-key"
  public_key = "ssh-rsa 
}
resource "aws_security_group" "instance" {
  name = "terraform-example-instance"
  ingress {
    from_port   = 8080
    to_port     = 8080
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}
variable "security_group_id" {}

data "aws_security_group" "selected" {
  id = var.security_group_id
}