EC2 Instance Spot
๐ฆ Overviewโ
This Terraform module provisions a Spot EC2 instance in AWS. Spot instances are ideal for cost-sensitive, fault-tolerant workloads such as stateless services, batch jobs, or testing environments.
โ Key Featuresโ
- Launches a Spot EC2 instance with user-specified AMI and instance type
- Supports SSH key-based access and security group assignments
- Tags resources with environment and organizational metadata
- Offers significant cost savings over On-Demand instances
๐ผ Use Casesโ
- Batch processing or CI/CD workloads
- Short-lived compute environments for testing
- Stateless applications where resiliency is externalized
- Scalable fleets built on Spot pricing models
๐ฅ Input Variablesโ
| Name | Type | Description |
|---|---|---|
| region | string | AWS region for deployment |
| instance_type | string | EC2 instance type (e.g., t3.micro) |
| ami_id | string | AMI ID for the instance |
| key_name | string | SSH key name for access |
| subnet_id | string | Subnet ID to launch the instance into |
| security_group_ids | list | List of security group IDs to attach |
| environment | string | Tag to represent the deployment environment |
๐ค Outputsโ
| Name | Description |
|---|---|
| instance_id | The ID of the Spot EC2 instance |
| instance_public_ip | Public IP address (if assigned) |
| instance_arn | ARN of the deployed EC2 instance |
๐ Deployment Readinessโ
- โ Compatible with Terraform 1.0+
- โ Requires AWS Provider 5.x+
- ๐ Requires
ec2:RunInstancesand related IAM permissions
๐ ๏ธ Example Usageโ
module "ec2_instance_spot_deployment" {
source = "git::ssh://git@github.com/archiphire/aws-level-1-modules.git//compute/ec2-instance-spot?ref=v1.0.0"
region = "us-east-1"
instance_type = "t3.micro"
ami_id = "ami-0123456789abcdef0"
key_name = "archiphire-key"
subnet_id = "subnet-abc123"
security_group_ids = ["sg-12345678"]
environment = "test"
}
terraform init
terraform plan
terraform apply
or
tofu init
tofu plan
tofu apply
๐งน Cleanupโ
Terraform Destroy (Isolated Use):
terraform destroy
or
tofu destroy
Manual Deletion (Production Use):
aws ec2 terminate-instances --instance-ids <instance-id>
๐ก๏ธ Notesโ
This is a Level 1 compute module optimized for ephemeral workloads.
To build fault-tolerant systems, pair this with auto-recovery logic or Spot Fleet integrations.
๐ 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.