How Do You Troubleshoot the Terraform Error ‘unsupported argument aws_key_pair’?

Problem scenario
You run a terraform command. You get 'unsupported argument aws_key_pair'. You want terraform to create an EC-2 server with a specific key pair. What should you do?

Don't use "aws_key_pair", use "key_name". The aws_instance section in a .tf file uses a different keyword. (The aws_key_pair is for creating an key-pair in AWS.) Use the "key_name" field for aws_instances like this:

resource "aws_instance" "example" {
  ami           = "ami-01a1234abcd567"
  instance_type = "t2.micro"
  key_name      = "appleorange"

Leave a comment

Your email address will not be published. Required fields are marked *