-
Notifications
You must be signed in to change notification settings - Fork 0
/
webserver.pkr.hcl
68 lines (59 loc) · 1.44 KB
/
webserver.pkr.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
packer {
required_plugins {
amazon = {
version = ">= 0.0.2"
source = "github.com/hashicorp/amazon"
}
}
}
variable "ami_prefix" {
type = string
default = "noah-challenge"
}
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}
source "amazon-ebs" "ubuntu" {
ami_name = "${var.ami_prefix}-${local.timestamp}"
instance_type = "t2.micro"
region = "us-east-1"
source_ami_filter {
filters = {
name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["099720109477"]
}
ssh_username = "ubuntu"
}
build {
name = "packer-ubuntu"
sources = [
"source.amazon-ebs.ubuntu"
]
provisioner "file" {
source = "index.html"
destination = "/tmp/index.html"
}
provisioner "file" {
source = "website"
destination = "/tmp/website"
}
provisioner "shell" {
inline = [
"echo Installing NGINX server...",
"sleep 10",
"sudo apt update",
"sudo apt install -y nginx",
"echo Install of NGINX successful...",
"echo Creating site directory...",
"sudo mkdir -p /var/www/website",
"sudo cp /tmp/index.html /var/www/website/index.html",
"sudo cp /tmp/website /etc/nginx/sites-enabled/website",
"sudo systemctl enable nginx",
"sudo service nginx restart",
]
}
}