运行Terraform时按键错误

spr*_*oob 6 terraform

当运行terraform apply时,键出现错误。我只是在学习地形。我似乎无法找到有关如何解决此问题的在线解决方案:

   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.
Run Code Online (Sandbox Code Playgroud)

我尝试转到AWS控制台并创建密钥对,但这似乎无济于事

Inn*_*gbo 10

在您的机器上,使用以下命令创建密钥对 ssh-keygen -f terraform-keys2

那么你的配置应该aws_key_pair在 aws 中有如下资源

resource "aws_key_pair" "terraform-keys2" {
  key_name = "terraform-keys2"
  public_key = "terraform-keys2.pub"
}
Run Code Online (Sandbox Code Playgroud)

  • 似乎需要给出密钥的内容,而不是路径:`public_key = "${file("${path.root}/terraform-keys2.pub")}"` 应该可以工作 (2认同)

BMW*_*BMW 6

出现此错误,请检查您是否terraform-keys2在要处理的区域中创建了密钥对。

aws_instance.nginix:启动源实例时出错:InvalidKeyPair.NotFound:密钥对terraform-keys2不存在状态码:400,请求标识:993cc401-4c7a-4e4b-9630-71bc4b5729b0