-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
80 lines (63 loc) · 1.38 KB
/
main.tf
File metadata and controls
80 lines (63 loc) · 1.38 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
provider "aws" {
region = "eu-west-2"
}
resource "aws_instance" "dbserver" {
ami = "ami-03ac5a9b225e99b02"
instance_type = "t2.micro"
tags = {
"Name" = "DBServer"
}
}
resource "aws_instance" "webserver" {
ami = "ami-03ac5a9b225e99b02"
instance_type = "t2.micro"
security_groups = [aws_security_group.sg.name]
user_data = file("server_script.sh")
tags = {
"Name" = "WebServer"
}
}
resource "aws_eip" "EIP" {
instance = aws_instance.webserver.id
}
output "EIP" {
value = aws_eip.EIP.public_ip
}
output "PIP" {
value = aws_instance.dbserver.private_ip
}
variable "ingressrules" {
type = list(string)
default = [ 443,80 ]
}
variable "egressrules" {
type = list(string)
default = [ 443,80 ]
}
resource "aws_security_group" "sg" {
name = "ALLOW HTTPHTTPS"
dynamic "ingress" {
iterator = port
for_each = var.ingressrules
content{
cidr_blocks = [ "0.0.0.0/0" ]
description = "value"
from_port = port.value
ipv6_cidr_blocks = [ "0.0.0.0/0" ]
protocol = "TCP"
to_port = port.value
}
}
dynamic "egress" {
iterator = port
for_each = var.egressrules
content{
cidr_blocks = [ "0.0.0.0/0" ]
description = "value"
from_port = port.value
ipv6_cidr_blocks = [ "0.0.0.0/0" ]
protocol = "TCP"
to_port = port.value
}
}
}