OpenStack is an open source infrastructure platform that uses pooled resources to build and manage private and public clouds. OpenStack Heat templates are files (usually YAML) that configure and automate the deployment of cloud infrastructure.
Recently, I faced some issues while I was creating different heat templates and after further investigation I found that the issue was with OS:Nova:KeyPair. If you are also facing a similar issue, I will be sharing the fix to this problem in this post.
What should work
new_keypair:
type: OS::Nova::KeyPair
properties:
name: "test_key"
save_private_key: true
Ideally, the above code creates a new keypair with name "test_key" along with a public and private key which you can use to create server instances, etc.
Now if this is not working for you and you are getting an error like below, the fix should work for you as well:
Case - 1 - Provide only the public_key contents
The error clearly states that you would need to pass in the public_key as a new parameter.
public_key_content:
type: string
description: Keypair public key
new_keypair:
type: OS::Nova::KeyPair
properties:
name: "test_key"
public_key: { get_param: public_key_content }
The above will work and a new keypair will be created with the public key provided.
Case - 2 - Provide both the public_key and private_key contents
Now, when public_key is provided, it does not generate a private_key automatically so you cannot do something like { get_attr: [test_keypair, private_key] }. If you require the private_key content, you would need to pass it as a new parameter.
private_key_content:
type: string
hidden: true # Pass as a hidden parameter
description: SSH private key
public_key_content:
type: string
description: Keypair public key
new_keypair:
type: OS::Nova::KeyPair
properties:
name: "test_key"
public_key: { get_param: public_key_content }
Run using the openstack stack create command
To create a stack named new-stack using a template.yml can be done my passing the public and private key contents using the --parameter-file argument.
export SSH_KEY=.ssh/id_rsa
openstack stack create new-stack -t ./template.yml --wait \
--parameter-file private_key_content=${SSH_KEY} \
--parameter-file public_key_content=${SSH_KEY}.pub

Top comments (0)