AWS Amazon EC2 EIP
This page shows how to write Terraform and CloudFormation for Amazon EC2 EIP and write them securely.
aws_eip (Terraform)
The EIP in Amazon EC2 can be configured in Terraform with the resource name aws_eip. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_eip" "eipalloc-dev-nat-eu-central-1c" { // 0ce2e574181a9bb6b
network_interface = aws_network_interface.eni-dev-nat-eu-central-1c.id // "eni-0e906faf95f71552b"
vpc = true
}
resource "aws_eip" "eipalloc-dev-nat-eu-central-1a" { // 0d599a316dbe98a24
resource "aws_eip" "kafka1" {
instance = aws_instance.kafka1.id
vpc = true
}
resource "aws_instance" "kafka1" {
resource "aws_eip" "prod-ip1" {}
resource "aws_eip" "prod-ip2" {}
resource "aws_eip" "stag-ip1" {}
resource "aws_eip" "stag-ip2" {}
resource "aws_eip" "tokyo_eip" {
provider = aws.tokyo
vpc = "true"
tags = {
Name = "salawu-live-demo"
resource "aws_eip" "prod-ip1" {}
resource "aws_eip" "prod-ip2" {}
resource "aws_eip" "stag-ip1" {}
resource "aws_eip" "stag-ip2" {}
resource "aws_eip" "stag-ip3" {}
Parameters
-
allocation_idoptional computed - string -
associate_with_private_ipoptional - string -
association_idoptional computed - string -
carrier_ipoptional computed - string -
customer_owned_ipoptional computed - string -
customer_owned_ipv4_pooloptional - string -
domainoptional computed - string -
idoptional computed - string -
instanceoptional computed - string -
network_border_groupoptional computed - string -
network_interfaceoptional computed - string -
private_dnsoptional computed - string -
private_ipoptional computed - string -
public_dnsoptional computed - string -
public_ipoptional computed - string -
public_ipv4_pooloptional computed - string -
tagsoptional - map from string to string -
vpcoptional computed - bool -
timeoutssingle block
Explanation in Terraform Registry
Provides an Elastic IP resource.
Note: EIP may require IGW to exist prior to association. Use
depends_onto set an explicit dependency on the IGW. Note: Do not usenetwork_interfaceto associate the EIP toaws_lboraws_nat_gatewayresources. Instead use theallocation_idavailable in those resources to allow AWS to manage the association, otherwise you will seeAuthFailureerrors.
Tips: Best Practices for The Other AWS Amazon EC2 Resources
In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_default_vpc
Ensure to avoid using default VPC
It is better to define the own VPC and use it.
aws_network_acl_rule
Ensure your network ACL rule blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
aws_ebs_volume
Ensure to use a customer-managed key for EBS volume encryption
It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).
aws_instance
Ensure to avoid storing AWS access keys in user data
It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.
aws_security_group
Ensure your security group blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
AWS::EC2::EIP (CloudFormation)
The EIP in EC2 can be configured in CloudFormation with the resource name AWS::EC2::EIP. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: 'AWS::EC2::EIP'
Properties:
Tags:
- Key: Name
Value: !Sub '${StackName}-EIPA-${Env}'
Domain: vpc
Type: AWS::EC2::EIP
Properties:
Domain: vpc
EIP2:
Type: AWS::EC2::EIP
Type: 'AWS::EC2::EIP'
Properties:
Domain: vpc
SecondEIP:
Type: 'AWS::EC2::EIP'
Type: AWS::EC2::EIP
Properties:
Domain: vpc
EipAz2:
Type: AWS::EC2::EIP
Type: AWS::EC2::EIP
Properties:
Tags:
- Key: Name
Value: ${env:APP_NAME}-eip-ngw-az1
Domain: Vpc
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "VPC"
}
},
"EIP2": {
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "VPC"
}
},
"EIP2": {
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "VPC"
}
},
"EIP2": {
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "VPC"
}
},
"EIP2": {
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "vpc"
}
},
"EIP2": {
Parameters
-
Domainoptional - String -
InstanceIdoptional - String -
PublicIpv4Pooloptional - String -
Tagsoptional - List of Tag
Explanation in CloudFormation Registry
Specifies an Elastic IP (EIP) address and can, optionally, associate it with an Amazon EC2 instance.
You can allocate an Elastic IP address from an address pool owned by AWS or from an address pool created from a public IPv4 address range that you have brought to AWS for use with your AWS resources using bring your own IP addresses (BYOIP). For more information, see Bring Your Own IP Addresses (BYOIP) in the Amazon EC2 User Guide.
[EC2-VPC] If you release an Elastic IP address, you might be able to recover it. You cannot recover an Elastic IP address that you released after it is allocated to another AWS account. You cannot recover an Elastic IP address for EC2-Classic. To attempt to recover an Elastic IP address that you released, specify it in this operation.
An Elastic IP address is for use either in the EC2-Classic platform or in a VPC. By default, you can allocate 5 Elastic IP addresses for EC2-Classic per Region and 5 Elastic IP addresses for EC2-VPC per Region.
For more information, see Elastic IP Addresses in the Amazon EC2 User Guide.
Frequently asked questions
What is AWS Amazon EC2 EIP?
AWS Amazon EC2 EIP is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Amazon EC2 EIP?
For Terraform, the mdigbazova/terraforming-4ha-live-all-resources, asaushkin/kafka-ansible and Dtenizbek/terraform source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the codedoeseverything/devops-infra, thbishop/kv and stelligent/cfn-model source code examples are useful. See the CloudFormation Example section for further details.