Creating an image with Packer is the first step. After that, we would like to deploy the image to use it. We can build an AWS EC2 instance based on the image from our Packer template using Terraform.
Example Terraform code would look like the following:
# Configure the AWS provider
provider "aws" {
region = var.region
version = "~> 2.7"
}
# Input variable pointing to an SSH key we want to associate with the
# newly created machine
variable "public_key_path" {
description = <<DESCRIPTION
Path to the SSH public key to be used for authentication.
Ensure this keypair is added to your local SSH agent so provisioners can
connect.
Example: ~/.ssh/terraform.pub
DESCRIPTION
default = "~/.ssh/id_rsa.pub"
}
# Input variable with a name to attach to the SSH key
variable "aws_key_name" {
description = "Desired name of AWS key pair"
default = "terraformer"
}
# An ID from our previous...