|
| 1 | +data "aws_availability_zones" "available" { |
| 2 | + state = "available" |
| 3 | +} |
| 4 | + |
| 5 | +data "aws_security_group" "default" { |
| 6 | + name = "default" |
| 7 | + vpc_id = module.vpc.vpc_id |
| 8 | +} |
| 9 | + |
| 10 | +# VPC Flow logs are not needed here |
| 11 | +# kics-scan ignore-line |
| 12 | +module "vpc" { |
| 13 | + source = "terraform-aws-modules/vpc/aws" |
| 14 | + version = ">= 5.16.0" |
| 15 | + |
| 16 | + name = "vpc-${var.environment}" |
| 17 | + cidr = "10.0.0.0/16" |
| 18 | + |
| 19 | + azs = [data.aws_availability_zones.available.names[0]] |
| 20 | + private_subnets = ["10.0.1.0/24"] |
| 21 | + public_subnets = ["10.0.101.0/24"] |
| 22 | + map_public_ip_on_launch = false |
| 23 | + |
| 24 | + enable_nat_gateway = true |
| 25 | + single_nat_gateway = true |
| 26 | + |
| 27 | + tags = { |
| 28 | + Environment = var.environment |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +module "vpc_endpoints" { |
| 33 | + source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints" |
| 34 | + version = ">= 5.16.0" |
| 35 | + |
| 36 | + vpc_id = module.vpc.vpc_id |
| 37 | + |
| 38 | + endpoints = { |
| 39 | + s3 = { |
| 40 | + service = "s3" |
| 41 | + tags = { Name = "s3-vpc-endpoint" } |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + tags = { |
| 46 | + Environment = var.environment |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +module "runner" { |
| 51 | + source = "../../" |
| 52 | + |
| 53 | + environment = var.environment |
| 54 | + |
| 55 | + vpc_id = module.vpc.vpc_id |
| 56 | + subnet_id = element(module.vpc.private_subnets, 0) |
| 57 | + |
| 58 | + runner_instance = { |
| 59 | + collect_autoscaling_metrics = ["GroupDesiredCapacity", "GroupInServiceCapacity"] |
| 60 | + name = var.runner_name |
| 61 | + ssm_access = true |
| 62 | + private_address_only = false |
| 63 | + } |
| 64 | + |
| 65 | + runner_networking = { |
| 66 | + allow_incoming_ping_security_group_ids = [data.aws_security_group.default.id] |
| 67 | + } |
| 68 | + |
| 69 | + runner_gitlab = { |
| 70 | + url = var.gitlab_url |
| 71 | + |
| 72 | + preregistered_runner_token_ssm_parameter_name = var.preregistered_runner_token_ssm_parameter_name |
| 73 | + } |
| 74 | + |
| 75 | + runner_worker = { |
| 76 | + type = "docker-autoscaler" |
| 77 | + max_jobs = 10 |
| 78 | + use_private_key = true |
| 79 | + |
| 80 | + environment_variables = [ |
| 81 | + "FF_USE_POWERSHELL_PATH_RESOLVER=1" |
| 82 | + ] |
| 83 | + } |
| 84 | + |
| 85 | + runner_worker_gitlab_pipeline = { |
| 86 | + pre_build_script = <<EOT |
| 87 | + ''' |
| 88 | + echo 'multiline 1' |
| 89 | + echo 'multiline 2' |
| 90 | + ''' |
| 91 | + EOT |
| 92 | + post_build_script = "\"echo 'single line'\"" |
| 93 | + } |
| 94 | + |
| 95 | + runner_worker_docker_autoscaler = { |
| 96 | + fleeting_plugin_version = "1.0.0" |
| 97 | + connector_config_user = "Administrator" |
| 98 | + } |
| 99 | + |
| 100 | + runner_worker_docker_autoscaler_ami_owners = ["self"] # FIXME Leave to self or change to your AWS account ID |
| 101 | + runner_worker_docker_autoscaler_ami_id = "<windows-ami-id>" |
| 102 | + |
| 103 | + runner_worker_docker_autoscaler_instance = { |
| 104 | + monitoring = true |
| 105 | + private_address_only = false |
| 106 | + } |
| 107 | + |
| 108 | + runner_worker_docker_autoscaler_asg = { |
| 109 | + subnet_ids = module.vpc.private_subnets |
| 110 | + types = ["m6a.medium", "m6i.medium"] # FIXME change these to what best fits your needs, keeping in mind that Windows runners need bigger instances |
| 111 | + enable_mixed_instances_policy = true |
| 112 | + |
| 113 | + # FIXME These settings enable windows runners to scale down to zero if no jobs are running but you can change it to fit your needs |
| 114 | + on_demand_base_capacity = 0 |
| 115 | + on_demand_percentage_above_base_capacity = 0 |
| 116 | + max_growth_rate = 10 |
| 117 | + spot_allocation_strategy = "price-capacity-optimized" |
| 118 | + spot_instance_pools = 0 |
| 119 | + } |
| 120 | + |
| 121 | + runner_worker_docker_autoscaler_autoscaling_options = [ |
| 122 | + { |
| 123 | + periods = ["* * * * *"] |
| 124 | + timezone = "Europe/Berlin" |
| 125 | + idle_count = 0 |
| 126 | + idle_time = "0s" |
| 127 | + scale_factor = 2 |
| 128 | + }, |
| 129 | + { |
| 130 | + periods = ["* 7-19 * * mon-fri"] |
| 131 | + timezone = "Europe/Berlin" |
| 132 | + idle_count = 3 |
| 133 | + idle_time = "30m" |
| 134 | + scale_factor = 2 |
| 135 | + } |
| 136 | + ] |
| 137 | + |
| 138 | + runner_worker_docker_options = { |
| 139 | + volumes = ["C:/cache"] |
| 140 | + privileged = false |
| 141 | + } |
| 142 | + |
| 143 | + tags = { |
| 144 | + "tf-aws-gitlab-runner:example" = "runner-default" |
| 145 | + "tf-aws-gitlab-runner:instancelifecycle" = "spot:yes" |
| 146 | + } |
| 147 | +} |
0 commit comments