Build your first
cloud server.
Use Terraform to provision an Ubuntu virtual machine on Amazon Web Services. Learn the workflow, understand each file, review the plan, and clean up the resources when you're done.
What are we creating?
A simple Ubuntu EC2 instance in the default VPC, with an inbound HTTP rule. Terraform describes the infrastructure; AWS hosts it.
Ubuntu EC2
A virtual server launched using an Ubuntu AMI and a configurable instance type.
Default VPC
Uses the account's default VPC and its default subnets to keep the first lab smaller.
HTTP rule
Allows inbound TCP port 80 from the internet. A web server must still be installed separately to serve a page.
Before you start
Complete these checks before running Terraform. You need access to an AWS account and a terminal on your computer.
Install Terraform CLI
Use the official installer for your operating system, then verify with terraform version.
Install and configure AWS CLI
Configure a named profile with credentials or a role. Never paste access keys into Terraform files.
Confirm your AWS identity and region
Run aws sts get-caller-identity --profile terraform-lab and confirm the intended account.
Create a dedicated project folder
Keep the Terraform configuration in one folder and open it in your terminal or VS Code.
Check cost and permissions
Use a sandbox account, confirm the selected instance type and understand AWS charges before applying.
Review the lab safety notes
Do not commit state, plan files, credentials or other sensitive values to a public repository.
Official setup: Terraform installation · AWS CLI installation
Meet your Terraform files
Each file has one clear responsibility. Select a tab, read the explanation, and copy the configuration into your project.
Provider and version requirements
This file declares the required Terraform version and AWS provider source. The lock file created by initialization records the selected provider build.
Command walkthrough
Run these commands in your local terminal from the Terraform project folder. The simulator below explains the expected purpose; it does not run commands on your machine.
The safe Terraform lifecycle
Initialize
Download required provider plugins.
Format & validate
Check style and configuration structure.
Plan
Review proposed changes before approval.
Apply
Create the infrastructure after review.
Try the command simulator
Choose a command to see what it does and what to look for in the output.
This is a guided simulation, not a real shell.
terraform plan. Applying creates billable AWS resources. Do not approve a plan if the account, region, instance type, network or proposed changes are unexpected.Verify, then clean up
A successful apply is not the end. Confirm what was created, understand the outputs, and destroy the disposable resources when finished.
Check the deployment
- Review the EC2 instance in the AWS console.
- Confirm its state is running and the region is correct.
- Use
terraform outputto inspect the instance ID and public IP. - Remember: an EC2 instance alone does not install or start a web server.
Destroy the lab resources
First preview the destroy operation, inspect the proposed deletions, and only then run the destroy command.
terraform plan -destroy
terraform destroyQuick knowledge check
Answer all three questions to test the core ideas from this lab.