Skip to content

Commit 925ae10

Browse files
committed
Improve README and config files
1 parent 4d57b4d commit 925ae10

File tree

9 files changed

+115
-18
lines changed

9 files changed

+115
-18
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ trim_trailing_whitespace = true
99
insert_final_newline = true
1010

1111
[*.md]
12+
indent_size = 2
1213
trim_trailing_whitespace = false
1314

1415
[*.yml]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ terraform.tfvars
33
terraform.tfstate
44
terraform.tfstate.backup
55
/terraform/gitlab/ssh_host_keys.tar.gz
6+
/tmp_ssh_host_keys
67
.terraform/
78
.terraform.tfstate.lock.info
89
/graphs

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SHELL := $(shell which bash)
33
ENV = /usr/bin/env
44
# default shell options
55
.SHELLFLAGS = -c
6+
SSH_KEY_COMMENT = "root@gitlab"
67
format = png
78
.SILENT: ; # no need for @
89
.ONESHELL: ; # recipes execute in same shell
@@ -20,15 +21,17 @@ all:
2021
# between SSH load balancer
2122
ssh_host_keys:
2223
if [ ! -f terraform/gitlab/ssh_host_keys.tar.gz ]; then \
23-
echo "generating Gitlab ssh host keys" \
24+
echo "generating Gitlab ssh host keys";\
2425
rm -rf tmp_ssh_host_keys ;\
2526
mkdir -p tmp_ssh_host_keys ;\
2627
cd tmp_ssh_host_keys ;\
27-
ssh-keygen -q -t dsa -N "" -f ssh_host_dsa_key -C "root@gitlab" ;\
28-
ssh-keygen -q -t rsa -N "" -f ssh_host_rsa_key -C "root@gitlab" ;\
29-
ssh-keygen -q -t ecdsa -N "" -f ssh_host_ecdsa_key -C "root@gitlab" ;\
30-
ssh-keygen -q -t ed25519 -N "" -f ssh_host_ed25519_key -C "root@gitlab" ;\
28+
ssh-keygen -q -t dsa -N "" -f ssh_host_dsa_key -C $(SSH_KEY_COMMENT) ;\
29+
ssh-keygen -q -t rsa -N "" -f ssh_host_rsa_key -C $(SSH_KEY_COMMENT) ;\
30+
ssh-keygen -q -t ecdsa -N "" -f ssh_host_ecdsa_key -C $(SSH_KEY_COMMENT) ;\
31+
ssh-keygen -q -t ed25519 -N "" -f ssh_host_ed25519_key -C $(SSH_KEY_COMMENT) ;\
3132
tar -cvzf ../terraform/gitlab/ssh_host_keys.tar.gz ssh_host_* ;\
33+
cd .. ;\
34+
rm -rf tmp_ssh_host_keys ;\
3235
fi;
3336

3437
config: ssh_host_keys
@@ -79,6 +82,7 @@ graphs: _graph_dir
7982
make _graph type=validate format=$(format)
8083
make _graph type=input format=$(format)
8184
make _graph type=refresh format=$(format)
85+
echo "Graphs exported to graphs directory"
8286

8387
destroy: _get_modules
8488
cd terraform

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,75 @@ Requirements
1818
------------
1919

