Resources: VPC (10.0.0.0/16), 1 public subnet, IGW, route table, security group (SSH/22 restricted to admin CIDR, all outbound), IAM role + instance profile, EC2 instances (count-based), Elastic IPs.
Configuration:
map_public_ip_on_launch = falseon the subnet; public IPs assigned only via explicitaws_eipresources per instance, not subnet default.- AMI resolved via
data "aws_ami"(latest AL2023), not hardcoded. - IAM role trust policy scoped to
ec2.amazonaws.comonly. Policies attached:CloudWatchAgentServerPolicy,AmazonSSMManagedInstanceCore. - Two-file variable pattern:
terraform.tfvars(committed, non-sensitive) /secrets.tfvars(gitignored).ssh_allowed_cidrplaceholder in the committed file is intentionally an invalid CIDR, soplan/applyfails ifsecrets.tfvarsisn’t supplied.
Issues/fixes:
- SSH key path used a Windows path (
C:\Users\...) from WSL; fixed by copying key into~/.ssh/(WSL filesystem),chmod 400.
Verification: terraform apply, SSH connectivity confirmed to both instances.