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β
| Name | Type | Description |
|---|---|---|
region | string | AWS region for deployment |
ami_id | string | ID of the Amazon Machine Image (AMI) to use |
instance_type | string | EC2 instance type (e.g., t2.micro) |
subnet_id | string | Subnet in which to launch the instance |
security_group_ids | list(string) | List of security group IDs to associate |
key_name | string | Name of the EC2 key pair for SSH access |
instance_name | string | Tag value for Name |
environment | string | Deployment environment label (e.g., dev, prod) |
π€ Outputsβ
| Name | Description |
|---|---|
instance_id | ID of the created EC2 instance |
instance_public_ip | Public IP address of the EC2 instance |
instance_arn | ARN 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.