DEV Community

Cover image for Deploying with Terraform
Ijay
Ijay

Posted on

Deploying with Terraform

The workflow design

The architure

In my previous posts, I focused on understanding Infrastructure as Code and setting up my environment. Now it is time to actually build something.

In today's challenge, we are to build our website using Terraform.

What I Built

I used Terraform to create a simple EC2 instance on AWS and made it accessible from the browser.

The setup included:

  • A provider block to connect to AWS

  • A resource block to create the EC2 instance

  • A security group to allow HTTP traffic on port 80

  • A user data script to serve a simple HTML page.

folder structure

To deploy the server, I ran:

terraform init
terraform plan
terraform apply -auto-approve
Enter fullscreen mode Exit fullscreen mode

Confirming the Server

After running terraform apply, Terraform returned a public IP in the AWS Console.

public IP

I copied the public IP generated and pasted it into the browser:

the website

That confirmed that the server was running and accessible.

The challenges I faced

One issue I encountered was using an invalid AMI. At first, my instance failed to launch because the AMI was not valid for my region.

I fixed this by using a data block to dynamically fetch the correct Amazon Linux AMI.

I also had an issue where my server was not loading in the browser. This was because the web server was not properly set up. I fixed it by installing and starting Apache using the user data.

What I Learned

Doing this challenge helped me understand how Terraform actually works in practice.

Conclusion

Instead of clicking around the AWS console, I was able to define everything in code and create infrastructure in a repeatable way.

This is just the beginning, and I’m looking forward to building more as I continue this challenge.

If this resonates with you, feel free to share it with others on a similar journey.


Other Helpful Resources


Stay updated with my projects by following me on Twitter, LinkedIn, and GitHub.

Thank you for reading

Top comments (0)