-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
ubuntu-hardened-aws.pkr.hcl
70 lines (62 loc) · 1.74 KB
/
ubuntu-hardened-aws.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
69
70
variable "aws_region" {
description = "The AWS Region to use."
type = string
}
variable "instance_type" {
description = "The Amazon EC2 Instance Type to use."
type = string
}
variable "release" {
description = "The Ubuntu release to use, YY-MM format."
type = string
}
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}
packer {
required_plugins {
amazon = {
version = ">= 1.2.6"
source = "github.com/hashicorp/amazon"
}
}
}
source "amazon-ebs" "hardened" {
ami_name = "hardened-ubuntu-${local.timestamp}"
instance_type = var.instance_type
region = var.aws_region
source_ami_filter {
filters = {
name = "ubuntu/images/hvm-ssd-gp3/*ubuntu-*${var.release}-amd64-server*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["099720109477"]
}
ssh_clear_authorized_keys = "true"
ssh_keep_alive_interval = "15s"
ssh_pty = "true"
ssh_timeout = "10m"
ssh_username = "ubuntu"
temporary_key_pair_type = "ed25519"
}
build {
sources = ["source.amazon-ebs.hardened"]
provisioner "file" {
sources = ["config/ansible.cfg", "config/local.yml"]
destination = "/tmp/"
}
provisioner "shell" {
environment_vars = ["ANSIBLE_CONFIG=/tmp/ansible.cfg", "HOME_DIR=/home/ubuntu", "TMPDIR=/var/tmp"]
execute_command = "echo 'ubuntu' | {{ .Vars }} sudo -S -E sh -eux '{{ .Path }}'"
expect_disconnect = true
pause_before = "10s"
remote_folder = "/var/tmp"
scripts = [
"${path.root}/scripts/hardening.sh",
"${path.root}/scripts/cleanup.sh",
"${path.root}/scripts/aws.sh"
]
}
}