Sunday, April 02, 2023

Packer File to Build Image

 {

  "variables": {

    "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",

    "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",

    "region": "us-west-2"

  },

  "builders": [

    {

      "type": "amazon-ebs",

      "access_key": "{{user `aws_access_key`}}",

      "secret_key": "{{user `aws_secret_key`}}",

      "region": "{{user `region`}}",

      "source_ami_filter": {

        "filters": {

          "virtualization-type": "hvm",

          "name": "ubuntu/images/*ubuntu-focal-20.04-amd64-server-*",

          "root-device-type": "ebs"

        },

        "owners": ["099720109477"],

        "most_recent": true

      },

      "instance_type": "t2.micro",

      "ssh_username": "ubuntu",

      "ami_name": "ubuntu-20.04-{{timestamp}}",

      "force_deregister": true

    }

  ],

  "provisioners": [

    {

      "type": "shell",

      "inline": [

        "sudo apt-get update",

        "sudo apt-get upgrade -y",

        "sudo apt-get install -y nginx"

      ]

    }

  ]

}

packer build ubuntu-20.04.json