Deploying-EC2-Instance-in-AWS-Using-Terraform

Step 1. First clone this repo: git clone https://github.com/michaelhollender/Deploying-EC2-Instance-in-AWS-Using-Terraform.git

Step 2: Run the Following Terraform Commands to Create the EC2 Instance and the Underlying Infrastructure

Finally, we are now ready to deploy our AWS resources using Terraform. We must run “terraform init” to initialize the working directory that is holding the Terraform configuration files.

Screenshot

To make sure that the Terraform code is formatted correctly we will need to run “terraform fmt”. When I ran this command all of my Terraform configuration files were formatted correctly, if some files needed to have the formatting corrected, Terraform would correct the formatting, then display the file names at the prompt.

Screenshot

Next, best practices dictates that, we must run “terraform plan” to see a preview of the changes Terraform will make to our infrastructure.

Screenshot Screenshot

As can be seen from the screenshot above, Terraform will create 10 resources in AWS.

Now, let’s deploy our resources:

Screenshot

You will be prompted to confirm that you want to perform these actions. Enter “yes”.

Screenshot

Once the command completes, you should see an output similar to below:

Screenshot

Congratulations! You have successfully deployed an EC2 instance running a webserver using Terraform.

Step 3: Verify Infrastructure Has Been Deployed

To verify, we can go to the management console and check!

Screenshot

We can copy the Public IP address from the management console and paste it in a web browser.

Screenshot Screenshot

Step 4: Tear-down AWS Infrastructure

Run “terraform destroy” to terminate all the resources that were deployed during this lab.

Screenshot

Please see https://medium.com/@michaelhollender/deploying-an-ec2-instance-in-aws-using-terraform-7c9e9a160ae6 for the complete blog article!!

That completes this project! Thank you for reading!