-
Notifications
You must be signed in to change notification settings - Fork 8
/
aws-ubuntu.pkr.hcl
111 lines (99 loc) · 2.6 KB
/
aws-ubuntu.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
variable "ami_prefix" {
type = string
default = "cloud-testing-vm"
}
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
tags = {
Name = "Cloud Testing Image"
}
}
packer {
required_plugins {
amazon = {
source = "github.com/hashicorp/amazon"
version = ">= 1"
}
ansible = {
source = "github.com/hashicorp/ansible"
version = ">= 1"
}
}
}
source "amazon-ebs" "ubuntu" {
ami_name = "${var.ami_prefix}-${local.timestamp}"
instance_type = "t3.medium"
region = "eu-west-2"
source_ami_filter {
filters = {
name = "ubuntu/images/*/ubuntu-noble-24.04-amd64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["099720109477"]
}
ssh_username = "ubuntu"
run_volume_tags = local.tags
tags = local.tags
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = 50
volume_type = "gp2"
delete_on_termination = true
}
temporary_iam_instance_profile_policy_document {
Statement {
Effect = "Allow"
Action = [
"ssm:DescribeAssociation",
"ssm:GetDeployablePatchSnapshotForInstance",
"ssm:GetDocument",
"ssm:DescribeDocument",
"ssm:GetManifest",
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:ListAssociations",
"ssm:ListInstanceAssociations",
"ssm:PutInventory",
"ssm:PutComplianceItems",
"ssm:PutConfigurePackageResult",
"ssm:UpdateAssociationStatus",
"ssm:UpdateInstanceAssociationStatus",
"ssm:UpdateInstanceInformation",
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel",
"ec2messages:AcknowledgeMessage",
"ec2messages:DeleteMessage",
"ec2messages:FailMessage",
"ec2messages:GetEndpoint",
"ec2messages:GetMessages",
"ec2messages:SendReply"
]
Resource = ["*"]
}
Version = "2012-10-17"
}
# skip_create_ami = true
}
build {
name = "build-testing-vm"
sources = [
"source.amazon-ebs.ubuntu"
]
provisioner "ansible" {
playbook_file = "./playbook.yml"
extra_arguments = ["--scp-extra-args", "'-O'", "--ssh-extra-args", "-o IdentitiesOnly=yes -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa"]
}
provisioner "shell" {
environment_vars = [
"TEST=testing"
]
inline = [
"echo testing",
"echo $TEST",
]
}
}