DEV Community

Cover image for Terraform AWS EC2 Deployment
Clinton Mbilitem
Clinton Mbilitem

Posted on • Edited on

Terraform AWS EC2 Deployment

Think of Terraform like your cloud-building robot, and now we want it to build a computer (EC2) in AWS.

The terraform block is the very first step where we tell the robot what it needs before it starts working

Provider Block asks, "Who are we working with?" This tells Terraform which cloud we are using.

The variable enable block turns things ON or OFF. This is like a switch.

Variable Region Block asks, "Where to build?" This tells Terraform where in the world to build the variable.

creating the config file, adding the aws provider

config

Now weโ€™re telling Terraform to build a Linux virtual machine (VM), like creating your own computer in the cloud

The resource says, โ€œHey robot, build something!" linux_virtual_machine builds a Linux computer; vm is the name of our machine.
source_image_resource, which is the brain of the computer. This part chooses the Linux system to install, the publisher who made it (like Canonical for Ubuntu), the offer for the type of system (Ubuntu Server), and the SKU for the version (like 18.04).

the resource block making use of Linux

provider

A security group block is like a safety gate that controls who can enter and connect to your cloud computer.
while ingress refers to traffic coming into your cloud computer and egress for traffic going out of your cloud computer.

write the security block to protect our instance/or

security aws

This step tells Terraform to create a cloud computer, attach a security group to keep it safe, and choose the type and size of the machine (like small or big) so it fits your needs.

creating the instance and adding the security ID.
telling terraform type of instance and size

instance

Our deployed instance

terminal

aws terminal

deployed instance

security group

destroy instance if no longer required

destroy

Top comments (0)