Skip to main content

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โ€‹

NameTypeDescription
regionstringAWS region for deployment
instance_typestringEC2 instance type (e.g., t3.micro)
ami_idstringAMI ID for the instance
key_namestringSSH key name for access
subnet_idstringSubnet ID to launch the instance into
security_group_idslistList of security group IDs to attach
environmentstringTag to represent the deployment environment

๐Ÿ“ค Outputsโ€‹

NameDescription
instance_idThe ID of the Spot EC2 instance
instance_public_ipPublic IP address (if assigned)
instance_arnARN of the deployed EC2 instance

๐Ÿš€ Deployment Readinessโ€‹

  • โœ… Compatible with Terraform 1.0+
  • โœ… Requires AWS Provider 5.x+
  • ๐Ÿ” Requires ec2:RunInstances and 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.