-
Notifications
You must be signed in to change notification settings - Fork 864
/
runner.tf
121 lines (114 loc) · 3.61 KB
/
runner.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
gitlab_runner_auth_token_secret_id = "gitlab_runner_auth_token"
}
module "runner-sa" {
source = "../../../modules/iam-service-account"
project_id = module.project.project_id
name = "gitlab-runner-sa"
}
module "runner-mig-sa" {
count = local.runner_config_type == "docker_autoscaler" ? 1 : 0
source = "../../../modules/iam-service-account"
project_id = module.project.project_id
name = "gitlab-runner-sa"
iam = {
"roles/iam.serviceAccountUser" = [
"serviceAccount:${module.runner-sa.email}"
]
}
}
module "runner-secrets" {
source = "../../../modules/secret-manager"
project_id = module.project.project_id
secrets = {
(local.gitlab_runner_auth_token_secret_id) = {
locations = [var.region]
}
}
versions = {
(local.gitlab_runner_auth_token_secret_id) = {
latest = {
enabled = true, data = var.gitlab_runner_config.authentication_token
}
}
}
iam = {
(local.gitlab_runner_auth_token_secret_id) = {
"roles/secretmanager.secretAccessor" = [
"serviceAccount:${module.runner-sa.email}"
]
}
}
}
module "gitlab-runner" {
source = "../../../modules/compute-vm"
project_id = module.project.project_id
boot_disk = {
initialize_params = {
size = var.vm_config.boot_disk_size
}
}
instance_type = var.vm_config.instance_type
name = var.vm_config.name
tags = var.vm_config.network_tags
zone = var.vm_config.zone
network_interfaces = [
{
network = var.network_config.network_self_link
subnetwork = var.network_config.subnet_self_link
}
]
metadata = {
startup-script = templatefile("${path.module}/assets/startup-script.sh.tpl", local.runner_startup_script_config)
}
service_account = {
email = module.runner-sa.email
}
}
module "gitlab-runner-template" {
count = local.runner_config_type == "docker_autoscaler" ? 1 : 0
source = "../../../modules/compute-vm"
project_id = module.project.project_id
name = var.gitlab_runner_config.executors_config.docker_autoscaler.mig_name
zone = var.gitlab_runner_config.executors_config.docker_autoscaler.zone
tags = ["ssh"]
network_interfaces = [
{
network = var.network_config.network_self_link
subnetwork = var.network_config.subnet_self_link
}
]
boot_disk = {
initialize_params = {
image = "projects/cos-cloud/global/images/family/cos-stable"
}
}
service_account = {
email = module.runner-mig-sa.0.email
}
create_template = true
}
module "gitlab-runner-mig" {
count = local.runner_config_type == "docker_autoscaler" ? 1 : 0
source = "../../../modules/compute-mig"
project_id = module.project.project_id
location = var.gitlab_runner_config.executors_config.docker_autoscaler.zone
name = var.gitlab_runner_config.executors_config.docker_autoscaler.mig_name
target_size = 1
instance_template = module.gitlab-runner-template.0.template.self_link
}