-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.tf
80 lines (75 loc) · 2.08 KB
/
ec2.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
data "aws_ami" "base_ami" {
owners = ["amazon"]
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
resource "aws_security_group" "instance_security_group" {
provider = aws.master_region
name = "instance_security_group"
vpc_id = aws_vpc.main.id
ingress {
description = "Public ingress on port 80"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
description = "Public egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_launch_template" "static_launch_template" {
provider = aws.master_region
name = "static_launch_template"
image_id = data.aws_ami.base_ami.image_id
instance_type = var.static_instance_type
iam_instance_profile {
arn = aws_iam_instance_profile.static_instance_profile.arn
}
network_interfaces {
security_groups = [aws_security_group.instance_security_group.id]
associate_public_ip_address = true
delete_on_termination =true
}
user_data = filebase64("webconfig/user-data-static.sh")
metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
instance_metadata_tags = "enabled"
}
}
resource "aws_launch_template" "load_balancer_launch_template" {
provider = aws.master_region
name = "load_balancer_launch_template"
image_id = data.aws_ami.base_ami.image_id
instance_type = var.load_balancer_instance_type
iam_instance_profile {
arn = aws_iam_instance_profile.load_balancer_instance_profile.arn
}
network_interfaces {
security_groups = [aws_security_group.instance_security_group.id]
associate_public_ip_address = true
delete_on_termination =true
}
user_data = filebase64("webconfig/user-data-lb.sh")
metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
instance_metadata_tags = "enabled"
}
}