2020
* a [AWS account](https://aws.amazon.com/) (**Be careful this template implies creating billable resources on AWS cloud**)
21+
22+
You will need an [AWS access key](http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html) and enough admin permissions to create AWS ressources
2123
* a [AWS Route 53 DNS zone](http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Welcome.html) already created (the template will add new subdomain DNS A records)
2224
* a SSH Key pair to connect to Gitlab and AWS instances (see [Github help for examples](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/))
2325
* [Packer](https://www.packer.io/) >= 0.12
2426
* [Terraform](https://www.terraform.io/) >= 8.2
2527
* GNU Make or some Unix equivalent Implementation
28+
* *(optional)* [Graphiz](http://www.graphviz.org/) to generate Terraform config Graph Images
29+
```sh
30+
# on ubuntu/debian
31+
sudo apt-get install graphviz
32+
```
33+
34+
35+
Usage
36+
-----
37+
38+
### To create the Gitlab infrastructure
39+
40+
1. Copy and edit the configuration files :
41+
42+
* **terraform** : `terraform/terraform.dist.tvars` to `terraform/terraform.tvars`
43+
* **packer** : `packer/config.dist.json` to `packer/config.json`
44+
45+
2. create Amazon Machine Images :
46+
47+
* Gitlab
48+
* Gitlab-CI-multirunner
49+
50+
```sh
51+
make ami
52+
```
53+
54+
3. check Terraform plan
55+
56+
```sh
57+
make plan
58+
```
59+
60+
3. if terraform plan is correct, create AWS resources by applying the terraform plan
61+
62+
```sh
63+
make apply
64+
```
65+
66+
* you can check again the terraform exported variables output
67+
```sh
68+
make output
69+
```
70+
* you can also get Graphviz graphs of all terraform config
71+
```sh
72+
# in PNG image format
73+
make graphs
74+
# or in SVG
75+
make graphs format=svg
76+
```
77+
78+
After creation, wait for a few minutes the autoscaled gitlab instances finish self initialization.
79+
80+
if variables are set in `packer/config.json` like :
81+
```
82+
aws_dns_zone = "my-aws.net"
83+
gitlab_dns_subdomain = "gitlab"
84+
```
85+
86+
The Gitlab server should be available to http://gitlab.my-aws.net/
87+
88+
### To destroy the Gitlab infrastructure
89+
90+
```sh
91+
make destroy
92+
```

terraform/global/dns.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ data "aws_route53_zone" "selected" {
44

55
resource "aws_route53_record" "bastion1" {
66
zone_id = "${data.aws_route53_zone.selected.zone_id}"
7-
name = "bastion1.${data.aws_route53_zone.selected.name}"
7+
name = "${var.bastion_dns_subdomain}.${data.aws_route53_zone.selected.name}"
88
type = "A"
99
ttl = "300"
1010
records = ["${aws_eip.bastion1.public_ip}"]

terraform/global/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ variable "aws_dns_zone" {
22
description = "AWS Route53 zone"
33
}
44

5-
variable "gitlab_dns_subdomain" {
6-
description = "AWS Route53 zone"
7-
default = "gitlab"
5+
variable "bastion_dns_subdomain" {
6+
description = "Bastion DNS subdomain"
7+
default = "bastion1"
88
}
99

1010
variable "aws_az1" {

terraform/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module "global" {
88
source = "./global"
99

1010
aws_dns_zone = "${var.aws_dns_zone}"
11-
gitlab_dns_subdomain = "${var.gitlab_dns_subdomain}"
11+
bastion_dns_subdomain = "${var.bastion_dns_subdomain}"
1212
aws_az1 = "${var.aws_az1}"
1313
aws_az2 = "${var.aws_az2}"
1414
vpc_cidr = "${var.vpc_cidr}"

terraform/terraform.dist.tfvars

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1-
aws_access_key =
2-
aws_secret_key =
1+
// Your Amazon Web Service Access Key http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html
2+
aws_access_key = ""
3+
// Your Amazon Web Service private secret Key
4+
aws_secret_key = ""
35

6+
// The AWS Region where to build
47
aws_region = "eu-west-1"
8+
// 2 different Availability Zone for the previous AWS Region
59
aws_az1 = "eu-west-1a"
610
aws_az2 = "eu-west-1b"
711

8-
admin_ssh_public_key =
12+
// Your SSH public key to connect to AWS EC2 instances e.g. : the content of ~/.ssh/id.rsa.pub
13+
admin_ssh_public_key = ""
914

15+
// the IP addresses (CIDR range) to restrict SSH access to the bastions
1016
sg_ssh_cidr = "0.0.0.0/0"
1117

12-
gitlab_db_password =
13-
gitlab_root_password =
14-
gitlab_ci_registration_token =
18+
// Gitlab Postgresql Database password
19+
gitlab_db_password = ""
20+
// Gitlab default root account password
21+
gitlab_root_password = ""
22+
// Gitlab default Registration token for Gitlab CI
23+
gitlab_ci_registration_token = ""
1524

16-
aws_dns_zone =
25+
// your AWS route 53 Zone Base Domain e.g.: "my-domain.com"
26+
aws_dns_zone = ""
27+
// the Gitlab subdomain
1728
gitlab_dns_subdomain = "gitlab"
29+
// the Bastion subdomain
30+
bastion_dns_subdomain = "bastion1"
1831

32+
// Number of Gitlab static instances (not in the autoscaling group)
1933
gitlab_static_instances = 0
34+
35+
// Gitlab autoscaling
36+
// Maximum number of Gitlab instances
2037
gitlab_max = 3
38+
// Minimum number of Gitlab instances
2139
gitlab_min = 1
40+
// Desired number of Gitlab instances
2241
gitlab_desired = 2

terraform/variables.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ variable "aws_dns_zone" {
1111
}
1212

1313
variable "gitlab_dns_subdomain" {
14-
description = "AWS Route53 zone"
14+
description = "Gitlab DNS subdomain"
1515
default = "gitlab"
1616
}
1717

18+
variable "bastion_dns_subdomain" {
19+
description = "Bastion DNS subdomain"
20+
default = "bastion1"
21+
}
22+
1823
variable "aws_az1" {
1924
description = "AWS EC2 availability zone 2"
2025
default = "eu-west-1a"

0 commit comments

Comments
 (0)