forked from cloudtalents/fictitious-startup-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2-instance.pkr.hcl
79 lines (70 loc) · 1.64 KB
/
ec2-instance.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
packer {
required_plugins {
amazon = {
version = ">= 1.3.3"
source = "github.com/hashicorp/amazon"
}
}
required_plugins {
amazon-ami-management = {
version = ">= 1.6.1"
source = "github.com/wata727/amazon-ami-management"
}
}
}
variable version {}
variable vpc_id {}
variable subnet_id {}
locals {
ami_name = "cloudtalents-fictitious-startup"
source_ami_name = "ubuntu/images/*ubuntu-jammy-22.04-amd64-server*"
source_ami_owner = ["099720109477"]
ssh_username = "ubuntu"
region = "eu-west-1"
}
source "amazon-ebs" "ubuntu" {
ami_name = "${local.ami_name}-${var.version}"
instance_type = "t2.micro"
region = local.region
tags = {
Amazon_AMI_Management_Identifier = local.ami_name
}
source_ami_filter {
filters = {
name = local.source_ami_name
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["099720109477"]
}
ssh_username = local.ssh_username
vpc_id = var.vpc_id
subnet_id = var.subnet_id
associate_public_ip_address = true
}
build {
name = "custom_ami_cloudtalents"
sources = ["source.amazon-ebs.ubuntu"]
provisioner "file" {
source = "./"
destination = "/tmp"
}
provisioner "shell" {
inline = [
"echo creating directory",
"sudo mkdir /opt/app",
"echo move files into directory",
"sudo mv /tmp/* /opt/app",
"sudo chmod +x /opt/app/setup.sh"
]
}
provisioner "shell" {
script = "setup.sh"
}
post-processor "amazon-ami-management" {
regions = ["eu-west-1"]
identifier = local.ami_name
keep_releases = 2
}
}