This module creates a simple GitLab CI Runner using a Docker executor on a long-lived AWS EC2 instance in an Auto Scaling Group.
The below outlines the current parameters and defaults.
Name | Description | Type | Default | Required |
---|---|---|---|---|
vpc_id | The target VPC for hosting the GitLab Runner | string | "" | Yes |
subnet_ids | List of subnets for hosting the GitLab Runner | list(string) | "" | Yes |
key_name | The name of the EC2 key pair to use | string | default | No |
enable_ssh_access | Enables SSH access to the GitLab Runner | bool | false | No |
ssh_cidr_blocks | List of CIDR blocks to use if allowing SSH Access to the GitLab Runner | list(string) | [0.0.0.0/0] | No |
gitlab_runner_registration_config | Configuration used to register the runner | map(string) | (map) | No |
gitlab_runner_concurrency | Maximum number of jobs to allow the GitLab Runner to run concurrently | number | 5 | No |
In the gitlab_runner_registration_config variable pass the details needed to register the GitLab Runner. It accepts four keys:
url
- the GitLab URL e.g. https://gitlab.comname
- the name of the GitLab Runner. This is informational only and forms the descriptionregistration_token
- the Registration Token. See below for instructions on generating thisdocker_image
- the Docker Image to be used by the Docker Executor e.g. alpine:latest
None.
See the GitLab docs here.
- Go to the project in GitLab e.g. https://gitlab.com/alexharv074/test
- On the left hand side select Settings > CI/CD
- Under Runners Expand.
The registration token can be found from here.
Put the token in a tfvars file or in an environment variable:
▶ export TF_VAR_registration_token=XXXXXXXXX
Create a simple .gitlab-ci.yml
file in the root of your project e.g.
---
image: busybox:latest
build1:
stage: build
script:
- echo "hello world"
Here is an example usage:
variable "registration_token" {}
variable "enable_ssh_access" {
default = false
}
variable "vpc_id" {}
variable "subnet_ids" {
type = list(string)
}
variable "key_name" {}
module "runner" {
source = "[email protected]:cmdlabs/terraform-aws-gitlab-runner.git"
key_name = var.key_name
vpc_id = var.vpc_id
subnet_ids = var.subnet_ids
gitlab_runner_concurrency = 10
gitlab_runner_registration_config = {
url = "https://gitlab.com"
name = "test-runner"
registration_token = var.registration_token
docker_image = "alpine:latest"
}
enable_ssh_access = var.enable_ssh_access
}
Apply that:
▶ terraform apply
Apache 2.0.