Terraform AWS EC2 Instance Config Builder
This builder generates Terraform HCL to launch an AWS EC2 instance along with a security group that governs inbound access. It produces a self-contained configuration you can terraform apply immediately, with sensible defaults for SSH access, an optional first-boot script, and tags for cost tracking.
How it works
The output defines an aws_security_group with one ingress block per port you allow (protocol tcp, source 0.0.0.0/0) and a permissive egress block. It then defines an aws_instance referencing that security group via vpc_security_group_ids. Key fields:
ami— the base image id for your region.instance_type— CPU and memory class, for examplet3.micro.key_name— the SSH key pair, included only when provided.user_data— a first-boot shell script, base64 encoded withbase64encode().tags— aNametag and any environment label.
Tips and example
After copying, initialize and launch:
terraform init
terraform plan
terraform apply
Always look up the correct AMI id for your target region, since AMIs are region scoped. Restrict the SSH ingress source to your own IP rather than 0.0.0.0/0 in production. Keep user_data idempotent so re-runs do not break a booted instance, and tag every resource so it is easy to find and clean up.