Terraform:

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

A comparison between Ansible Vs Docker Vs Terraform:

Docker is platform as a service whereas terraform and ansible are infrastructure as a service

Ansible is suitable for small, temporary, and fast deployments.

Terraform is better when it comes to managing cloud services below the server.

 Terraform is an open source, IaC platform. Whereas, Ansible is an open source configuration management tool. Developers can use Ansible and Terraform at the same time

Terraform uses HCL,Ansible uses Yaml,Docker uses namespaces ,images

Terraform uses to create resources and services .ansible to configure resourses

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
}