I want to use Terraform to create a VPN with a fixed public IP address that I can assign to our Lambda functions.
I found this blog post and code that does this:
- Blog post: https://jaffarshaik.medium.com/implementing-vpc-architecture-using-terraform-3de6c42d7646
- Github: https://github.com/Jaffarterraform786/vpc
However, when I run the script I get this error:
│ Error: Error creating NAT Gateway: InvalidElasticIpID.Malformed: The elastic-ip ID 'aws_eip.ip.id' is malformed
│ status code: 400, request id: 96b26796-931d-4470-85b5-5c46c39889a9
│
│ with aws_nat_gateway.natgateway,
│ on natgateway.tf line 1, in resource "aws_nat_gateway" "natgateway":
│ 1: resource "aws_nat_gateway" "natgateway" {
This is the content of the natgateway.tf file:
resource "aws_nat_gateway" "natgateway" {
allocation_id = "aws_eip.ip.id"
subnet_id = "aws_subnet.publicsubnet.id"
tags = {
name = "prod nategatway"
}
depends_on = [aws_eip.eip]
}
Things I tried:
- Running scripts on a clean region with no other VPCs created - still didn't work
- Raised an issue on Github: https://github.com/Jaffarterraform786/vpc/issues/2
- Ran the Terraform checkers to see if there's any errors, none found.
Any clue or something in the scripts that I need to change?
CodePudding user response:
There are strings with mistakes in natgateway.tf
. The corrected version is:
resource "aws_nat_gateway" "natgateway" {
allocation_id = aws_eip.eip.id
subnet_id = aws_subnet.publicsubnet.id
tags = {
name = "prod nategatway"
}
depends_on = [aws_eip.eip]
}
Please note that I do not check the validity of the VPC or its other resources. I'm just addressing the error you've reported.