-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path7.bastian-host.tf
76 lines (58 loc) · 1.49 KB
/
7.bastian-host.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
data "aws_ami" "amazon_linux_2" {
most_recent = true
owners = ["amazon"]
filter {
name = "architecture"
values = ["arm64"]
}
}
resource "aws_instance" "bastian_host" {
subnet_id = aws_subnet.public_subnet.id
vpc_security_group_ids = [
aws_security_group.bastian_host.id
]
ami = data.aws_ami.amazon_linux_2.image_id
instance_type = "t4g.small"
root_block_device {
volume_size = 25
}
key_name = aws_key_pair.this.key_name
provisioner "file" {
when = create
on_failure = fail
connection {
host = aws_instance.bastian_host.public_ip
user = "ubuntu"
private_key = tls_private_key.this.private_key_pem
}
content = tls_private_key.this.private_key_pem
destination = "/home/ubuntu/private-key.pem"
}
lifecycle {
ignore_changes = [
ami,
user_data,
associate_public_ip_address
]
}
}
resource "aws_security_group" "bastian_host" {
name_prefix = "bastian-host"
vpc_id = aws_vpc.this.id
// In production scenarios, the Bastian Host can be accessed, only from the IPs that you've
// allowed. But for simplicity, I am keeping it accessible from anywhere.
ingress {
description = "Allow access from anywhere"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
description = "Allow all outbound traffic"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}