-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
62 lines (53 loc) · 1.65 KB
/
main.tf
File metadata and controls
62 lines (53 loc) · 1.65 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
resource "random_shuffle" "subnets" {
input = var.subnets
result_count = var.instance_count
}
resource "aws_key_pair" "ssh" {
key_name = "${var.name_prefix}-ssh-key"
public_key = var.ssh_public_key
}
resource "aws_instance" "code_runner" {
ami = data.aws_ami.debian.id
instance_type = var.instance_type
key_name = aws_key_pair.ssh.key_name
vpc_security_group_ids = var.security_groups
subnet_id = random_shuffle.subnets.result[count.index]
count = var.instance_count
root_block_device {
volume_type = "gp3"
volume_size = var.instance_root_device_size
delete_on_termination = true
}
tags = merge(
{
Name = "${var.name_prefix}-${count.index + 1}"
ManagedBy = "terraform"
},
var.tags
)
}
resource "aws_eip" "eip" {
count = (var.create_elastic_ip) ? var.instance_count : 0
tags = merge(
{
Name = "${var.name_prefix}-address-${count.index + 1}"
ManagedBy = "terraform"
},
var.tags
)
}
resource "aws_eip_association" "eip_assoc" {
count = (var.create_elastic_ip) ? var.instance_count : 0
instance_id = aws_instance.code_runner[count.index].id
allocation_id = aws_eip.eip[count.index].id
}
resource "cloudflare_record" "website" {
count = (var.website_domain != "" && var.cloudflare_zone_id != "") ? 1 : 0
zone_id = var.cloudflare_zone_id
name = var.website_domain
value = aws_eip.eip[0].public_ip
type = "A"
proxied = true
allow_overwrite = true
comment = "Managed by terraform"
}