DEV Community

Cover image for Deploy an Nginx Web Server on an EC2 instance with Terraform

Deploy an Nginx Web Server on an EC2 instance with Terraform

Daniel Favour on September 19, 2022

In this tutorial, you will learn how to automatically deploy an Nginx Web Server on an EC2 instance, with Terraform. Prerequisites An ...
Collapse
 
opshack profile image
Pooria A

Thanks, great point about user_data.

Collapse
 
bansikah profile image
Tandap Noel Bansikah

Yeah but for me I would use a bash script then under my Ec2 recourse for the user data I will supply the script file

Collapse
 
kamaravichow profile image
Aravind Chowdary

This is outdated, here is the updated guide Nginx web server on EC2 instance with Terraform

Collapse
 
cloudistinct profile image
CloudistinctAB

LOL

Collapse
 
barnyvic profile image
Barny victor

thanks for this

Collapse
 
moe443 profile image
Moe

Hi, great article!
I could be wrong but I think your Terraform file misses attaching the security group to the aws_ubuntu instance, no? :)

Collapse
 
husseinalamutu profile image
Hussein Alamutu

What connects the security group and the instance is the vpc_id, an ec2 instance or any resource in aws, needs to be created in a vpc, in this case default vpc was used and a security group was created that allows ssh etc. in the same vpc to be used by the ec2 instance.

Collapse
 
cloudistinct profile image
CloudistinctAB

"ec2 instance or any resource in AWS, needs to be created in a vpc..." - Not all resources in AWS need to be created in a VPC

Thread Thread
 
husseinalamutu profile image
Hussein Alamutu • Edited

For such resources, it’s desirable to have a vpc, even when it seems like is not needed. Plus without the VPC, most times an alternative is used i.e., AWS private link

Collapse
 
cloudimole profile image
Daniel Sanya

Thanks so much for this clear and concise guideline Favour, I've just become your biggest fan. Is there a way to connect with you?

Collapse
 
cloudimole profile image
Daniel Sanya

Also, I tried this and noticed the filters under the data section really made it difficult for terraform to find the infrastructures and apply them so i removed them to make the range wider.