AWS EC2 Foreman SSH Key Deletion/Recreation

Hi All,

I have come across the following issue(s) which the EC2 compute resource.

Initial creation of an EC2 resource works fine.

1: An attempt to recreate the SSH key pair by clicking the "recreate"
option in the SSH Tab on the Foreman UI results in the following error:

*Oops, we're sorry but something went wrong *Validation failed: Compute
resource has already been taken

2: If the ssh key is deleted from within the Network & Security -> Key
Pairs section of the AWS Web Console the key disappears from the list,
however the user is not subsequently requested to create a new key pair.
The SSH tab on the Foreman UI displays the correct list of SSH keys
present in the Key Pairs list on AWS

3: An attempt to resolve the above issue with the forman console
(foreman-rake console) results in the following:

irb(main):006:0> ComputeResource.find_by(:name => 'AWS').send(:recreate)

ActiveRecord::RecordInvalid: Validation failed: Compute resource has
already been taken

The issue can be worked around by running the following:

irb(main):001:0> ComputeResource.find_by(:name =>
'AWS').send(:destroy_key_pair)

=> true

irb(main):002:0> ComputeResource.find_by(:name =>
'AWS').send(:create_key_pair)

=> #<KeyPair id: nil, secret: nil, compute_resource_id: 1, name: nil,
created_at: nil, updated_at: nil, public: nil>

And then going back to the compute resource from the main compute resource
menu ( Infrastructure -> Computer resource) on the Foreman UI

I don't believe the above is intended behaviour.

From a user perspective the recreate button should work, however there
should also be an option to create a new pair where one doesn't exist, or
arbitrarily.

Callum

1 Like