-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathaws_packer.hcl
More file actions
79 lines (73 loc) · 2.49 KB
/
aws_packer.hcl
File metadata and controls
79 lines (73 loc) · 2.49 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
packer {
required_version = "1.7.9"
required_plugins {
amazon = {
version = "1.0.0"
source = "github.com/hashicorp/amazon"
}
}
}
locals {
ami_base_name = "aws-test"
aws_region = "us-east-1"
subnet_id = "subnet-07910a"
temporary_security_group_source_cidrs = ["172.4.0.0/16"]
associate_public_ip_address = true
ssh_interface = "private_ip"
ebs_volume_size = "10"
timestamp = formatdate("YYYYMMDDhhmm", timeadd(timestamp(), "8h"))
ansible_vault_password_file = "script.sh"
}
variable "environment" {
type = string
}
source "amazon-ebs" "aws-test {
ami_name = "${local.ami_base_name}-${local.timestamp}"
ami_description = "Standard Amazon Linux 2"
instance_type = "t2.xlarge"
region = "${local.aws_region}"
subnet_id = "${local.subnet_id}"
associate_public_ip_address = "${local.associate_public_ip_address}"
ssh_interface = "${local.ssh_interface}"
temporary_security_group_source_cidrs = "${local.temporary_security_group_source_cidrs}"
source_ami_filter {
filters = {
name = "*Build_AML_2_*"
architecture = "x86_64"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["272677"]
}
ami_block_device_mappings {
device_name = "/dev/xvda"
volume_size = "${local.ebs_volume_size}"
volume_type = "gp2"
delete_on_termination = true
}
launch_block_device_mappings {
device_name = "/dev/xvda"
volume_size = "${local.ebs_volume_size}"
volume_type = "gp2"
delete_on_termination = true
}
ssh_username = "ec2-user"
tags = {
Name = "${local.ami_base_name}-${local.timestamp}"
Base_Name = "${local.ami_base_name}"
Timestamp = "${local.timestamp}"
Packer = "yes"
}
run_tags = {
Name = "${local.ami_base_name}-${local.timestamp}-packer"
}
}
build {
name = "aws-test-ami"
sources = ["amazon-ebs.aws-test"]
provisioner "ansible" {
playbook_file = "./playbook.yml"
extra_arguments = ["-e", "environment=var.environment","--vault-password-file", "${local.ansible_vault_password_file}"]
}
}