Skip to content

Commit 172a2db

Browse files
committed
reorganize into terraform modules
1 parent c92a7f1 commit 172a2db

32 files changed

+850
-483
lines changed

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/packer/config.json
2-
/terraform/terraform.tfvars
3-
/terraform/terraform.tfstate
4-
/terraform/terraform.tfstate.backup
5-
/tmp_ssh_host_keys
6-
/terraform/ssh_host_keys.tar.gz
2+
terraform.tfvars
3+
terraform.tfstate
4+
terraform.tfstate.backup
5+
/terraform/gitlab/ssh_host_keys.tar.gz
6+
.terraform/
77
.terraform.tfstate.lock.info
8+
/graphs

Makefile

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SHELL := $(shell which bash)
33
ENV = /usr/bin/env
44
# default shell options
55
.SHELLFLAGS = -c
6-
6+
format = png
77
.SILENT: ; # no need for @
88
.ONESHELL: ; # recipes execute in same shell
99
.NOTPARALLEL: ; # wait for this target to finish
@@ -19,15 +19,15 @@ all:
1919
# prevent ssh client warnings about ssh host keys to be different
2020
# between SSH load balancer
2121
ssh_host_keys:
22-
if [ ! -f terraform/ssh_host_keys.tar.gz ]; then \
22+
if [ ! -f terraform/gitlab/ssh_host_keys.tar.gz ]; then \
2323
rm -rf tmp_ssh_host_keys ;\
2424
mkdir -p tmp_ssh_host_keys ;\
2525
cd tmp_ssh_host_keys ;\
2626
ssh-keygen -q -t dsa -N "" -f ssh_host_dsa_key -C "root@gitlab" ;\
2727
ssh-keygen -q -t rsa -N "" -f ssh_host_rsa_key -C "root@gitlab" ;\
2828
ssh-keygen -q -t ecdsa -N "" -f ssh_host_ecdsa_key -C "root@gitlab" ;\
2929
ssh-keygen -q -t ed25519 -N "" -f ssh_host_ed25519_key -C "root@gitlab" ;\
30-
tar -cvzf ../terraform/ssh_host_keys.tar.gz ssh_host_* ;\
30+
tar -cvzf ../terraform/gitlab/ssh_host_keys.tar.gz ssh_host_* ;\
3131
fi;
3232

3333
config: ssh_host_keys
@@ -44,18 +44,37 @@ ami-runner: config
4444
cd packer
4545
packer build -var-file=config.json gitlab-ci-runner.json
4646

47-
plan: config
47+
_get_modules: config
48+
cd terraform
49+
terraform get
50+
51+
plan: _get_modules
4852
cd terraform
4953
terraform plan
5054

51-
apply: config
55+
apply: _get_modules
5256
cd terraform
5357
terraform apply
5458

55-
output: config
59+
output: _get_modules
5660
cd terraform
5761
terraform output
5862

59-
destroy: config
63+
_graph_dir: _get_modules
64+
mkdir -p graphs
65+
66+
_graph:
67+
cd terraform
68+
terraform graph -type=$(type) -draw-cycles | dot -T$(format) > ../graphs/infra_$(type).$(format)
69+
70+
graphs: _graph_dir
71+
make _graph type=plan format=$(format)
72+
make _graph type=plan-destroy format=$(format)
73+
make _graph type=apply format=$(format)
74+
make _graph type=validate format=$(format)
75+
make _graph type=input format=$(format)
76+
make _graph type=refresh format=$(format)
77+
78+
destroy: _get_modules
6079
cd terraform
6180
terraform destroy

terraform/data.tf

Lines changed: 0 additions & 174 deletions
This file was deleted.

