Terraform教程 - 创建AWS Key Pair


每次在创建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了。


文章作者: 逻思
版权声明: 本博客所有文章除特別声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明来源 逻思 !