-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
125 lines (97 loc) · 2.97 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
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
124
// Backend
variable "env" {
default = "dev"
}
variable "ami_id" {
default = "ami-02df9ea15c1778c9c"
}
terraform {
backend "s3" {
bucket = "gkaskonas-terraform-state"
key = "rocketchat_state.tfstate"
region = "eu-west-1"
}
}
provider "aws" {
profile = "default"
region = "eu-west-1"
}
variable "number_of_instances" {
description = "Number of instances to create and attach to alb"
default = 2
}
data "aws_vpc" "default" {
default = true
}
data "aws_subnet_ids" "all" {
vpc_id = "${data.aws_vpc.default.id}"
}
resource "aws_route53_zone" "primary" {
name = "example.co.uk"
}
resource "aws_route53_record" "rocketchat" {
zone_id = "${aws_route53_zone.primary.zone_id}"
name = "rocketchat.example.co.uk"
type = "A"
alias {
name = "${module.cdn.domain_name}"
zone_id = "${module.cdn.hosted_zone_id}"
evaluate_target_health = true
}
}
module "cdn" {
source = "./modules/cdn/"
domain_name = "${module.alb.dns_name}"
}
module "alb" {
source = "./modules/alb/"
number_of_instances = "${var.number_of_instances}"
instance_ids = "${module.rocketchat.id}"
vpc_id = "${data.aws_vpc.default.id}"
sg_id = ["${module.security_group.rocketchat_sg_id}"]
subnet_ids = "${data.aws_subnet_ids.all.ids}"
}
module "security_group" {
source = "./modules/security_group"
vpc_id = "${data.aws_vpc.default.id}"
}
module "efs" {
source = "./modules/efs"
subnet = element(tolist(data.aws_subnet_ids.all.ids), 0)
sg = "${module.security_group.efs_sg_id}"
}
module "mongo_db" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 2.0"
instance_count = "${var.number_of_instances}"
name = "mongodb"
ami = "${var.ami_id}"
instance_type = "t2.micro"
vpc_security_group_ids = ["${module.security_group.mongodb_sg_id}"]
subnet_id = element(tolist(data.aws_subnet_ids.all.ids), 0)
associate_public_ip_address = true
user_data = "${file("scripts/install_mongo")}"
key_name = "rocketchat"
}
module "rocketchat" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 2.0"
instance_count = "${var.number_of_instances}"
name = "rocketchat"
ami = "${var.ami_id}"
instance_type = "t2.micro"
vpc_security_group_ids = ["${module.security_group.rocketchat_sg_id}"]
subnet_id = element(tolist(data.aws_subnet_ids.all.ids), 0)
associate_public_ip_address = true
user_data = "${file("scripts/install_rocketchat")}"
key_name = "rocketchat"
}
output "mongo_hosts" {
value = "${module.mongo_db.public_dns}"
}
output "rocketchat_hosts" {
value = "${module.rocketchat.public_ip}"
}
output "efs_dns" {
value = "${module.efs.efs_dns_name}"
}