forked from romange/image-bakery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprometheus.pkr.hcl
117 lines (100 loc) · 2.77 KB
/
prometheus.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
105
106
107
108
109
110
111
112
113
114
115
116
117
variable "region" { default = "us-east1" }
variable "zone" { default = "us-east1-b" }
variable "project" {
default = ""
}
source "amazon-ebs" "dev" {
source_ami_filter {
filters = {
virtualization-type = "hvm"
name = "udev-2110*"
root-device-type = "ebs"
}
owners = ["self"]
most_recent = true
}
launch_block_device_mappings {
delete_on_termination = true
device_name = "/dev/sda1"
encrypted = false
volume_size = 16
volume_type = "gp2"
}
ami_name = "prometheus"
ami_virtualization_type = "hvm"
ena_support = true
encrypt_boot = false
force_deregister = true
force_delete_snapshot = true
instance_type = "m5.large"
ami_description = "prometheus"
region = var.region
ssh_username = "ubuntu"
user_data_file = "prometheus/cloudconfig.yml"
tags = {
OS_Version = "Ubuntu"
Release = "Latest"
Base_AMI_Name = "{{ .SourceAMIName }}"
Name = "Prometheus Server"
}
}
source "googlecompute" "dev" {
project_id = var.project
source_image_family = "ubuntu-dev"
ssh_username = "ubuntu"
preemptible = true
zone = var.zone
image_storage_locations = [split("-", var.region)[0]]
machine_type = "n1-standard-1"
image_family = "prometheus"
metadata_files = {
user-data = "prometheus/cloudconfig.yml"
}
wrap_startup_script = false
image_name = "prometheus-${local.timestamp}"
// service_account_email = local.gservice_account_id
scopes = [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.full_control",
]
image_labels = {
type = "custom"
}
}
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
wait_script = <<EOT
while [ ! -f /var/lib/cloud/instance/boot-finished ]
do echo 'Waiting for cloud-init...'
sleep 10
done
EOT
}
build {
sources = ["sources.googlecompute.dev", "sources.amazon-ebs.dev", ]
provisioner "shell-local" {
inline = [
"echo 'Running source ${source.type}'",
]
}
provisioner "shell" {
inline = [
local.wait_script,
"echo finished",
]
expect_disconnect = false
}
provisioner "file" {
sources = ["prometheus/prometheus.service", "prometheus/prometheus.yml"]
destination = "/tmp/"
}
provisioner "shell" {
execute_command = "sudo env {{ .Vars }} {{ .Path }}"
inline = [
"mv /tmp/prometheus.service /etc/systemd/system/",
"mv /tmp/prometheus.yml /etc/prometheus/"
]
inline_shebang = "/bin/bash -ex"
}
}