Automating AWS-EC2 via Terraform

AWS-EC2 Creation using Terraform

  1. Setup AWS Command Line Inerface (CLI)
$ terraform --version
terraform version
# Create a new instance of the latest Ubuntu 20.04 on an
# t2.micro node with an AWS Tag naming it "HelloWorld"
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
# Configure the AWS Provider
provider "aws" {
region = "us-east-1"
}
# Setting up the EC2 instace named as testingweb
resource "aws_instance" "testingweb" {
ami = "ami-0dba2cb6798deb6d8"
instance_type = "t2.micro"
tags = {
Name = "HelloWorld"
}
}
  • provider “aws”, this is to set the service provider, you are using. So here we are setting up EC2, so we have write aws here.
  • resource “aws_instance” “testingweb” resource is to tell what service of AWS we are using, here we are using EC2 which is an AWS Instance so aws_instance would be hardcoded and testingweb is the name we have assign to it.
terraform init
terraform init
terraform validate
terraform validate
terraform plan
terraform plan
terraform apply
terraform apply

Further Options to Explore

AWS EC2 terraform options

In a Nutshell

--

--

--

Python, DevOps, Cryptography, Infra-Structure Automation. https://syedsaadahmed.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Ultimate multichain land sale on traditional & blockchain venues

Auto-complete for AWS cli in zsh

Validate Bad Email Address in PHP, Laravel

Validate BAD Emails in PHP, Laravel

Integration of Huawei Analytics Kit in HarmonyOS

Three Ways to Get Things Done and Get On With Your Day

Consistency Problems in A Microservice Architecture (Part II)

Test-Driven Development — Part 2

Useful Postgresql Commands/Queries Part-1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Syed Saad Ahmed

Syed Saad Ahmed

Python, DevOps, Cryptography, Infra-Structure Automation. https://syedsaadahmed.com/

More from Medium

How-to setup a HA/DR database in AWS? [2 — Definitions]

Ansible and using a Bastion server to AWS EC2 instances

Setting Up Self Managed Kubernetes On AWS EC2