A simple overview of 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!
Comparison between Ansible, Docker and Terraform
Ansible | Docker | Terraform |
Ansible is a configuration management tool | Docker is a container tool | Terraform is an Orchestration tool |
It provides support for mutable infrastructure | It provides support for immutable infrastructure | It provides support for immutable infrastructure |
It follows a procedural language | It follows a declarative language | It follows a declarative language |
It provides complete support for packaging and templating | It provides support for packaging and templating | It provides partial support for packaging and templating |
It does not have lifecycle management | It follows lifecycle | It 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
}