When running terraform apply I get an error with keys. I am just learning terraform. I can't seem to find a solution online on how to fix this issue:
machine:terraform$ terraform apply
aws_instance.nginix: Creating...
ami: "" => "ami-d1180894"
associate_public_ip_address: "" => "<computed>"
availability_zone: "" => "<computed>"
ebs_block_device.#: "" => "<computed>"
ephemeral_block_device.#: "" => "<computed>"
instance_state: "" => "<computed>"
instance_type: "" => "t2.nano"
ipv6_address_count: "" => "<computed>"
ipv6_addresses.#: "" => "<computed>"
key_name: "" => "terraform-keys2"
network_interface.#: "" => "<computed>"
network_interface_id: "" => "<computed>"
placement_group: "" => "<computed>"
primary_network_interface_id: "" => "<computed>"
private_dns: "" => "<computed>"
private_ip: "" => "<computed>"
public_dns: "" => "<computed>"
public_ip: "" => "<computed>"
root_block_device.#: "" => "<computed>"
security_groups.#: "" => "<computed>"
source_dest_check: "" => "true"
subnet_id: "" => "<computed>"
tenancy: "" => "<computed>"
volume_tags.%: "" => "<computed>"
vpc_security_group_ids.#: "" => "<computed>"
Error applying plan:
1 error(s) occurred:
* aws_instance.nginix: 1 error(s) occurred:
* aws_instance.nginix: Error launching source instance: InvalidKeyPair.NotFound: The key pair 'terraform-keys2' does not exist
status code: 400, request id: 993cc401-4c7a-4e4b-9630-71bc4b5729b0
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
I tried going to AWS console and creating a keypair but that does not seem to help
From your machine, create the keypair using the command as follow ssh-keygen -f terraform-keys2
then your config should have resource aws_key_pair
as below to it in aws
resource "aws_key_pair" "terraform-keys2" {
key_name = "terraform-keys2"
public_key = "terraform-keys2.pub"
}
With this error, please check if you have created the keypair terraform-keys2
in the region you are working on.
aws_instance.nginix: Error launching source instance: InvalidKeyPair.NotFound: The key pair
terraform-keys2
does not exist status code: 400, request id: 993cc401-4c7a-4e4b-9630-71bc4b5729b0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With