Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Latest commit

 

History

History
130 lines (90 loc) · 3.47 KB

README.md

File metadata and controls

130 lines (90 loc) · 3.47 KB

CMD Solutions|medium

terraform-aws-gitlab-runner

Table of contents

  1. Overview
  2. AWS GitLab Runner Terraform
  3. Example
  4. License

Overview

This module creates a simple GitLab CI Runner using a Docker executor on a long-lived AWS EC2 instance in an Auto Scaling Group.

AWS GitLab Runner Terraform

Inputs

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

Registration config

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.com
  • name - the name of the GitLab Runner. This is informational only and forms the description
  • registration_token - the Registration Token. See below for instructions on generating this
  • docker_image - the Docker Image to be used by the Docker Executor e.g. alpine:latest

Outputs

None.

Example

Obtain a Registration Token

See the GitLab docs here.

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

Add a .gitlab-ci.yml to a project

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"

Declare the module

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

License

Apache 2.0.