-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathweb.tf
More file actions
123 lines (106 loc) · 3.18 KB
/
web.tf
File metadata and controls
123 lines (106 loc) · 3.18 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#Deploy Wordpress instances
#Reference to bash script which prepares xenial image
data "template_file" "wpdeploy"{
template = "${file("./webconfig.cfg")}"
vars = {
db_ip = "${aws_db_instance.wpdb.address}"
db_user = "${var.db_user}"
db_password = "${var.db_password}"
}
}
data "template_cloudinit_config" "wpdeploy_config" {
gzip = false
base64_encode = false
part {
filename = "webconfig.cfg"
content_type = "text/cloud-config"
content = "${data.template_file.wpdeploy.rendered}"
}
}
resource "aws_instance" "web-server" {
ami = "${var.web_ami}"
# The public SG is added for SSH and ICMP
vpc_security_group_ids = ["${aws_security_group.web-sec.id}", "${aws_security_group.allout.id}"]
instance_type = "${var.web_instance_type}"
# Attaching to first web subnet for now, until NLB target group issue can be resolved
subnet_id = "${aws_subnet.web_subnet1.id}"
# my private key for testing
#key_name = "win3_aws"
tags = {
Name = "AZ 1 web-server-${count.index}"
}
count = "${var.web_number}"
depends_on = ["aws_db_instance.wpdb"]
user_data = "${data.template_cloudinit_config.wpdeploy_config.rendered}"
}
/* Having issues implementing this, will explore later
resource "aws_instance" "web-server2" {
ami = "${var.web_ami}"
# The public SG is added for SSH and ICMP
vpc_security_group_ids = ["${aws_security_group.web-sec.id}", "${aws_security_group.allout.id}"]
instance_type = "${var.web_instance_type}"
subnet_id = "${aws_subnet.web_subnet2.id}"
# my private key for testing
key_name = "win3_aws"
tags = {
Name = "AZ 2 web-server-${count.index}"
}
count = "${var.web_number1}"
depends_on = ["aws_db_instance.wpdb"]
#user_data = "${data.template_file.wpdeploy.rendered}"
user_data = "${data.template_cloudinit_config.wpdeploy_config.rendered}"
}
*/
# bastion server
/*
resource "aws_instance" "bastion" {
ami = "${var.web_ami}"
# The public SG is added for SSH and ICMP
vpc_security_group_ids = ["${aws_security_group.web-sec.id}", "${aws_security_group.allout.id}"]
instance_type = "${var.web_instance_type}"
subnet_id = "${aws_subnet.pub_subnet1.id}"
# my private key for testing
#key_name = "win3_aws"
#get public ip
associate_public_ip_address = true
depends_on = ["aws_db_instance.wpdb"]
#user_data = "${data.template_file.wpdeploy.rendered}"
}
*/
resource "aws_security_group" "web-sec" {
name = "webserver-secgroup"
vpc_id = "${aws_vpc.app_vpc.id}"
# Internal HTTP access from anywhere
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
#ssh from anywhere (unnecessary)
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# ping access from anywhere
ingress {
from_port = 8
to_port = 0
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
}
#public access sg
# allow all egress traffic (needed for server to download packages)
resource "aws_security_group" "allout" {
name = "allout-secgroup"
vpc_id = "${aws_vpc.app_vpc.id}"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}