For this project, I used Terraform to automate the provisioning of an AWS EC2 instance and then created a custom Amazon Machine Image (AMI) from that instance. This report documents the steps I took, the evidence of the created resources, and the process for cleaning up the environment.
My primary goal was to apply Infrastructure as Code (IaC) principles to create a reusable server template, demonstrating a foundational DevOps skill.
I began by ensuring my local environment was correctly configured to interact with AWS.
-
AWS CLI Version: I first confirmed the AWS CLI was installed.
aws --version
-
AWS CLI Configuration: I then verified that the CLI was configured with my credentials.
aws configure list
-
AWS Authentication: I ran
sts get-caller-identityto ensure my credentials were valid and authentication to my AWS account was successful.aws sts get-caller-identity
Evidence below confirms my identity and successful authentication.

-
Terraform Version: Finally, I confirmed that Terraform was installed and ready.
terraform --version
With the prerequisites confirmed, I proceeded with the implementation.
I created a new directory for the project to keep the configuration files organized.
mkdir terraform-ec2-ami
cd terraform-ec2-amiI created a main.tf file and wrote the following script. The script defines the AWS provider, an EC2 instance resource, and a resource to create an AMI from that instance.
provider "aws" {
region = "us-east-1"
}
# This resource defines the EC2 instance I want to create.image
resource "aws_instance" "my_ec2_spec" {
# I chose a standard Amazon Linux 2 AMI for the us-east-1 region.
ami = "ami-052064a798f08f0d3"
instance_type = "t2.micro"
tags = {
Name = "Terraform-created-EC2-Instance"
}
}
# This resource creates a custom AMI from the instance defined above.
resource "aws_ami_from_instance" "my_ec2_spec_ami" {
name = "my-ec2-ami-from-terraform"
source_instance_id = aws_instance.my_ec2_spec.id
tags = {
Name = "My-Custom-AMI"
}
}image
I followed the standard Terraform workflow to deploy the infrastructure.
-
terraform init: I initialized the project, which downloaded the AWS provider plugin. Evidence of successful initialization.
-
terraform plan: I ran a plan to review the changes before applying them. The plan correctly showed that two resources (the EC2 instance and the AMI) would be created. Evidence of the execution plan.
-
terraform apply: I applied the configuration, and after I confirmed withyes, Terraform began creating the resources. Evidence of the successful apply command.
After the apply command completed, I logged into the AWS Management Console to verify the resources were created as expected.
-
EC2 Instance Verification: I navigated to the EC2 dashboard and found the instance named
Terraform-created-EC2-Instancerunning correctly. Evidence: Screenshot from the AWS Console showing the running EC2 instance.
-
Custom AMI Verification: I then went to the AMIs section and confirmed that the new AMI,
my-ec2-ami-from-terraform, was successfully created. Evidence: Screenshot from the AWS Console showing the new custom AMI.
During the project, I anticipated some potential errors. For example, an InvalidAMIID.NotFound error could occur if the AMI ID was incorrect for the chosen region. To mitigate this, I ensured the AMI ID was valid for us-east-1. I also knew to use aws_ami_from_instance instead of aws_ami to avoid an Unsupported argument error for source_instance_id.
To avoid incurring costs, I cleaned up all the resources created during this project using the destroy command.
terraform destroy: I ran the destroy command and confirmed withyesto terminate the EC2 instance and deregister the AMI. Evidence of the successful destroy operation.
This project was a successful exercise in using Terraform to automate infrastructure provisioning on AWS.


