Skip to content

Adesdorcas/Deploying-AWS-EC2-with-Terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Deploying an AWS EC2 Instance with Terraform

Description

Terraform is an open-source infrastructure as code (IaC) tool that enables you to safely and predictably create, change, and improve infrastructure. In this project, we will be creating a VM in AWS by following the Terraform workflow, Write > Plan > Apply. After we have successfully deployed the VM, we will then clean up our infrastructure and destroy it :) Let's get started.

Environments Used

  • Terraform
  • Local Command Prompt
  • AWS Management Console

Project walk-through:

First we need to SSH into our machine.



We now need to create a directory to house our Terraform code, we'll call the directory "terraform_code".



Then we create a new file for the code called main.tf by using the command 'vim main.tf'. And then add the code for creating an EC2 instance in AWS to the main.tf file.



Now we need to initialize the Terraform configuration with the 'terraform init' command. Which initializes our working directory containing the configuration files (main.tf) and installs plugins for required providers.



After initializing, we need to run the 'terraform plan' command to create an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure.





Now that we have a plan set, we can now execute that plan with 'terraform apply' which will create our instance in AWS.





Let's check the AWS management console to see if our EC2 instances has been created. Looks like it did!



Finally, we can destroy our infrastructure using the 'terraform destroy' command.





I hope you enjoyed following along if you did!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published