-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.tf
97 lines (89 loc) · 2.77 KB
/
main.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
data "aws_subnet" "main" {
id = var.subnet_id
}
# NGINX Plus agent instance(s)
resource "aws_instance" "nginx_plus_agent" {
count = var.nginx_plus_agent_count
ami = var.ami_id
instance_type = var.instance_type
key_name = var.key_name
associate_public_ip_address = true
vpc_security_group_ids = [
aws_security_group.nginx_plus_agent.id,
]
subnet_id = var.subnet_id
tags = {
Name = var.name_prefix != "" ? "${var.name_prefix}_nginx_plus_agent" : "nginx_plus_agent"
Owner = var.owner != "" ? var.owner : "Terraform"
}
}
# Create AWS security group for NGINX Controller agent instances
resource "aws_security_group" "nginx_plus_agent" {
name = var.name_prefix != "" ? "${var.name_prefix}_nginx_plus_agent_sg" : "nginx_plus_agent_sg"
description = "Security group for NGINX Plus agent instance"
vpc_id = data.aws_subnet.main.vpc_id
tags = {
Name = var.name_prefix != "" ? "${var.name_prefix}_nginx_plus_agent_sg" : "nginx_plus_agent_sg"
Owner = var.owner != "" ? var.owner : "Terraform"
}
}
resource "aws_security_group_rule" "nginx_plus_agent_ingress_ssh" {
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
security_group_id = aws_security_group.nginx_plus_agent.id
cidr_blocks = [
"0.0.0.0/0",
]
}
resource "aws_security_group_rule" "nginx_plus_agent_ingress_http" {
type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
security_group_id = aws_security_group.nginx_plus_agent.id
cidr_blocks = [
"0.0.0.0/0",
]
}
resource "aws_security_group_rule" "nginx_plus_agent_ingress_https" {
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
security_group_id = aws_security_group.nginx_plus_agent.id
cidr_blocks = [
"0.0.0.0/0",
]
}
resource "aws_security_group_rule" "nginx_plus_agent_egress_http" {
type = "egress"
from_port = 80
to_port = 80
protocol = "tcp"
security_group_id = aws_security_group.nginx_plus_agent.id
cidr_blocks = [
"0.0.0.0/0",
]
}
resource "aws_security_group_rule" "nginx_plus_agent_egress_https" {
type = "egress"
from_port = 443
to_port = 443
protocol = "tcp"
security_group_id = aws_security_group.nginx_plus_agent.id
cidr_blocks = [
"0.0.0.0/0",
]
}
resource "aws_security_group_rule" "nginx_plus_agent_egress_controller" {
type = "egress"
from_port = 8443
to_port = 8443
protocol = "tcp"
security_group_id = aws_security_group.nginx_plus_agent.id
cidr_blocks = [
"0.0.0.0/0",
]
}