-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitlab.tf
104 lines (92 loc) · 3.99 KB
/
gitlab.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
data "template_file" "userdata" {
template = "${file("${path.module}/templates/userdata-rhel.tpl")}"
vars {
fs_id = "${module.efs_mount.file_system_id}"
region = "${data.aws_region.current.name}"
db_database = "${var.db_database}"
db_username = "${var.db_username}"
db_password = "${var.db_password}"
db_host = "${module.postgresql_rds.endpoint}"
db_port = "${var.db_port}"
redis_host = "${module.redis.endpoint}"
redis_port = "${var.redis_port}"
mount_point = "${var.mount_point}"
external_url = "${aws_elb.gtilab.dns_name}"
}
}
data "aws_region" "current" {
current = true
}
resource "aws_sns_topic" "gitlab_pgsql_threshold" {
name = "gitlab-pgsql-threshold-topic"
}
module "postgresql_rds" {
source = "github.com/azavea/terraform-aws-postgresql-rds"
vpc_id = "${var.vpc_id}"
allocated_storage = "50"
engine_version = "9.6.2"
instance_type = "db.t2.medium"
storage_type = "gp2"
database_identifier = "${var.project}-pgsql"
database_name = "${var.db_database}"
database_username = "${var.db_username}"
database_password = "${var.db_password}"
database_port = "${var.db_port}"
backup_retention_period = "30"
backup_window = "04:00-04:30"
maintenance_window = "sun:04:30-sun:05:30"
auto_minor_version_upgrade = false
multi_availability_zone = true
storage_encrypted = false
subnet_group = "${aws_db_subnet_group.gitlab_pgsql.name}"
parameter_group = "${aws_db_parameter_group.gitlab_pgsql.name}"
alarm_cpu_threshold = "75"
alarm_disk_queue_threshold = "10"
alarm_free_disk_threshold = "5000000000"
alarm_free_memory_threshold = "128000000"
alarm_actions = ["${aws_sns_topic.gitlab_pgsql_threshold.arn}"]
project = "${var.project}"
environment = "${var.env}"
}
module "efs_mount" {
source = "github.com/BigAl/tf_efs_mount"
name = "gitlab-nfs"
subnets = "${var.data_subnets}"
vpc_id = "${var.vpc_id}"
}
module "redis" {
source = "github.com/BigAl/tf_aws_elasticache_redis?ref=aviod_count_compute"
env = "${var.env}"
name = "${var.project}"
redis_clusters = "2"
redis_failover = "true"
subnets = "${var.data_subnet_list}"
vpc_id = "${var.vpc_id}"
allowed_security_groups = ["${aws_security_group.instance.id}"]
}
module "gitlab_asg" {
source = "github.com/BigAl/tf_aws_asg_elb"
lc_name = "${var.lc_name}"
ami_id = "${var.ami_id}"
instance_type = "${var.instance_type}"
iam_instance_profile = "${aws_iam_instance_profile.app_profile.id}"
key_name = "${var.key_name}"
security_groups = ["${aws_security_group.instance.id}", "${module.efs_mount.ec2_security_group_id}"]
user_data = "${data.template_file.userdata.rendered}"
asg_name = "${var.asg_name}"
asg_number_of_instances = "${var.asg_number_of_instances}"
asg_minimum_number_of_instances = "${var.asg_minimum_number_of_instances}"
load_balancer_names = "${aws_elb.gtilab.name}"
health_check_type = "${var.health_check_type}"
availability_zones = "${var.availability_zones}"
vpc_zone_subnets = "${var.private_subnets}"
}
# Add EC2 security group to database_security_group_id
resource "aws_security_group_rule" "PostgresIngress200" {
type = "ingress"
from_port = 5432
to_port = 5432
protocol = "tcp"
security_group_id = "${module.postgresql_rds.database_security_group_id}"
source_security_group_id = "${aws_security_group.instance.id}"
}