File tree Expand file tree Collapse file tree 5 files changed +138
-0
lines changed Expand file tree Collapse file tree 5 files changed +138
-0
lines changed Original file line number Diff line number Diff line change 1+ locals {
2+ tags = {
3+ Name = " gitlab-shell-runner"
4+ ManagedBy = " Terraform"
5+ }
6+ runner_user_data = templatefile (" ${ path . module } /templates/runner.tftpl" , {
7+ gitlab_url = var.gitlab_url
8+ runner_registration_token = var.runner_registration_token
9+ runner_description = var.runner_description
10+ runner_tags = " \" ${ join (" , " , var. runner_tags )} \" "
11+ run_untagged_jobs = var.run_untagged_jobs
12+ runner_locked = var.runner_locked
13+ })
14+ }
15+
16+ resource "aws_key_pair" "this" {
17+ count = var. ssh_public_key != null ? 1 : 0
18+
19+ key_name = " gitlab-shell-runner"
20+ public_key = var. ssh_public_key
21+
22+ tags = merge (
23+ local. tags ,
24+ var. additional_tags ,
25+ )
26+ }
27+
28+ resource "aws_instance" "this" {
29+ count = var. instance_count
30+
31+ ami = var. ami_id
32+ instance_type = var. instance_type
33+ key_name = var. ssh_public_key != null ? aws_key_pair. this [0 ]. key_name : null
34+ vpc_security_group_ids = var. vpc_security_group_ids
35+ subnet_id = var. subnet_id
36+ user_data = local. runner_user_data
37+ user_data_replace_on_change = true
38+
39+ tags = merge (
40+ local. tags ,
41+ var. additional_tags ,
42+ )
43+ }
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ sudo gitlab-runner register \
4+ --non-interactive \
5+ --url ${gitlab_url} \
6+ --registration-token ${runner_registration_token} \
7+ --executor shell \
8+ --description ${runner_description} \
9+ --tag-list ${runner_tags} \
10+ --run-untagged=${run_untagged_jobs} \
11+ --locked=${runner_locked} \
12+ --access-level=" not_protected"
Original file line number Diff line number Diff line change 1+ variable "ami_id" {
2+ description = " AMI to use for the instance"
3+ type = string
4+ }
5+
6+ variable "instance_type" {
7+ description = " Type of instance to provision"
8+ type = string
9+ }
10+
11+ variable "instance_count" {
12+ description = " Number of instances to provision"
13+ type = number
14+ default = 1
15+ }
16+
17+ variable "vpc_security_group_ids" {
18+ description = " List of security group IDs to associate"
19+ type = list (string )
20+ default = []
21+ }
22+
23+ variable "subnet_id" {
24+ description = " VPC Subnet ID to launch in"
25+ type = string
26+ default = " "
27+ }
28+
29+ variable "additional_tags" {
30+ description = " Additional tags to apply to the resources"
31+ type = map (string )
32+ default = {}
33+ }
34+
35+ variable "gitlab_url" {
36+ description = " Gitlab URL"
37+ type = string
38+ }
39+
40+ variable "runner_registration_token" {
41+ description = " Gitlab registration token"
42+ type = string
43+ }
44+
45+ variable "runner_description" {
46+ description = " Description for Gitlab Runners"
47+ type = string
48+ default = " Shell Runner"
49+ }
50+
51+ variable "runner_tags" {
52+ description = " Runner tags"
53+ type = list (string )
54+ default = [" shell" , " aws" ]
55+ }
56+
57+ variable "run_untagged_jobs" {
58+ description = " Run untagged jobs or not"
59+ type = bool
60+ default = true
61+ }
62+
63+ variable "runner_locked" {
64+ description = " Lock the runner or not"
65+ type = bool
66+ default = false
67+ }
68+
69+ variable "ssh_public_key" {
70+ description = " SSH public key to use for the key pair"
71+ type = string
72+ default = null
73+ }
Original file line number Diff line number Diff line change 1+ terraform {
2+ required_providers {
3+ aws = {
4+ source = " hashicorp/aws"
5+ version = " >= 4.49.0"
6+ }
7+ }
8+
9+ required_version = " ~> 1.3.0"
10+ }
You can’t perform that action at this time.
0 commit comments