-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
ubuntu-hardened-azure.pkr.hcl
104 lines (90 loc) · 2.79 KB
/
ubuntu-hardened-azure.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
variable "client_id" {
type = string
default = env("ARM_CLIENT_ID")
description = "The Azure Active Directory service principal client ID"
}
variable "client_secret" {
type = string
default = env("ARM_CLIENT_SECRET")
description = "The Azure Active Directory service principal client secret"
}
variable "image_offer" {
description = "The offer to use."
type = string
}
variable "image_sku" {
description = "The SKU to use."
type = string
}
variable "resource_group" {
type = string
description = "Resource group."
}
variable "principal_name" {
type = string
description = "Principal name."
}
variable "subscription_id" {
type = string
default = env("ARM_SUBSCRIPTION_ID")
description = "The ID of the Azure subscription"
}
variable "tenant_id" {
type = string
default = env("ARM_TENANT_ID")
description = "The ID of the Azure Active Directory tenant"
}
variable "vm_size" {
description = "The SKU to use."
type = string
}
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}
packer {
required_plugins {
azure = {
source = "github.com/hashicorp/azure"
version = "~> 2"
}
}
}
source "azure-arm" "hardened" {
image_offer = var.image_offer
image_publisher = "canonical"
image_sku = var.image_sku
managed_image_name = "hardened-ubuntu-${var.image_sku}-${local.timestamp}"
os_type = "Linux"
vm_size = var.vm_size
ssh_clear_authorized_keys = "true"
ssh_keep_alive_interval = "15s"
ssh_pty = "true"
ssh_timeout = "10m"
ssh_username = "ubuntu"
temporary_key_pair_type = "ed25519"
client_id = var.client_id
client_secret = var.client_secret
subscription_id = var.subscription_id
tenant_id = var.tenant_id
managed_image_resource_group_name = var.resource_group
build_resource_group_name = var.resource_group
}
build {
sources = ["source.azure-arm.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/azure.sh"
]
}
}