Skip to content

Commit 37e56ca

Browse files
committed
Updated the packer example to use HCL
1 parent accd6c6 commit 37e56ca

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

packer-example/simple-web-server.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"region": "us-east-2"
44
},
55
"builders": [{
6-
"ami_name": "gruntwork-packer-training-rails-{{isotime | clean_ami_name}}",
7-
"ami_description": "An Ubuntu AMI that with Ruby on Rails installed.",
6+
"ami_name": "gruntwork-packer-training-rails-{{isotime | clean_resource_name}}",
7+
"ami_description": "An Ubuntu AMI that has Ruby on Rails installed.",
88
"instance_type": "t2.micro",
99
"region": "{{user `region`}}",
1010
"type": "amazon-ebs",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
variable "region" {
2+
description = "The AWS Region to launch the AMI builder in"
3+
default = "us-east-2"
4+
}
5+
6+
source "amazon-ebs" "ubuntu" {
7+
ami_name = "gruntwork-packer-training-rails-hcl-{{isotime | clean_resource_name}}"
8+
ami_description = "An Ubuntu AMI that has Ruby on RIls installed"
9+
region = var.region
10+
instance_type = "t2.micro"
11+
12+
source_ami_filter {
13+
filters = {
14+
virtualization-type = "hvm"
15+
architecture = "x86_64"
16+
name = "*ubuntu-xenial-16.04-amd64-server-*"
17+
root-device-type = "ebs"
18+
}
19+
owners = ["099720109477"]
20+
most_recent = true
21+
}
22+
communicator = "ssh"
23+
ssh_username = "ubuntu"
24+
}
25+
26+
build {
27+
sources = ["source.amazon-ebs.ubuntu"]
28+
29+
provisioner "shell" {
30+
inline = [
31+
"echo 'Sleeping for 30 seconds to give Ubuntu enough time to initialize (otherwise, packages may fail to install).'",
32+
"sleep 30"
33+
]
34+
}
35+
36+
provisioner "shell" {
37+
# TODO: Use `template_dir` once implemented for HCL:
38+
# https://github.com/hashicorp/packer/issues/9176
39+
script = "./install-rails.sh"
40+
}
41+
42+
provisioner "file" {
43+
# TODO: Use `template_dir` once implemented for HCL:
44+
# https://github.com/hashicorp/packer/issues/9176
45+
source = "../example-rails-app"
46+
destination = "/home/ubuntu"
47+
}
48+
49+
provisioner "shell" {
50+
inline = [
51+
"cd /home/ubuntu/example-rails-app",
52+
"bundle install"
53+
]
54+
}
55+
}

0 commit comments

Comments
 (0)