Terraform Basics - EC2 instance
January 28, 2020 ยท View on GitHub
Goal
Create EC2 instance running Amazon Linux AMI in the public subnet (default VPC) using aws_instance resource and aws_ami data-source.
Tasks
- Make sure to install Terraform 0.12
- Start with updating content of
main.tfin this directory (see sub-tasks in that file) - Optionally, split content into
main.tf,variables.tfandoutputs.tffor better readability
Solutions
Solutions are inside solutions/0-basic directory.
Extra tasks
-
Verify that EC2 instance has been launched (using
aws_instancedata source, AWS CLI or AWS Console). -
Launch 2 similar EC2 instances (using
countmeta-argument onaws_instanceresource) and output their public IPs. -
Explore various Terraform built-in functions and learn the difference between accessing element in a list using short form (
[0]) and element() function. -
Connect to EC2 instance by SSH (eg, using EC2 keypair).
-
Using terraform-aws-elb module create a public-facing Elastic Load Balancer which will stay in front of EC2 instances launched by an autoscaling group.