-
Notifications
You must be signed in to change notification settings - Fork 692
feat(runner-role): Enable using separate IAM role for runners #4875
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
base: main
Are you sure you want to change the base?
Changes from all commits
fe00fd3
b09301d
509bb71
703763f
abaf7af
8cdfa6a
6161117
7065778
e0fb3e6
666df6e
8a26390
5457d53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -162,6 +162,17 @@ variable "multi_runner_config" { | |||||||||||||||||||||||||
| lambda_timeout = optional(number, 30) | ||||||||||||||||||||||||||
| max_attempts = optional(number, 1) | ||||||||||||||||||||||||||
| }), {}) | ||||||||||||||||||||||||||
| iam_overrides = optional(object({ | ||||||||||||||||||||||||||
| override_instance_profile = optional(bool, null) | ||||||||||||||||||||||||||
| instance_profile_name = optional(string, null) | ||||||||||||||||||||||||||
| override_runner_role = optional(bool, null) | ||||||||||||||||||||||||||
| runner_role_arn = optional(string, null) | ||||||||||||||||||||||||||
| }), { | ||||||||||||||||||||||||||
| override_instance_profile = false | ||||||||||||||||||||||||||
| instance_profile_name = null | ||||||||||||||||||||||||||
| override_runner_role = false | ||||||||||||||||||||||||||
| runner_role_arn = null | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| matcherConfig = object({ | ||||||||||||||||||||||||||
| labelMatchers = list(list(string)) | ||||||||||||||||||||||||||
|
|
@@ -233,6 +244,7 @@ variable "multi_runner_config" { | |||||||||||||||||||||||||
| 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`." | ||||||||||||||||||||||||||
| job_retry: "Experimental! Can be removed / changed without trigger a major release. Configure job retries. The configuration enables job retries (for ephemeral runners). After creating the instances a message will be published to a job retry queue. The job retry check lambda is checking after a delay if the job is queued. If not the message will be published again on the scale-up (build queue). Using this feature can impact the rate limit of the GitHub app." | ||||||||||||||||||||||||||
| pool_config: "The configuration for updating the pool. The `pool_size` to adjust to by the events triggered by the `schedule_expression`. For example you can configure a cron expression for week days to adjust the pool to 10 and another expression for the weekend to adjust the pool to 1. Use `schedule_expression_timezone` to override the schedule time zone (defaults to UTC)." | ||||||||||||||||||||||||||
| iam_overrides: "Allows to (optionally) override the instance profile and runner role created by the module. Set `override_instance_profile` to true and provide the `instance_profile_name` to use an existing instance profile. Set `override_runner_role` to true and provide the `runner_role_arn` to use an existing role for the runner instances." | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| matcherConfig: { | ||||||||||||||||||||||||||
| labelMatchers: "The list of list of labels supported by the runner configuration. `[[self-hosted, linux, x64, example]]`" | ||||||||||||||||||||||||||
|
|
@@ -724,3 +736,20 @@ variable "user_agent" { | |||||||||||||||||||||||||
| type = string | ||||||||||||||||||||||||||
| default = "github-aws-runners" | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| variable "iam_overrides" { | ||||||||||||||||||||||||||
| description = "This map provides the possibility to override some IAM defaults. The following attributes are supported: `instance_profile_name` overrides the instance profile name used in the launch template. `runner_role_arn` overrides the IAM role ARN used for the runner instances." | ||||||||||||||||||||||||||
| type = object({ | ||||||||||||||||||||||||||
| override_instance_profile = optional(bool, null) | ||||||||||||||||||||||||||
| instance_profile_name = optional(string, null) | ||||||||||||||||||||||||||
| override_runner_role = optional(bool, null) | ||||||||||||||||||||||||||
| runner_role_arn = optional(string, null) | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| default = { | ||||||||||||||||||||||||||
| override_instance_profile = false | ||||||||||||||||||||||||||
| instance_profile_name = null | ||||||||||||||||||||||||||
| override_runner_role = false | ||||||||||||||||||||||||||
| runner_role_arn = null | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| } | |
| } | |
| validation { | |
| condition = !var.iam_overrides.override_instance_profile || var.iam_overrides.instance_profile_name != null | |
| error_message = "instance_profile_name must be provided when override_instance_profile is true." | |
| } | |
| validation { | |
| condition = !var.iam_overrides.override_runner_role || var.iam_overrides.runner_role_arn != null | |
| error_message = "runner_role_arn must be provided when override_runner_role is true." | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| data "aws_caller_identity" "current" {} | ||||||
|
|
||||||
| resource "aws_iam_role" "runner" { | ||||||
| count = var.iam_overrides["override_runner_role"] ? 0 : 1 | ||||||
| name = "${substr("${var.prefix}-runner", 0, 54)}-${substr(md5("${var.prefix}-runner"), 0, 8)}" | ||||||
| assume_role_policy = templatefile("${path.module}/policies/instance-role-trust-policy.json", {}) | ||||||
| path = local.role_path | ||||||
|
|
@@ -9,22 +10,24 @@ resource "aws_iam_role" "runner" { | |||||
| } | ||||||
|
|
||||||
| resource "aws_iam_instance_profile" "runner" { | ||||||
| name = "${var.prefix}-runner-profile" | ||||||
| role = aws_iam_role.runner.name | ||||||
| path = local.instance_profile_path | ||||||
| tags = local.tags | ||||||
| count = var.iam_overrides["override_instance_profile"] ? 0 : 1 | ||||||
|
||||||
| count = var.iam_overrides["override_instance_profile"] ? 0 : 1 | |
| count = (var.iam_overrides["override_instance_profile"] || var.iam_overrides["override_runner_role"]) ? 0 : 1 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -48,7 +48,7 @@ module "pool" { | |||||
| group_name = var.runner_group_name | ||||||
| name_prefix = var.runner_name_prefix | ||||||
| pool_owner = var.pool_runner_owner | ||||||
| role = aws_iam_role.runner | ||||||
| role = var.iam_overrides["override_runner_role"] ? var.iam_overrides["runner_role_arn"] : aws_iam_role.runner[0].name | ||||||
|
||||||
| role = var.iam_overrides["override_runner_role"] ? var.iam_overrides["runner_role_arn"] : aws_iam_role.runner[0].name | |
| role = var.iam_overrides["override_runner_role"] ? { arn = var.iam_overrides["runner_role_arn"] } : aws_iam_role.runner[0] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -45,6 +45,23 @@ variable "overrides" { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| variable "iam_overrides" { | ||||||||||||||||||||||
| description = "This map provides the possibility to override some IAM defaults. The following attributes are supported: `instance_profile_name` overrides the instance profile name used in the launch template. `runner_role_arn` overrides the IAM role ARN used for the runner instances." | ||||||||||||||||||||||
| type = object({ | ||||||||||||||||||||||
| override_instance_profile = optional(bool, null) | ||||||||||||||||||||||
| instance_profile_name = optional(string, null) | ||||||||||||||||||||||
| override_runner_role = optional(bool, null) | ||||||||||||||||||||||
| runner_role_arn = optional(string, null) | ||||||||||||||||||||||
| }) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| default = { | ||||||||||||||||||||||
| override_instance_profile = false | ||||||||||||||||||||||
| instance_profile_name = null | ||||||||||||||||||||||
| override_runner_role = false | ||||||||||||||||||||||
| runner_role_arn = null | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
||||||||||||||||||||||
| } | |
| } | |
| validation { | |
| condition = !var.iam_overrides.override_instance_profile || var.iam_overrides.instance_profile_name != null | |
| error_message = "instance_profile_name must be provided when override_instance_profile is true." | |
| } | |
| validation { | |
| condition = !var.iam_overrides.override_runner_role || var.iam_overrides.runner_role_arn != null | |
| error_message = "runner_role_arn must be provided when override_runner_role is true." | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -108,6 +108,23 @@ variable "runner_group_name" { | |||||||||||||||||||||||||
| default = "Default" | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| variable "iam_overrides" { | ||||||||||||||||||||||||||
maratinvitae marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
| description = "This map provides the possibility to override some IAM defaults. Note that when using this variable, you are responsible for ensuring the role has necessary permissions to access required resources; `override_instance_profile`: When set to true, the instance profile name provided in `instance_profile_name` will be used for the runners. `override_runner_role`: When set to true, the role ARN provided in `runner_role_arn` will be used for the runners." | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| description = "This map provides the possibility to override some IAM defaults. Note that when using this variable, you are responsible for ensuring the role has necessary permissions to access required resources; `override_instance_profile`: When set to true, the instance profile name provided in `instance_profile_name` will be used for the runners. `override_runner_role`: When set to true, the role ARN provided in `runner_role_arn` will be used for the runners." | |
| description = "This map provides the possibility to override some IAM defaults. Note that when using this variable, you are responsible for ensuring the role has necessary permissions to access required resources. `override_instance_profile`: When set to true, uses the instance profile name specified in `instance_profile_name` instead of creating a new instance profile. `override_runner_role`: When set to true, uses the role ARN specified in `runner_role_arn` instead of creating a new IAM role." |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The iam_overrides variable lacks validation to ensure that when override_instance_profile is true, the instance_profile_name is also provided (not null). Similarly, when override_runner_role is true, runner_role_arn should be provided.
Consider adding validation rules:
validation {
condition = !var.iam_overrides.override_instance_profile || var.iam_overrides.instance_profile_name != null
error_message = "instance_profile_name must be provided when override_instance_profile is true."
}
validation {
condition = !var.iam_overrides.override_runner_role || var.iam_overrides.runner_role_arn != null
error_message = "runner_role_arn must be provided when override_runner_role is true."
}
| } | |
| } | |
| validation { | |
| condition = !var.iam_overrides.override_instance_profile || var.iam_overrides.instance_profile_name != null | |
| error_message = "instance_profile_name must be provided when override_instance_profile is true." | |
| } | |
| validation { | |
| condition = !var.iam_overrides.override_runner_role || var.iam_overrides.runner_role_arn != null | |
| error_message = "runner_role_arn must be provided when override_runner_role is true." | |
| } |
Uh oh!
There was an error while loading. Please reload this page.