@@ -41,6 +41,13 @@ module "nat" {
4141 private_subnets_cidr_blocks = module.vpc.private_subnets_cidr_blocks
4242 private_route_table_ids = module.vpc.private_route_table_ids
4343}
44+
45+ resource "aws_eip" "nat" {
46+ network_interface = module.nat.eni_id
47+ tags = {
48+ "Name" = "nat-instance-main"
49+ }
50+ }
4451```
4552
4653Now create an EC2 instance in the private subnet to verify the NAT configuration.
@@ -55,12 +62,13 @@ This module provisions the following resources:
5562
5663- Auto Scaling Group with mixed instances policy
5764- Launch Template
58- - Elastic IP
5965- Elastic Network Interface
6066- Security Group
6167- IAM Role for SSM and ENI attachment
6268- VPC Route (optional)
6369
70+ You need to attach your elastic IP to the ENI.
71+
6472Take a look at the diagram:
6573
6674![ diagram] ( diagram.svg )
@@ -119,6 +127,24 @@ resource "aws_security_group_rule" "nat_ssh" {
119127```
120128
121129
130+ ## Migration guide
131+
132+ ### Upgrade to v2 from v1
133+
134+ This module no longer creates an EIP since v2.
135+
136+ To keep your EIP when you migrate to module v2, rename the EIP in the state as follows:
137+
138+ ``` console
139+ % terraform state mv -dry-run module.nat.aws_eip.this aws_eip.nat
140+ Would move "module.nat.aws_eip.this" to "aws_eip.nat"
141+
142+ % terraform state mv module.nat.aws_eip.this aws_eip.nat
143+ Move "module.nat.aws_eip.this" to "aws_eip.nat"
144+ Successfully moved 1 object(s).
145+ ```
146+
147+
122148## Contributions
123149
124150This is an open source software. Feel free to open issues and pull requests.
@@ -152,14 +178,11 @@ No requirements.
152178| user\_ data\_ runcmd | Additional runcmd section of cloud-init | ` list ` | ` [] ` | no |
153179| user\_ data\_ write\_ files | Additional write\_ files section of cloud-init | ` list ` | ` [] ` | no |
154180| vpc\_ id | ID of the VPC | ` string ` | n/a | yes |
155- | eip_creation | Whether to create an eip | ` bool ` | ` true ` | no |
156181
157182## Outputs
158183
159184| Name | Description |
160185| ------| -------------|
161- | eip\_ id | ID of the Elastic IP |
162- | eip\_ public\_ ip | Public IP of the Elastic IP for the NAT instance |
163186| eni\_ id | ID of the ENI for the NAT instance |
164187| eni\_ private\_ ip | Private IP of the ENI for the NAT instance |
165188| iam\_ role\_ name | Name of the IAM role for the NAT instance |
0 commit comments