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

Huawei Map Kit Integration

Abstraction in Programming

Introducing Brownie

Think as… a Dev

Security and optimization in Resource Management

Modern Approach to Smart Contracts with Hyperledger Fabric 2.0

Data Modeling

Top AIOps Trends Impacting DevOps in 2020 and Beyond

Top AIOps Trends Impacting DevOps in 2020 and Beyond

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

ACL on S3 bucket objects with Terraform

How to Deploy a Debian Linux EC2 Instance in AWS using Terraform

Automate F5 BIG-IP On-Prem using Terraform Cloud with GitHub

Terraform Password Protection of AWS, GCP, and Azure resources.