每次在创建EC2的时候,最好的方式就是能够使得自己本地的SSH Key能够继续工作。下面是步骤:
terraform.tfvars
terraform
public_key_location = "/home/lcoding/.ssh/id_rsa.pub"main.tf
terraform
provider "aws" {
}
variable "public_key_location" {
description = "the location for the aws key pair"
}
resource "aws_key_pair" "tf-ssh-key" {
key_name = "tf-ssh-key"
public_key = file(var.public_key_location)
}运行terraform apply后就会看到在EC2 => Network & Security => Key Pairs中有自己刚创建的Key了。
