| || || || |
We'll publish a public key to AWS, an EC2 Key Pair, and use this to SSH into instances and manage them via Ansible. Without defining a Key Pair in AWs we'll be able to manage or access our instances.
If you use the wrong SSH public key then you'll be locked out of your EC2 Instances. You'll have to recreate the instances if you get the key wrong and have to change it to the correct one.
1 2 3 4
The contents of
deployment_key.pub are what you need to provide for the above code to work. This means you have to update the
public_key attribute of the
aws_key_pair to be the contents of your public key, not mine.
Remember when you created this key?
You can get these contents by using
Remember that the file
deployment_key is the private key and should not be shared with anyone!
Grab the contents of the file and copy/paste them into the
1 2 3 4
| ||Terraform AWS Provider|
Committing the Code¶
- Set your working directory to the
- Save the file as
git add key_pairs.tfto add it to the Git staging area
git commit -am 'defining the public key for ssh access to our instances'to commit the file to our repository
- Push the code to GitLab.com: