-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathimage.pkr.hcl
More file actions
114 lines (96 loc) · 2.6 KB
/
image.pkr.hcl
File metadata and controls
114 lines (96 loc) · 2.6 KB
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
105
106
107
108
109
110
111
112
113
114
packer {
required_plugins {
amazon = {
source = "github.com/hashicorp/amazon"
version = "~> 1.3.1"
}
}
}
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}
variable "region" {
type = string
}
variable "nomad_version" {
type = string
default = "1.8.1"
}
variable "consul_version" {
type = string
default = "1.18.2"
}
variable "consul_template_version" {
type = string
default = "0.39.0"
}
variable "vault_version" {
type = string
default = "1.17.0"
}
data "amazon-ami" "hashistack" {
filters = {
architecture = "x86_64"
"block-device-mapping.volume-type" = "gp2"
name = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["099720109477"]
region = var.region
}
source "amazon-ebs" "hashistack" {
ami_name = "hashistack-${local.timestamp}"
instance_type = "t2.medium"
region = var.region
source_ami = "${data.amazon-ami.hashistack.id}"
ssh_username = "ubuntu"
force_deregister = true
force_delete_snapshot = true
tags = {
Name = "nomad"
source = "hashicorp/learn"
purpose = "demo"
OS_Version = "Ubuntu"
Release = "Latest"
Base_AMI_ID = "{{ .SourceAMI }}"
Base_AMI_Name = "{{ .SourceAMIName }}"
}
snapshot_tags = {
Name = "nomad"
source = "hashicorp/learn"
purpose = "demo"
}
}
build {
hcp_packer_registry {
bucket_name = "nomad-consul"
description = "AMI with Nomad, Consul and Vault"
build_labels = {
"nomad_version" = var.nomad_version,
"consul_version" = var.consul_version,
"consul_template_version" = var.consul_template_version,
"vault_version" = var.vault_version,
"region" = var.region
}
}
sources = ["source.amazon-ebs.hashistack"]
provisioner "shell" {
inline = ["sudo mkdir -p /ops/shared", "sudo chmod 777 -R /ops"]
}
provisioner "file" {
destination = "/ops"
source = "shared"
}
provisioner "shell" {
environment_vars = ["INSTALL_NVIDIA_DOCKER=false", "CLOUD_ENV=aws"]
script = "./shared/scripts/setup.sh"
env = {
"NOMADVERSION" = var.nomad_version,
"CONSULVERSION" = var.consul_version,
"CONSULTEMPLATEVERSION" = var.consul_template_version,
"VAULTVERSION" = var.vault_version
}
}
}