The ec2_eip.tf File¶
| Filename | Location | Group | Project/Repository |
|---|---|---|---|
ec2_eip.tf | ./ec2_eip.tf | infrastructure | terraform |
Why?¶
Our EC2 instances will each have a static public IPv4 address. This will allow us to SSH into the instances directly so we can provision them. Without public IP addresses we cannot route traffic from the public Internet to the instance nor from the instance to the public Internet.
In the future we'll replace these (E)IPs with a bastion host and perhaps a NAT Gateway.
Breakdown¶
Defining an EIP is very simple:
1 2 3 4 | |
We use the instance attribute to inform AWS what EC2 Instance we want thr EIP to be attached to.
Finally we use the vpc attribute to create a VPC based EIP, because we're using a VPC.
And of course we create our second EIP:
1 2 3 4 | |
The Solution¶
1 2 3 4 5 6 7 8 9 | |
Terraform Documentation¶
| Type | Documentation |
|---|---|
aws_eip | Terraform AWS Provider |
Committing the Code¶
- Set your working directory to the
infrastructure/terraformrepository - Save the file as
ec2_eip.tfand usegit add ec2_eip.tfto add it to the Git staging area - Use
git commit -am 'creating a pair of ipv4 ips for our ec2 instances'to commit the file to our repository - Push the code to GitLab.com:
git push