Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 1a25b2c

Browse files
feat: Add public IP association to github runner (#3547)
### Description * Add option to associate public IP with runner (disabled by default) Fixes [3528](https://github.com/philips-labs/terraform-aws-github-runner/issues/3528) Suggested changes have been used in our env for over a month and it works as expected. ### Checklists **Development and testing:** - [x] All tests related to the changed code pass in development - [x] Pull request is ready for review --------- Co-authored-by: Niek Palm <[email protected]>
1 parent e232af5 commit 1a25b2c

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

modules/multi-runner/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ module "multi-runner" {
116116

117117
| Name | Description | Type | Default | Required |
118118
|------|-------------|------|---------|:--------:|
119+
| <a name="input_associate_public_ipv4_address"></a> [associate\_public\_ipv4\_address](#input\_associate\_public\_ipv4\_address) | Associate public IPv4 with the runner. Only tested with IPv4 | `bool` | `false` | no |
119120
| <a name="input_aws_partition"></a> [aws\_partition](#input\_aws\_partition) | (optiona) partition in the arn namespace to use if not 'aws' | `string` | `"aws"` | no |
120121
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region. | `string` | n/a | yes |
121122
| <a name="input_cloudwatch_config"></a> [cloudwatch\_config](#input\_cloudwatch\_config) | (optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details. | `string` | `null` | no |

modules/multi-runner/runners.tf

+1
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@ module "runners" {
103103
pool_lambda_timeout = var.pool_lambda_timeout
104104
pool_runner_owner = each.value.runner_config.pool_runner_owner
105105
pool_lambda_reserved_concurrent_executions = var.pool_lambda_reserved_concurrent_executions
106+
associate_public_ipv4_address = var.associate_public_ipv4_address
106107
}

modules/multi-runner/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,9 @@ variable "lambda_tracing_mode" {
556556
type = string
557557
default = null
558558
}
559+
560+
variable "associate_public_ipv4_address" {
561+
description = "Associate public IPv4 with the runner. Only tested with IPv4"
562+
type = bool
563+
default = false
564+
}

modules/runners/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ yarn run dist
126126
| <a name="input_ami_id_ssm_parameter_name"></a> [ami\_id\_ssm\_parameter\_name](#input\_ami\_id\_ssm\_parameter\_name) | Externally managed SSM parameter (of data type aws:ec2:image) that contains the AMI ID to launch runner instances from. Overrides ami\_filter | `string` | `null` | no |
127127
| <a name="input_ami_kms_key_arn"></a> [ami\_kms\_key\_arn](#input\_ami\_kms\_key\_arn) | Optional CMK Key ARN to be used to launch an instance from a shared encrypted AMI | `string` | `null` | no |
128128
| <a name="input_ami_owners"></a> [ami\_owners](#input\_ami\_owners) | The list of owners used to select the AMI of action runner instances. | `list(string)` | <pre>[<br> "amazon"<br>]</pre> | no |
129+
| <a name="input_associate_public_ipv4_address"></a> [associate\_public\_ipv4\_address](#input\_associate\_public\_ipv4\_address) | Associate public IPv4 with the runner. Only tested with IPv4 | `bool` | `false` | no |
129130
| <a name="input_aws_partition"></a> [aws\_partition](#input\_aws\_partition) | (optional) partition for the base arn if not 'aws' | `string` | `"aws"` | no |
130131
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region. | `string` | n/a | yes |
131132
| <a name="input_block_device_mappings"></a> [block\_device\_mappings](#input\_block\_device\_mappings) | The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops`, `throughput`, `kms_key_id`, `snapshot_id`. | <pre>list(object({<br> delete_on_termination = optional(bool, true)<br> device_name = optional(string, "/dev/xvda")<br> encrypted = optional(bool, true)<br> iops = optional(number)<br> kms_key_id = optional(string)<br> snapshot_id = optional(string)<br> throughput = optional(number)<br> volume_size = number<br> volume_type = optional(string, "gp3")<br> }))</pre> | <pre>[<br> {<br> "volume_size": 30<br> }<br>]</pre> | no |

modules/runners/main.tf

+14-2
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ resource "aws_launch_template" "runner" {
119119
key_name = var.key_name
120120
ebs_optimized = var.ebs_optimized
121121

122-
vpc_security_group_ids = compact(concat(
122+
vpc_security_group_ids = !var.associate_public_ipv4_address ? compact(concat(
123123
var.enable_managed_runner_security_group ? [aws_security_group.runner_sg[0].id] : [],
124124
var.runner_additional_security_group_ids,
125-
))
125+
)) : []
126126

127127
tag_specifications {
128128
resource_type = "instance"
@@ -176,6 +176,18 @@ resource "aws_launch_template" "runner" {
176176
tags = local.tags
177177

178178
update_default_version = true
179+
180+
dynamic "network_interfaces" {
181+
for_each = var.associate_public_ipv4_address ? [var.associate_public_ipv4_address] : []
182+
iterator = associate_public_ipv4_address
183+
content {
184+
associate_public_ip_address = associate_public_ipv4_address.value
185+
security_groups = compact(concat(
186+
var.enable_managed_runner_security_group ? [aws_security_group.runner_sg[0].id] : [],
187+
var.runner_additional_security_group_ids,
188+
))
189+
}
190+
}
179191
}
180192

181193
resource "aws_security_group" "runner_sg" {

modules/runners/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,9 @@ variable "enable_jit_config" {
622622
type = bool
623623
default = null
624624
}
625+
626+
variable "associate_public_ipv4_address" {
627+
description = "Associate public IPv4 with the runner. Only tested with IPv4"
628+
type = bool
629+
default = false
630+
}

0 commit comments

Comments
 (0)