Skip to main content

Component: github-runners

This component is responsible for provisioning EC2 instances for GitHub runners.

Usage

Stack Level: Regional

Here's an example snippet for how to use this component.

components:
terraform:
github-runners:
vars:
cpu_utilization_high_threshold_percent: 5
cpu_utilization_low_threshold_percent: 1
default_cooldown: 300
github_scope: company
instance_type: "t3.small"
max_size: 10
min_size: 1
runner_group: default
scale_down_cooldown_seconds: 2700
wait_for_capacity_timeout: 10m
mixed_instances_policy:
instances_distribution:
on_demand_allocation_strategy: "prioritized"
on_demand_base_capacity: 1
on_demand_percentage_above_base_capacity: 0
spot_allocation_strategy: "capacity-optimized"
spot_instance_pools: null
spot_max_price: null
override:
- instance_type: "t4g.large"
weighted_capacity: null
- instance_type: "m5.large"
weighted_capacity: null
- instance_type: "m5a.large"
weighted_capacity: null
- instance_type: "m5n.large"
weighted_capacity: null
- instance_type: "m5zn.large"
weighted_capacity: null
- instance_type: "m4.large"
weighted_capacity: null
- instance_type: "c5.large"
weighted_capacity: null
- instance_type: "c5a.large"
weighted_capacity: null
- instance_type: "c5n.large"
weighted_capacity: null
- instance_type: "c4.large"
weighted_capacity: null

Configuration

API Token

Prior to deployment, the API Token must exist in SSM.

To generate the token, please follow these instructions. Once generated, write the API token to the SSM key store at the following location within the same AWS account and region where the GitHub Actions runner pool will reside.

assume-role <automation-admin role>
chamber write github/runners/<github-org> registration-token ghp_secretstring

Requirements

NameVersion
terraform>= 1.0.0
aws>= 4.9.0
cloudinit>= 2.2

Providers

NameVersion
aws>= 4.9.0
cloudinit>= 2.2

Modules

NameSourceVersion
account_mapcloudposse/stack-config/yaml//modules/remote-state1.4.1
autoscale_groupcloudposse/ec2-autoscale-group/aws0.30.1
graceful_scale_in./modules/graceful_scale_inn/a
iam_roles../account-map/modules/iam-rolesn/a
sgcloudposse/security-group/aws1.0.1
thiscloudposse/label/null0.25.0
vpccloudposse/stack-config/yaml//modules/remote-state1.4.1

Resources

NameType
aws_iam_instance_profile.github_action_runnerresource
aws_iam_policy.github_action_runnerresource
aws_iam_role.github_action_runnerresource
aws_ami.runnerdata source
aws_iam_policy_document.github_action_runnerdata source
aws_iam_policy_document.instance_assume_role_policydata source
aws_partition.currentdata source
aws_ssm_parameter.github_tokendata source
cloudinit_config.configdata source

Inputs

NameDescriptionTypeDefaultRequired
account_map_environment_nameThe name of the environment where account_map is provisionedstring"gbl"no
account_map_stage_nameThe name of the stage where account_map is provisionedstring"root"no
account_map_tenant_nameThe name of the tenant where account_map is provisioned.

