-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamazon-ebs.pkr.hcl
78 lines (64 loc) · 1.63 KB
/
amazon-ebs.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
packer {
required_plugins {
amazon = {
version = ">= 1.2.2"
source = "github.com/hashicorp/amazon"
}
}
}
variable "kubernetes_version" {
type = string
description = "Kubernetes version"
}
variable "source_ami_id" {
type = string
default = null
description = "(Optional) Source AMI to use as a base"
}
variable "tags" {
type = map(string)
default = {}
description = "Additional tags to add to the created AMI"
}
locals {
default_tags = {
Generated_By = "xrd-packer"
Kubernetes_Version = var.kubernetes_version
Base_AMI_ID = "{{ .SourceAMI }}"
Base_AMI_Name = "{{ .SourceAMIName }}"
}
}
source "amazon-ebs" "base" {
ami_name = format("xrd-%s-{{timestamp}}", var.kubernetes_version)
instance_type = "m5.xlarge"
ssh_username = "ec2-user"
source_ami = var.source_ami_id
source_ami_filter {
most_recent = true
owners = ["amazon"]
filters = {
name = format("amazon-eks-node-%s-*", var.kubernetes_version)
root-device-type = "ebs"
virtualization-type = "hvm"
}
}
tags = merge(local.default_tags, var.tags)
}
locals {
assets_dir = "/tmp/worker"
}
build {
sources = ["source.amazon-ebs.base"]
provisioner "shell" {
inline = [format("mkdir -p %s", local.assets_dir)]
}
provisioner "file" {
source = "${path.root}/files/"
destination = local.assets_dir
}
provisioner "shell" {
env = { "ASSETS_DIR" : local.assets_dir }
execute_command = "sudo sh -c \"{{ .Vars }} {{ .Path }}\""
script = "${path.root}/install.sh"
}
}