Skip to content

Commit

Permalink
refactor: runner configuration v4.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
raisedadead committed Aug 28, 2023
1 parent a65641f commit fa4a58c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 47 deletions.
9 changes: 9 additions & 0 deletions backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
cloud {
organization = "freecodecamp"

workspaces {
name = "tfws-ops-github-runners"
}
}
}
74 changes: 49 additions & 25 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@

resource "random_id" "random" {
byte_length = 20
}

data "aws_caller_identity" "current" {}

resource "aws_resourcegroups_group" "resourcegroups_group" {
name = "${var.prefix}-group"
resource_query {
query = <<JSON
{
"ResourceTypeFilters" : ["AWS::AllSupported"],
"TagFilters" : [
{
"Key" : "GitHubRunner",
"Values" : ["${var.prefix}"]
}
]
}
JSON
}
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.1.1"

name = "${var.prefix}-vpc"
cidr = "10.0.0.0/16"

azs = ["${var.aws_region}a", "${var.aws_region}b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]

enable_dns_hostnames = true
enable_nat_gateway = true
map_public_ip_on_launch = false
single_nat_gateway = true
}

module "runners" {
source = "philips-labs/github-runner/aws"
version = "4.2.0"
Expand All @@ -13,10 +46,10 @@ module "runners" {
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets

prefix = var.environment
prefix = var.prefix

tags = {
Project = "GitHubRunner"
Environment = var.environment
GitHubRunner = var.prefix
}

github_app = {
Expand All @@ -32,8 +65,9 @@ module "runners" {
runners_lambda_zip = "lambdas/runners.zip"

enable_organization_runners = false
runner_extra_labels = "ubuntu,on-aws"
runner_extra_labels = "on-aws"

# Run the GitHub actions agent as user.
runner_run_as = "ubuntu"

# enable access to the runners via SSM
Expand All @@ -49,16 +83,17 @@ module "runners" {
# idleCount = 2
# }]

instance_types = ["m5.large", "c5.large"]
instance_types = ["c5.xlarge"]
runner_name_prefix = "${var.prefix}-"

# Use the latest Ubuntu 20.04 AMI from our account
# built using the packer template in the packer folder
ami_filter = {
name = ["github-runner-ubuntu-focal-amd64-*"]
state = ["available"]
}
ami_owners = [data.aws_caller_identity.current.account_id]
enable_userdata = false
# ami_filter = {
# name = ["github-runner-ubuntu-focal-amd64-*"]
# state = ["available"]
# }
# ami_owners = [data.aws_caller_identity.current.account_id]
# enable_userdata = false

block_device_mappings = [{
# Set the block device name for Ubuntu root device
Expand Down Expand Up @@ -95,7 +130,7 @@ module "runners" {
]

# disable binary syncer since github agent is already installed in the AMI.
enable_runner_binaries_syncer = false
enable_runner_binaries_syncer = true

# override delay of events in seconds
delay_webhook_event = 5
Expand All @@ -104,23 +139,12 @@ module "runners" {
# set up a fifo queue to remain order
enable_fifo_build_queue = true

# override scaling down
# scale_down_schedule_expression = "cron(* * * * ? *)"

# enable ephemeral runners
enable_ephemeral_runners = true

# More on AWS Cron Expressions: https://stackoverflow.com/a/39508593/1932901
# Will scale down to minimum runners if there are no builds in the queue in the last 1 hours
scale_down_schedule_expression = "cron(0 0/1 * * ? *)"
}

terraform {
cloud {
organization = "freecodecamp"

workspaces {
name = "tfws-ops-github-runners"
}
}
log_level = "debug"
}
3 changes: 3 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ output "webhook_secret" {
value = random_id.random.hex
}

output "vpc" {
value = module.vpc
}
7 changes: 1 addition & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ variable "aws_region" {
}

variable "prefix" {
default = "github-runner"
default = "gh-nws-ci"
description = "Prefix used for resource naming."
}

variable "environment" {
default = "ubuntu"
description = "Environment name to use for tagging resources"
}
16 changes: 0 additions & 16 deletions vpc.tf

This file was deleted.

0 comments on commit fa4a58c

Please sign in to comment.