test-kitchen / kitchen-ec2

A Test Kitchen Driver for Amazon EC2
Other
221 stars 202 forks source link

Unable to create EC2 instance with `unexpected value at params[:key_type]` error #595

Closed jmvbxx closed 1 year ago

jmvbxx commented 1 year ago

:speaking_head: Foreword

Thank for taking the time to fill this bug report fully. Without it we may not be able to fix the bug, and the issue may be closed without resolution.

:ghost: Brief Description

When attempting to spin up an EC2 instance the following error occurs:

>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #create action: [unexpected value at params[:key_type] in the specified region us-east-1. Please check this AMI is available in this region.] on default-amazonlinux
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

Before I continue, yes, I've confirmed that the AMI is correct and exists in the account/region specified.

Version

kitchen-ec2 v3.15.0

Environment

Local workstation: Ubuntu 22.04 kitchen-ec2 v3.15.0

Scenario

Trying to spin up an EC2 instance and unable to based on the above error. Full output is:

-----> Starting Test Kitchen (v2.4.0)
-----> Creating <default-amazonlinux>...
       instance_type not specified. Using free tier t2.micro instance ...
       Detected platform: amazon2 version 5.10 on x86_64. Instance Type: t2.micro. Default username: ec2-user (default).
       If you are not using an account that qualifies under the AWS
free-tier, you may be charged to run these suites. The charge
should be minimal, but neither Test Kitchen nor its maintainers
are responsible for your incurred costs.

       Created automatic security group sg-0ce07fb5bdbaaab85
       Removing automatic security group sg-0ce07fb5bdbaaab85
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #create action: [unexpected value at params[:key_type] in the specified region us-east-1. Please check this AMI is available in this region.] on default-amazonlinux
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

Steps to Reproduce

Run the command bundle exec kitchen converge default-amazonlinux. Both create and converge have the same behaviour. Also, with and without aws-vault also ends the same way.

The output is as above.

Expected Result

I expect an EC2 instance to get spun up.

Actual Result

The error is above, specifically:

Failed to complete #create action: [unexpected value at params[:key_type] in the specified region us-east-1. Please check this AMI is available in this region.]

Thank you in advance!

jmvbxx commented 1 year ago

I'm sorry, I forgot to include my config

---
driver:
  name: ec2
  subnet_id: subnet-a1b2c3d4e5

provisioner:
  name: chef_solo

verifier:
  name: inspec

platforms:
  - name: amazonlinux
    driver:
      image_id: ami-0b5eea76982371e91
jmvbxx commented 1 year ago

After reading the source code, I discovered that the error was related to SSH key configuration. I solved this today by explicitly updating the config to the following:

---
driver:
  name: ec2
  aws_ssh_key_id: <SSH_KEY_NAME>
  subnet_id: subnet-a1b2c3d4e5

provisioner:
  name: chef_solo

verifier:
  name: inspec

transport:
  ssh_key: <SSH_KEY_PATH>
  connection_timeout: 10
  connection_retries: 5
  username: ec2-user

platforms:
  - name: amazon
    driver:
      image_id: ami-0b5eea76982371e91