Skip to content

Commit 36633fa

Browse files
authored
refactor: Harmonize subnet variables (cattle-ops#420)
* Introduce new variable and deprecate the old ones * Use new variable * Fix validation error * Move deprecated variables to the end * Make it a boolean expression * Update docs * Fix examples * Make deprecated variable optional to support new `subnet_id` * Fix license * Fix Terraform code format with version 1.0.8
1 parent 262c483 commit 36633fa

File tree

7 files changed

+402
-224
lines changed

7 files changed

+402
-224
lines changed

README.md

+375-201
Large diffs are not rendered by default.

examples/runner-default/main.tf

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ module "runner" {
3333
aws_region = var.aws_region
3434
environment = var.environment
3535

36-
vpc_id = module.vpc.vpc_id
37-
subnet_ids_gitlab_runner = module.vpc.private_subnets
38-
subnet_id_runners = element(module.vpc.private_subnets, 0)
39-
metrics_autoscaling = ["GroupDesiredCapacity", "GroupInServiceCapacity"]
36+
vpc_id = module.vpc.vpc_id
37+
subnet_id = element(module.vpc.private_subnets, 0)
38+
metrics_autoscaling = ["GroupDesiredCapacity", "GroupInServiceCapacity"]
4039

4140
runners_name = var.runner_name
4241
runners_gitlab_url = var.gitlab_url

examples/runner-docker/main.tf

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ module "runner" {
3131
docker_machine_security_group_description = "Custom description for docker-machine"
3232
gitlab_runner_security_group_description = "Custom description for gitlab-runner"
3333

34-
vpc_id = module.vpc.vpc_id
35-
subnet_ids_gitlab_runner = module.vpc.public_subnets
36-
subnet_id_runners = element(module.vpc.public_subnets, 0)
34+
vpc_id = module.vpc.vpc_id
35+
subnet_id = element(module.vpc.public_subnets, 0)
3736

3837
runners_executor = "docker"
3938
runners_name = var.runner_name

examples/runner-pre-registered/main.tf

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ module "runner" {
2929
aws_region = var.aws_region
3030
environment = var.environment
3131

32-
vpc_id = module.vpc.vpc_id
33-
subnet_ids_gitlab_runner = module.vpc.private_subnets
34-
subnet_id_runners = element(module.vpc.private_subnets, 0)
32+
vpc_id = module.vpc.vpc_id
33+
subnet_id = element(module.vpc.private_subnets, 0)
3534

3635
runners_name = var.runner_name
3736
runners_gitlab_url = var.gitlab_url

examples/runner-public/main.tf

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ module "runner" {
3232

3333
runners_use_private_address = false
3434

35-
vpc_id = module.vpc.vpc_id
36-
subnet_ids_gitlab_runner = module.vpc.public_subnets
37-
subnet_id_runners = element(module.vpc.public_subnets, 0)
35+
vpc_id = module.vpc.vpc_id
36+
subnet_id = element(module.vpc.public_subnets, 0)
3837

3938
docker_machine_spot_price_bid = "on-demand-price"
4039

main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
data "aws_caller_identity" "current" {}
22

33
data "aws_subnet" "runners" {
4-
id = var.subnet_id_runners
4+
id = length(var.subnet_id) > 0 ? var.subnet_id : var.subnet_id_runners
55
}
66

77
data "aws_availability_zone" "runners" {
@@ -99,7 +99,7 @@ locals {
9999
aws_region = var.aws_region
100100
gitlab_url = var.runners_gitlab_url
101101
runners_vpc_id = var.vpc_id
102-
runners_subnet_id = var.subnet_id_runners
102+
runners_subnet_id = length(var.subnet_id) > 0 ? var.subnet_id : var.subnet_id_runners
103103
runners_aws_zone = data.aws_availability_zone.runners.name_suffix
104104
runners_instance_type = var.docker_machine_instance_type
105105
runners_spot_price_bid = var.docker_machine_spot_price_bid == "on-demand-price" ? "" : var.docker_machine_spot_price_bid
@@ -174,7 +174,7 @@ data "aws_ami" "docker-machine" {
174174

175175
resource "aws_autoscaling_group" "gitlab_runner_instance" {
176176
name = var.enable_asg_recreation ? "${aws_launch_template.gitlab_runner_instance.name}-asg" : "${var.environment}-as-group"
177-
vpc_zone_identifier = var.subnet_ids_gitlab_runner
177+
vpc_zone_identifier = length(var.subnet_id) > 0 ? [var.subnet_id] : var.subnet_ids_gitlab_runner
178178
min_size = "1"
179179
max_size = "1"
180180
desired_capacity = "1"

variables.tf

+15-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ variable "vpc_id" {
1919
type = string
2020
}
2121

22-
variable "subnet_id_runners" {
23-
description = "List of subnets used for hosting the gitlab-runners."
22+
variable "subnet_id" {
23+
description = "Subnet id used for the runner and executors. Must belong to the VPC specified above."
2424
type = string
25-
}
26-
27-
variable "subnet_ids_gitlab_runner" {
28-
description = "Subnet used for hosting the GitLab runner."
29-
type = list(string)
25+
default = "" # TODO remove as soon as subnet_id_runners and subnet_ids_gitlab_runner are gone. Variable is mandatory now.
3026
}
3127

3228
variable "extra_security_group_ids_runner_agent" {
@@ -726,3 +722,15 @@ variable "docker_machine_egress_rules" {
726722
description = "Allow all egress traffic for docker machine build runners"
727723
}]
728724
}
725+
726+
variable "subnet_id_runners" {
727+
description = "Deprecated! Use subnet_id instead. List of subnets used for hosting the gitlab-runners."
728+
type = string
729+
default = ""
730+
}
731+
732+
variable "subnet_ids_gitlab_runner" {
733+
description = "Deprecated! Use subnet_id instead. Subnet used for hosting the GitLab runner."
734+
type = list(string)
735+
default = []
736+
}

0 commit comments

Comments
 (0)