terraform/gitlab/cache.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
resource "aws_elasticache_subnet_group" "gitlab_cache" {
2+
name = "gitlab-cache-subnet"
3+
subnet_ids = ["${var.private_subnet_ids["private1"]}", "${var.private_subnet_ids["private2"]}"]
4+
}
5+
6+
resource "aws_elasticache_cluster" "gitlab_cache" {
7+
cluster_id = "gitlab-cache"
8+
engine = "redis"
9+
engine_version = "3.2.4"
10+
node_type = "cache.t2.small"
11+
port = 6379
12+
num_cache_nodes = 1
13+
parameter_group_name = "default.redis3.2"
14+
subnet_group_name = "${aws_elasticache_subnet_group.gitlab_cache.name}"
15+
security_group_ids = ["${aws_security_group.gitlab_cache.id}"]
16+
}
17+
18+
resource "aws_security_group" "gitlab_cache" {
19+
name = "gitlab-cache"
20+
description = "Allow traffic to gitlab cache"
21+
vpc_id = "${var.vpc_id}"
22+
23+
ingress {
24+
from_port = 6379
25+
to_port = 6379
26+
protocol = "TCP"
27+
security_groups = ["${aws_security_group.gitlab.id}"]
28+
}
29+
}

terraform/config/gitlab.rb.j2 renamed to terraform/gitlab/config/gitlab.rb.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ user['username'] = "git"
3434
user['group'] = "git"
3535
user['uid'] = 998
3636
user['gid'] = 998
37+
38+
nginx['real_ip_trusted_addresses'] = [ '{{ gitlab_proxy_subnets|join('\', \'') }}' ]
39+
nginx['real_ip_header'] = 'X-Real-IP'
40+
nginx['real_ip_recursive'] = 'on'
File renamed without changes.
File renamed without changes.

terraform/config/gitlab_env.yml renamed to terraform/gitlab/config/gitlab_env.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ gitlab_db_host: "${gitlab_db_host}"
1111
gitlab_db_port: ${gitlab_db_port}
1212
gitlab_cache_host: "${gitlab_cache_host}"
1313
gitlab_cache_port: ${gitlab_cache_port}
14+
gitlab_proxy_subnets: ["${join('", "', gitlab_proxy_subnets)}"]

terraform/gitlab/db.tf

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
resource "aws_security_group" "db_allow" {
2+
name = "db_allow"
3+
description = "Allow inbound traffic to databases"
4+
vpc_id = "${var.vpc_id}"
5+
6+
ingress {
7+
from_port = 5432
8+
to_port = 5432
9+
protocol = "TCP"
10+
security_groups = ["${aws_security_group.gitlab.id}"]
11+
}
12+
}
13+
14+
resource "aws_db_subnet_group" "gitlab_db_sg" {
15+
name = "gitlab-db"
16+
subnet_ids = ["${var.private_subnet_ids["private1"]}", "${var.private_subnet_ids["private2"]}"]
17+
18+
tags {
19+
Name = "Gitlab DB subnet group"
20+
}
21+
}
22+
23+
resource "aws_db_parameter_group" "pg_default" {
24+
name = "gitlab-postgres-pg"
25+
family = "postgres9.5"
26+
27+
parameter {
28+
name = "client_encoding"
29+
value = "utf8"
30+
}
31+
}
32+
33+
resource "aws_db_instance" "gitlab" {
34+
allocated_storage = 10
35+
engine = "postgres"
36+
engine_version = "9.5.4"
37+
license_model = "postgresql-license"
38+
instance_class = "db.t2.micro"
39+
name = "${var.gitlab_db_name}"
40+
username = "${var.gitlab_db_username}"
41+
password = "${var.gitlab_db_password}"
42+
db_subnet_group_name = "${aws_db_subnet_group.gitlab_db_sg.name}"
43+
vpc_security_group_ids = ["${aws_security_group.db_allow.id}"]
44+
// parameter_group_name = "default.postgres9.5"
45+
parameter_group_name = "${aws_db_parameter_group.pg_default.name}"
46+
storage_type = "gp2"
47+
publicly_accessible = true
48+
final_snapshot_identifier = "gitlab-db"
49+
skip_final_snapshot = true
50+
copy_tags_to_snapshot = true
51+
backup_retention_period = 1
52+
apply_immediately = true
53+
multi_az = false
54+
}

terraform/gitlab/dns.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "aws_route53_record" "gitlab" {
2+
zone_id = "${var.dns_zone_id}"
3+
name = "${var.gitlab_dns_subdomain}.${var.dns_zone_name}"
4+
type = "A"
5+
6+
alias {
7+
name = "${aws_elb.gitlab.dns_name}"
8+
zone_id = "${aws_elb.gitlab.zone_id}"
9+
evaluate_target_health = true
10+
}
11+
}

0 commit comments

Comments
 (0)