github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/examples/packer-docker-example/build.pkr.hcl (about) 1 packer { 2 required_plugins { 3 amazon = { 4 version = ">=v1.0.0" 5 source = "github.com/hashicorp/amazon" 6 } 7 } 8 } 9 10 variable "ami_name_base" { 11 type = string 12 default = "terratest-packer-docker-example" 13 } 14 15 variable "aws_region" { 16 type = string 17 default = "us-east-1" 18 } 19 20 variable "instance_type" { 21 type = string 22 default = "t2.micro" 23 } 24 25 data "amazon-ami" "aws" { 26 filters = { 27 architecture = "x86_64" 28 "block-device-mapping.volume-type" = "gp2" 29 name = "*ubuntu-xenial-16.04-amd64-server-*" 30 root-device-type = "ebs" 31 virtualization-type = "hvm" 32 } 33 most_recent = true 34 owners = ["099720109477"] 35 region = var.aws_region 36 } 37 38 source "amazon-ebs" "ubuntu-ami" { 39 ami_description = "An example of how to create a custom AMI with a simple web app on top of Ubuntu" 40 ami_name = "${var.ami_name_base}-${formatdate("YYYYMMDD-hhmm", timestamp())}" 41 encrypt_boot = false 42 instance_type = var.instance_type 43 region = var.aws_region 44 source_ami = data.amazon-ami.aws.id 45 ssh_username = "ubuntu" 46 } 47 48 source "docker" "ubuntu-docker" { 49 changes = ["ENTRYPOINT [\"\"]"] 50 commit = true 51 image = "gruntwork/ubuntu-test:16.04" 52 } 53 54 build { 55 sources = ["source.amazon-ebs.ubuntu-ami", "source.docker.ubuntu-docker"] 56 57 provisioner "shell" { 58 inline = ["echo 'Sleeping for a few seconds to give Ubuntu time to boot up'", "sleep 30"] 59 only = ["amazon-ebs.ubuntu-ami"] 60 } 61 62 provisioner "file" { 63 destination = "/tmp/packer-docker-example" 64 source = path.root 65 } 66 67 provisioner "shell" { 68 inline = ["/tmp/packer-docker-example/configure-sinatra-app.sh"] 69 } 70 71 post-processor "docker-tag" { 72 only = ["docker.ubuntu-docker"] 73 repository = "gruntwork/packer-docker-example" 74 tag = ["latest"] 75 } 76 }