Skip to main content

EC2 Instance (Default)

πŸ“¦ Overview​

This Terraform module provisions a default Amazon EC2 instance with minimal configuration. It is intended for sandbox, development, or proof-of-concept environments.


βœ… Key Features​

  • Launches a single EC2 instance
  • Supports selection of instance type, AMI ID, and key pair
  • Enables optional tags for environment and ownership
  • Associates with a specified VPC subnet and security group

πŸ’Ό Use Cases​

  • Quick spin-up of development/test environments
  • Proof-of-concept projects
  • Educational cloud labs
  • Lightweight workloads with simple networking needs

πŸ“₯ Input Variables​

NameTypeDescription
regionstringAWS region for deployment
ami_idstringID of the Amazon Machine Image (AMI) to use
instance_typestringEC2 instance type (e.g., t2.micro)
subnet_idstringSubnet in which to launch the instance
security_group_idslist(string)List of security group IDs to associate
key_namestringName of the EC2 key pair for SSH access
instance_namestringTag value for Name
environmentstringDeployment environment label (e.g., dev, prod)

πŸ“€ Outputs​

NameDescription
instance_idID of the created EC2 instance
instance_public_ipPublic IP address of the EC2 instance
instance_arnARN of the EC2 instance

πŸš€ Deployment Readiness​

  • βœ… Compatible with Terraform 1.0+
  • βœ… Supports AWS provider 5.x
  • πŸ” Requires a valid key pair and subnet ID in the selected region

πŸ› οΈ Example Usage​

module "ec2_instance_default" {
source = "git::ssh://git@github.com/archiphire/aws-level-1-modules.git//compute/ec2-instance-default?ref=v1.0.0"

region = "us-east-1"
ami_id = "ami-0abcdef1234567890"
instance_type = "t3.micro"
subnet_id = "subnet-0123456789abcdef0"
security_group_ids = ["sg-0123abc456def7890"]
key_name = "my-keypair"
instance_name = "dev-box"
environment = "dev"
}
terraform init
terraform plan
terraform apply

or

tofu init
tofu plan
tofu apply

🧹 Cleanup Options​

To remove the EC2 instance:

terraform destroy

or

tofu destroy

Or manually terminate the instance via the AWS Console if it’s tied to other resources or part of a wider environment.

πŸ›‘οΈ Notes​

This is a Level 1 module for creating a single EC2 instance with essential settings. For hardened, production-grade EC2 deployments, consider pairing this with EBS, IAM roles, auto-recovery settings, or a higher-level module.

πŸ”’ Deployment Package Notice​

This module is part of the Level 1 AWS License Tier. To access the full deployment package and source code, subscribe to Archiphire.