-
Notifications
You must be signed in to change notification settings - Fork 693
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 3 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,7 +36,7 @@ variable "subnet_ids" { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| variable "overrides" { | ||||||||||||||||||||||
| description = "This map provides the possibility to override some defaults. The following attributes are supported: `name_sg` overrides the `Name` tag for all security groups created by this module. `name_runner_agent_instance` overrides the `Name` tag for the ec2 instance defined in the auto launch configuration. `name_docker_machine_runners` overrides the `Name` tag spot instances created by the runner agent." | ||||||||||||||||||||||
| description = "This map provides the possibility to override some defaults. The following attributes are supported: `name_sg` overrides the `Name` tag for all security groups created by this module. `name_runner` overrides the `Name` tag for the ec2 instance defined in the auto launch configuration. `instance_profile_name` overrides the instance profile name used in the launch template." | ||||||||||||||||||||||
| type = map(string) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| default = { | ||||||||||||||||||||||
|
|
@@ -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." | |
| } |
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.
When
override_runner_roleis true, theaws_iam_role.runnerresource is not created (count = 0). However, this resource still tries to referenceaws_iam_role.runner[0].namewhenoverride_instance_profileis false, which will cause a Terraform error.If
override_runner_roleis true, thenoverride_instance_profileshould also be true (or the instance profile creation should be skipped). Consider adding validation to enforce this constraint, or adjust the logic to handle this case properly.