How to Terraform import an AWS Route of Route Table targeting a NAT gateway

Viewed 1562

Given the following AWS resources:

  • Route table
  • Route of Route table
  • NAT gateway

The following HCL code (Terraform v0.11)

resource "aws_route" "nat-route" {
  route_table_id         = "${var.route_table_id}"
  destination_cidr_block = "0.0.0.0/0"
  nat_gateway_id         = "${var.nat_gw_id}"
}

The Terraform documentation suggest this method to import:

terraform import aws_route.nat-route rtb-123456ABCDF_0.0.0.0/0

But didn't specify the target ID for its NAT gateway, VPC peering, Internet gateway, etc. only the route table and the destination CIDR.

How can this NAT route be imported to the Terraform state?

1 Answers

Does your existing Route already have it's NAT gateway etc configured (in AWS)? If so, then Terraform will pick up all the configuration during the import. If not, then you can configure those items with Terraform after importing it.

Related