forked from lizthegrey/pds-tf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws.tf
99 lines (83 loc) · 1.98 KB
/
aws.tf
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
resource "aws_launch_template" "pds" {
capacity_reservation_specification {
capacity_reservation_preference = "open"
}
cpu_options {
core_count = 2
threads_per_core = 1
}
ebs_optimized = true
instance_type = "t4g.small"
monitoring {
enabled = true
}
tag_specifications {
resource_type = "instance"
tags = {
Name = var.pds_hostname
}
}
metadata_options {
http_tokens = "required"
http_put_response_hop_limit = "1"
}
user_data = base64encode(templatefile("${path.module}/launch.sh", {
pds_hostname : var.pds_hostname,
pds_admin_email : var.pds_admin_email,
}))
}
resource "aws_key_pair" "pds_ssh_key" {
key_name = var.ssh_key_name
public_key = var.public_key
}
data "aws_ami" "ubuntu22" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-arm64-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
resource "aws_instance" "pds" {
availability_zone = var.az
key_name = aws_key_pair.pds_ssh_key.key_name
launch_template {
version = "$Latest"
id = aws_launch_template.pds.id
}
subnet_id = aws_subnet.pds_subnet.id
vpc_security_group_ids = [aws_security_group.pds_sg.id]
associate_public_ip_address = true
ipv6_address_count = 1
ami = data.aws_ami.ubuntu22.id
tags = {
Name = var.pds_hostname
}
lifecycle {
ignore_changes = [
user_data,
]
prevent_destroy = true
}
}
resource "aws_ebs_volume" "pds_datastore" {
availability_zone = var.az
size = var.ebs_volume_size
type = var.ebs_volume_type
final_snapshot = true
lifecycle {
prevent_destroy = true
}
tags = {
Snapshot = true
}
}
resource "aws_volume_attachment" "pds" {
device_name = "/dev/sdf"
volume_id = aws_ebs_volume.pds_datastore.id
instance_id = aws_instance.pds.id
}