forked from cattle-ops/terraform-aws-gitlab-runner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
107 lines (87 loc) · 2.78 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
data "aws_availability_zones" "available" {
state = "available"
}
data "aws_security_group" "default" {
name = "default"
vpc_id = module.vpc.vpc_id
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.33"
name = "vpc-${var.environment}"
cidr = "10.0.0.0/16"
azs = [data.aws_availability_zones.available.names[0]]
private_subnets = ["10.0.1.0/24"]
public_subnets = ["10.0.101.0/24"]
enable_nat_gateway = true
single_nat_gateway = true
enable_s3_endpoint = true
tags = {
Environment = var.environment
}
}
module "runner" {
source = "../../"
aws_region = var.aws_region
environment = var.environment
vpc_id = module.vpc.vpc_id
subnet_ids_gitlab_runner = module.vpc.private_subnets
subnet_id_runners = element(module.vpc.private_subnets, 0)
metrics_autoscaling = ["GroupDesiredCapacity", "GroupInServiceCapacity"]
runners_name = var.runner_name
runners_gitlab_url = var.gitlab_url
enable_runner_ssm_access = true
gitlab_runner_security_group_ids = [data.aws_security_group.default.id]
docker_machine_download_url = "https://gitlab-docker-machine-downloads.s3.amazonaws.com/v0.16.2-gitlab.2/docker-machine"
docker_machine_spot_price_bid = "0.06"
gitlab_runner_registration_config = {
registration_token = var.registration_token
tag_list = "docker_spot_runner"
description = "runner default - auto"
locked_to_project = "true"
run_untagged = "false"
maximum_timeout = "3600"
}
tags = {
"tf-aws-gitlab-runner:example" = "runner-default"
"tf-aws-gitlab-runner:instancelifecycle" = "spot:yes"
}
runners_privileged = "true"
runners_additional_volumes = ["/certs/client"]
runners_volumes_tmpfs = [
{
volume = "/var/opt/cache",
options = "rw,noexec"
}
]
runners_services_volumes_tmpfs = [
{
volume = "/var/lib/mysql",
options = "rw,noexec"
}
]
# working 9 to 5 :)
# Deprecated, replaced by runners_machine_autoscaling
# runners_off_peak_periods = "[\"* * 0-9,17-23 * * mon-fri *\", \"* * * * * sat,sun *\"]"
# runners_off_peak_timezone = var.timezone
# runners_off_peak_idle_count = 0
# runners_off_peak_idle_time = 60
runners_machine_autoscaling = [
{
periods = ["\"* * 0-9,17-23 * * mon-fri *\"", "\"* * * * * sat,sun *\""]
idle_count = 0
idle_time = 60
timezone = var.timezone
}
]
}
resource "null_resource" "cancel_spot_requests" {
# Cancel active and open spot requests, terminate instances
triggers = {
environment = var.environment
}
provisioner "local-exec" {
when = destroy
command = "../../ci/bin/cancel-spot-instances.sh ${self.triggers.environment}"
}
}