-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.pkr.hcl
64 lines (59 loc) · 1.66 KB
/
ec2.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
########################################## PACKER BLOCK
packer {
required_plugins {
amazon = {
version = ">= 1.1.1"
source = "github.com/hashicorp/amazon"
}
}
}
########################################## DATA SOURCE BLOCK
# Dynamic AMI data source
data "amazon-ami" "ami" {
filters = {
virtualization-type = "hvm"
root-device-type = "ebs"
name = var.base_ami
}
owners = [var.ami_owner_id]
most_recent = true
region = var.region
}
########################################## SOURCE BLOCK
source "amazon-ebs" "linux" {
source_ami = data.amazon-ami.ami.id
ami_name = "${var.ami_name}-${local.timestamp}"
instance_type = var.instance_type
region = var.region
vpc_id = var.vpc_id
subnet_id = var.subnet_id
user_data_file = "script.sh"
communicator = "ssh" # this is a default so doesn't need to be specified (unless using windows which is winrm)
ssh_username = var.ssh_username
iam_instance_profile = var.instance_profile
ssh_interface = var.ssh_interface
run_tags = {
Name = "${var.ami_name}-${local.timestamp}"
Creator = "Packer"
}
run_volume_tags = {
Name = "${var.ami_name}-${local.timestamp}"
Creator = "Packer"
}
snapshot_tags = {
Name = "${var.ami_name}-${local.timestamp}"
Creator = "Packer"
}
tags = {
Name = "${var.ami_name}-${local.timestamp}"
Base_AMI_Name = "{{ .SourceAMIName}}"
Creator = "Packer"
}
}
########################################## BUILD BLOCK
build {
name = "${var.ami_name}-${local.timestamp}"
sources = [
"source.amazon-ebs.linux"
]
}