Troubleshooting a failing VPC Transit Gateway Terraform Apply sequence

2024-06-06 1 min read Troubleshooting Barny Baron

Journey: 📊 Community Builder 📊

Subject matter: 💡 Troubleshooting 💡

When I was working on a recent VPC Transit Gateway build using Terraform, I ran into a problem that needed troubleshooting and thought I would share it.

Content

During the Terraform Apply sequence, it failed with the following error:

“Error: creating EC2 Instance: InvalidKeyPair.NotFound: The key pair ‘<>’ does not exist.”

Error

Investigations commence!

Configuration parameters:
  • The Terraform configuration sets everything up in region US-East-1.
  • I knew I had a key pair set up already and had pointed my configuration to the key pair but it could not be seen.
Problem observed:

The configuration could not find the key pair and failed.

After running some checks, I found my mistake… I had accidently created the key pair in US-East-2.

Fix required:

I recreated my key pair in the correct region:

Fixing

I then re-ran the Terraform Apply command and this completed without error. The environment was built out successfully!

Successful

I used the following documentation to troubleshoot:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/tag-key-pair.html

It was a simple error but I hope it might help someone else who runs into the same problem.

A link to the VPC project overview is here: Building a VPC Transit Gateway between VPCs using Terraform!

Cloud