If the tenant label is not used, leave this as null.
stringnullno
additional_tag_mapAdditional key-value pairs to add to each map in tags_as_list_of_maps. Not added to tags or id.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration.
map(string){}no
ami_filterMap of lists used to look up the AMI which will be used for the GitHub Actions Runner.map(list(string))
{
"name": [
"amzn2-ami-hvm-2.*-x86_64-ebs"
]
}
no
ami_ownersThe list of owners used to select the AMI of action runner instances.list(string)
[
"amazon"
]
no
attributesID element. Additional attributes (e.g. workers or cluster) to add to id,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the delimiter
and treated as a single ID element.
list(string)[]no
block_device_mappingsSpecify volumes to attach to the instance besides the volumes specified by the AMI
list(object({
device_name = string
no_device = bool
virtual_name = string
ebs = object({
delete_on_termination = bool
encrypted = bool
iops = number
kms_key_id = string
snapshot_id = string
volume_size = number
volume_type = string
})
}))
[]no
contextSingle object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as null to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
any
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
no
cpu_utilization_high_evaluation_periodsThe number of periods over which data is compared to the specified thresholdnumber2no
cpu_utilization_high_period_secondsThe period in seconds over which the specified statistic is appliednumber300no
cpu_utilization_high_threshold_percentThe value against which the specified statistic is comparednumber90no
cpu_utilization_low_evaluation_periodsThe number of periods over which data is compared to the specified thresholdnumber2no
cpu_utilization_low_period_secondsThe period in seconds over which the specified statistic is appliednumber300no
cpu_utilization_low_threshold_percentThe value against which the specified statistic is comparednumber10no
default_cooldownThe amount of time, in seconds, after a scaling activity completes before another scaling activity can startnumber300no
delimiterDelimiter to be used between ID elements.
Defaults to - (hyphen). Set to "" to use no delimiter at all.
stringnullno
descriptor_formatsDescribe additional descriptors to be output in the descriptors output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
{<br/> format = string<br/> labels = list(string)<br/>}
(Type is any so the map values can later be enhanced to provide additional options.)
format is a Terraform format string to be passed to the format() function.
labels is a list of labels, in order, to pass to format() function.
Label values will be normalized before being passed to format() so they will be
identical to how they appear in id.
Default is {} (descriptors output will be empty).
any{}no
docker_compose_versionThe version of docker-compose to installstring"1.29.2"no
enabledSet to false to prevent the module from creating any resourcesboolnullno
environmentID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'stringnullno
github_scopeScope of the runner (e.g. cloudposse/example for repo or cloudposse for org)stringn/ayes
id_length_limitLimit id to this many characters (minimum 6).
Set to 0 for unlimited length.
Set to null for keep the existing setting, which defaults to 0.
Does not affect id_full.
numbernullno
import_profile_nameAWS Profile name to use when importing a resourcestringnullno
import_role_arnIAM Role ARN to use when importing a resourcestringnullno
instance_typeDefault instance type for the action runner.string"m5.large"no
label_key_caseControls the letter case of the tags keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the tags input.
Possible values: lower, title, upper.
Default value: title.
stringnullno
label_orderThe order in which the labels (ID elements) appear in the id.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
list(string)nullno
label_value_caseControls the letter case of ID elements (labels) as included in id,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the tags input.
Possible values: lower, title, upper and none (no transformation).
Set this to title and set delimiter to "" to yield Pascal Case IDs.
Default value: lower.
stringnullno
labels_as_tagsSet of labels (ID elements) to include as tags in the tags output.
Default is to include all labels.
Tags with empty values will not be included in the tags output.
Set to [] to suppress all generated tags.
Notes:
The value of the name tag, if included, will be the id, not the name.
Unlike other null-label inputs, the initial setting of labels_as_tags cannot be
changed in later chained modules. Attempts to change it will be silently ignored.
set(string)
[
"default"
]
no
max_instance_lifetimeThe maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 604800 and 31536000 secondsnumbernullno
max_sizeThe maximum size of the autoscale groupnumbern/ayes
min_sizeThe minimum size of the autoscale groupnumbern/ayes
mixed_instances_policyPolicy to use a mixed group of on-demand/spot of differing types. Launch template is automatically generated. https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#mixed_instances_policy-1
object({
instances_distribution = object({
on_demand_allocation_strategy = string
on_demand_base_capacity = number
on_demand_percentage_above_base_capacity = number
spot_allocation_strategy = string
spot_instance_pools = number
spot_max_price = string
})
override = list(object({
instance_type = string
weighted_capacity = number
}))
})
nullno
nameID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a tag.
The "name" tag is set to the full id string. There is no tag with the value of the name input.
stringnullno
namespaceID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally uniquestringnullno
regex_replace_charsTerraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, "/[^a-zA-Z0-9-]/" is used to remove all characters other than hyphens, letters and digits.
stringnullno
regionAWS Regionstringn/ayes
runner_groupGitHub runner groupstring"default"no
runner_labelsList of labels to add to the GitHub Runner (e.g. 'Amazon Linux 2').list(string)[]no
runner_role_additional_policy_arnsList of policy ARNs that will be attached to the runners' default role on creation in addition to the defaultslist(string)[]no
runner_versionGitHub runner release versionstring"2.288.1"no
scale_down_cooldown_secondsThe amount of time, in seconds, after a scaling activity completes and before the next scaling activity can startnumber300no
ssm_parameter_name_formatSSM parameter name formatstring"/%s/%s"no
ssm_pathGitHub token SSM pathstring"github"no
ssm_path_keyGitHub token SSM path keystring"registration-token"no
stageID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'stringnullno
tagsAdditional tags (e.g. {'BusinessUnit': 'XYZ'}).
Neither the tag keys nor the tag values will be modified by this module.
map(string){}no
tenantID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is forstringnullno
userdata_post_installShell script to run post installation of github action runnerstring""no
userdata_pre_installShell script to run before installation of github action runnerstring""no
wait_for_capacity_timeoutA maximum duration that Terraform should wait for ASG instances to be healthy before timing out. (See also Waiting for Capacity below.) Setting this to '0' causes Terraform to skip all Capacity Waiting behaviorstring"10m"no

Outputs

NameDescription
autoscaling_group_arnThe Amazon Resource Name (ARN) of the Auto Scaling Group.
autoscaling_group_nameThe name of the Auto Scaling Group.
autoscaling_lifecycle_hook_nameThe name of the Lifecycle Hook for the Auto Scaling Group.
eventbridge_rule_arnThe ARN of the Eventbridge rule for the EC2 lifecycle transition.
eventbridge_target_arnThe ARN of the Eventbridge target corresponding to the Eventbridge rule for the EC2 lifecycle transition.
iam_role_arnThe ARN of the IAM role associated with the Autoscaling Group
ssm_document_arnThe ARN of the SSM document.

References