Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option to disable lambda to sync runner binaries #2314

Merged
merged 4 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ locals {
"ghr:environment" = var.prefix
})

s3_action_runner_url = "s3://${module.runner_binaries.bucket.id}/${module.runner_binaries.runner_distribution_object_key}"
s3_action_runner_url = var.enable_runner_binaries_syncer ? "s3://${module.runner_binaries[0].bucket.id}/${module.runner_binaries[0].runner_distribution_object_key}" : null
github_app_parameters = {
id = module.ssm.parameters.github_app_id
key_base64 = module.ssm.parameters.github_app_key_base64
Expand Down Expand Up @@ -134,7 +134,7 @@ module "runners" {
prefix = var.prefix
tags = local.tags

s3_bucket_runner_binaries = module.runner_binaries.bucket
s3_bucket_runner_binaries = var.enable_runner_binaries_syncer ? module.runner_binaries[0].bucket : null
s3_location_runner_binaries = local.s3_action_runner_url

runner_os = var.runner_os
Expand Down Expand Up @@ -169,6 +169,7 @@ module "runners" {
runner_additional_security_group_ids = var.runner_additional_security_group_ids
metadata_options = var.runner_metadata_options

enable_runner_binaries_syncer = var.enable_runner_binaries_syncer
lambda_s3_bucket = var.lambda_s3_bucket
runners_lambda_s3_key = var.runners_lambda_s3_key
runners_lambda_s3_object_version = var.runners_lambda_s3_object_version
Expand Down Expand Up @@ -218,6 +219,8 @@ module "runners" {
}

module "runner_binaries" {
count = var.enable_runner_binaries_syncer ? 1 : 0

source = "./modules/runner-binaries-syncer"

aws_region = var.aws_region
Expand Down
2 changes: 1 addition & 1 deletion modules/runners/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ resource "aws_launch_template" "runner" {
user_data = var.enabled_userdata ? base64encode(templatefile(local.userdata_template, {
pre_install = var.userdata_pre_install
install_runner = templatefile(local.userdata_install_runner[var.runner_os], {
S3_LOCATION_RUNNER_DISTRIBUTION = var.s3_location_runner_binaries
S3_LOCATION_RUNNER_DISTRIBUTION = var.enable_runner_binaries_syncer ? var.s3_location_runner_binaries : ""
RUNNER_ARCHITECTURE = var.runner_architecture
})
post_install = var.userdata_post_install
Expand Down
2 changes: 2 additions & 0 deletions modules/runners/policies-runner.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ resource "aws_iam_role_policy" "ssm_parameters" {
}

resource "aws_iam_role_policy" "dist_bucket" {
count = var.enable_runner_binaries_syncer ? 1 : 0

name = "distribution-bucket"
role = aws_iam_role.runner.name
policy = templatefile("${path.module}/policies/instance-s3-policy.json",
Expand Down
8 changes: 7 additions & 1 deletion modules/runners/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,10 @@ variable "lambda_architecture" {
condition = contains(["arm64", "x86_64"], var.lambda_architecture)
error_message = "`lambda_architecture` value is not valid, valid values are: `arm64` and `x86_64`."
}
}
}

variable "enable_runner_binaries_syncer" {
description = "Option to disable the lambda to sync GitHub runner distribution, usefull when using a pre-build AMI."
type = bool
default = true
npalm marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 5 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ output "runners" {
}

output "binaries_syncer" {
value = {
lambda = module.runner_binaries.lambda
lambda_role = module.runner_binaries.lambda_role
value = var.enable_runner_binaries_syncer ? {
lambda = module.runner_binaries[0].lambda
lambda_role = module.runner_binaries[0].lambda_role
location = local.s3_action_runner_url
bucket = module.runner_binaries.bucket
}
bucket = module.runner_binaries[0].bucket
} : null
}

output "webhook" {
Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,10 @@ variable "lambda_architecture" {
condition = contains(["arm64", "x86_64"], var.lambda_architecture)
error_message = "`lambda_architecture` value is not valid, valid values are: `arm64` and `x86_64`."
}
}
}

variable "enable_runner_binaries_syncer" {
description = "Option to disable the lambda to sync GitHub runner distribution, usefull when using a pre-build AMI."
type = bool
default = true
}