runs-on
This component is responsible for provisioning an RunsOn (https://runs-on.com/).
After deploying this component, you will need to install the RunsOn app to GitHub. See the RunsOn documentation for more information.
Compatibility
Due to output changes, this component only works with version 2.8.2+ of the RunsOn CloudFormation template.
Usage
Stack Level: Regional
Defaults
Regardless of the networking style, you should have these defaults in common:
(runs-on/defaults.yaml)
components:
terraform:
runs-on/defaults:
metadata:
component: runs-on
type: abstract
vars:
name: runs-on
enabled: true
capabilities: ["CAPABILITY_IAM"]
on_failure: "ROLLBACK"
timeout_in_minutes: 30
# template_url: https://runs-on.s3.eu-west-1.amazonaws.com/cloudformation/template.yaml
# See latest version and changelog at https://runs-on.com/changelog/
template_url: https://runs-on.s3.eu-west-1.amazonaws.com/cloudformation/template-v2.8.3.yaml
parameters:
AppCPU: 256
AppMemory: 512
EmailAddress: developer@cloudposse.com
# Environments let you run multiple Stacks in one organization and segregate resources.
# If you specify an environment, then all the jobs must also specify the which environment they are running in.
# To keep things simple, we use the default environment ("production") and leave the `env` label unset in the workflow.
EncryptEbs: true
# With the default value of SSHAllowed: true, the runners that are placed in a public subnet
# will allow ingress on port 22. This is highly abused (scanners running constantly looking for vulernable SSH servers)
# and should not be allowed. If you need access to the runners, use Session Manager (SSM).
SSHAllowed: false
LicenseKey: <LICENSE_KEY>
Private: false # always | true | false - Always will default place in private subnet, true will place in private subnet if tag `private=true` present on workflow, false will place in public subnet
RunnerLargeDiskSize: 120 # Disk size in GB for disk=large runners
Ec2LogRetentionInDays: 30
VpcFlowLogRetentionInDays: 14
Embedded networking (Runs On managed VPC)
When no VPC details are set, the component will create a new VPC and subnets for you. This is done via the CloudFormation template.
Note, you should set the VpcCidrBlock parameter to the CIDR block of the VPC that will be created.
(runs-on.yaml)
import:
- orgs/acme/core/auto/_defaults
- mixins/region/us-east-1
- catalog/runs-on/defaults
components:
terraform:
runs-on:
metadata:
inherits:
- runs-on/defaults
component: runs-on
vars:
networking_stack: embedded
parameters:
VpcCidrBlock: 10.100.0.0/16
External networking (Use existing VPC)
When you want to use an existing VPC, you can set the vpc_id, subnet_ids, and security_group_id variables.
(_defaults.yaml)
terraform:
hooks:
store-outputs:
name: auto/ssm
(runs-on.yaml)
import:
- orgs/acme/core/auto/_defaults
- mixins/region/us-east-1
- catalog/vpc/defaults
- catalog/runs-on/defaults
components:
terraform:
runs-on:
metadata:
inherits:
- runs-on/defaults
component: runs-on
vars:
networking_stack: external
# There are other ways to get the vpc_id, subnet_ids, and security_group_id. You can
# Harcode
# Use Atmos KV Store
# Use atmos !terraform.output yaml function
vpc_id: !store auto/ssm vpc vpc_id
subnet_ids: !store auto/ssm vpc private_subnet_ids
security_group_id: !store auto/ssm vpc default_security_group_id
(DEPRECATED) Configuring with Transit Gateway
It's important to note that the embedded networking will require some customization to work with Transit Gateway.
The following configuration assumes you are using the Cloud Posse Components for Transit Gateway (tgw/hub & tgw/spoke).
The outputs of this component contain the same outputs as the vpc component. This is because the runs-on
cloudformation stack creates a VPC and subnets.
First we need to update the TGW/Hub - this stores information about the VPCs that are allowed to be used by TGW Spokes.
Assuming your TGW/Hub lives in the core-network account and your Runs-On is deployed to core-auto (tgw-hub.yaml)
vars:
connections:
- account:
tenant: core
stage: auto
vpc_component_names:
- vpc
- runs-on
components:
terraform:
tgw/hub/defaults:
metadata:
type: abstract
component: tgw/hub
vars:
enabled: true
name: tgw-hub
tags:
Team: sre
Service: tgw-hub
tgw/hub:
metadata:
inherits:
- tgw/hub/defaults
component: tgw/hub
vars:
connections:
- account:
tenant: core
stage: network
- account:
tenant: core
stage: auto
vpc_component_names:
- vpc
- runs-on
- account:
tenant: plat
stage: sandbox
- account:
tenant: plat
stage: dev
- account:
tenant: plat
stage: staging
- account:
tenant: plat
stage: prod
We then need to create a spoke that refers to the VPC created by Runs-On.
(tgw-spoke.yaml)
tgw/spoke/runs-on:
metadata:
component: tgw/spoke
inherits:
- tgw/spoke-defaults
vars:
own_vpc_component_name: runs-on
attributes:
- "runs-on"
connections:
- account:
tenant: core
stage: network
- account:
tenant: core
stage: auto
vpc_component_names:
- vpc
- runs-on
- account:
tenant: plat
stage: sandbox
- account:
tenant: plat
stage: dev
- account:
tenant: plat
stage: staging
- account:
tenant: plat
stage: prod
Finally we need to update the spokes of the TGW/Spokes to allow Runs-On traffic to the other accounts.
Typically this includes core-auto, core-network, and your platform accounts.
(tgw-spoke.yaml)
tgw/spoke:
metadata:
inherits:
- tgw/spoke-defaults
vars:
connections:
...
vpc_component_names:
- vpc
- runs-on
...
Terraform Docs
Variables
Required Variables
region(string) requiredAWS Region
template_url(string) requiredAmazon S3 bucket URL location of a file containing the CloudFormation template body. Maximum file size: 460,800 bytes
Optional Variables
capabilities(list(string)) optionalA list of capabilities. Valid values: CAPABILITY_IAM, CAPABILITY_NAMED_IAM, CAPABILITY_AUTO_EXPAND
Default value:
[ ]networking_stack(string) optionalLet RunsOn manage your networking stack (
embedded), or use a vpc under your control (external). Null will default to whatever the template used as default. If you selectexternal, you will need to provide the VPC ID, the subnet IDs, and optionally the security group ID, and make sure your whole networking setup is compatible with RunsOn (see https://runs-on.com/networking/embedded-vs-external/ for more details). To get started quickly, we recommend using the 'embedded' option.Default value:
"embedded"on_failure(string) optionalAction to be taken if stack creation fails. This must be one of:
DO_NOTHING,ROLLBACK, orDELETEDefault value:
"ROLLBACK"parameters(map(string)) optionalKey-value map of input parameters for the Stack Set template. (e.g. map("BusinessUnit","ABC")
Default value:
{ }policy_body(string) optionalStructure containing the stack policy body
Default value:
""security_group_id(string) optionalSecurity group ID. If not set, a new security group will be created.
Default value:
nullsecurity_group_rulesoptionalSecurity group rules. These are either added to the security passed in, or added to the security group created when var.security_group_id is not set. Types include
ingressandegress.Type:
list(object({
type = string
from_port = number
to_port = number
protocol = string
cidr_blocks = list(string)
}))Default value:
nullsubnet_ids(list(string)) optionalSubnet IDs
Default value:
nulltimeout_in_minutes(number) optionalThe amount of time that can pass before the stack status becomes
CREATE_FAILEDDefault value:
30vpc_id(string) optionalVPC ID
Default value:
null
Context Variables
The following variables are defined in the context.tf file of this module and part of the terraform-null-label pattern.
context.tf file of this module and part of the terraform-null-label pattern.additional_tag_map(map(string)) optionalAdditional key-value pairs to add to each map in
tags_as_list_of_maps. Not added totagsorid.
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.Required: No
Default value:
{ }attributes(list(string)) optionalID element. Additional attributes (e.g.
workersorcluster) to add toid,
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 thedelimiter
and treated as a single ID element.Required: No
Default value:
[ ]context(any) optionalSingle object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables asnullto use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.Required: No
Default value:
{
"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
}delimiter(string) optionalDelimiter to be used between ID elements.
Defaults to-(hyphen). Set to""to use no delimiter at all.Required: No
Default value:
nulldescriptor_formats(any) optionalDescribe additional descriptors to be output in the
descriptorsoutput map.
Map of maps. Keys are names of descriptors. Values are maps of the form
\{<br/> format = string<br/> labels = list(string)<br/> \}
(Type isanyso the map values can later be enhanced to provide additional options.)
formatis a Terraform format string to be passed to theformat()function.
labelsis a list of labels, in order, to pass toformat()function.
Label values will be normalized before being passed toformat()so they will be
identical to how they appear inid.
Default is{}(descriptorsoutput will be empty).Required: No
Default value:
{ }enabled(bool) optionalSet to false to prevent the module from creating any resources
Required: NoDefault value:
nullenvironment(string) optionalID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'
Required: NoDefault value:
nullid_length_limit(number) optionalLimit
idto this many characters (minimum 6).
Set to0for unlimited length.
Set tonullfor keep the existing setting, which defaults to0.
Does not affectid_full.Required: No
Default value:
nulllabel_key_case(string) optionalControls the letter case of the
tagskeys (label names) for tags generated by this module.
Does not affect keys of tags passed in via thetagsinput.
Possible values:lower,title,upper.
Default value:title.Required: No
Default value:
nulllabel_order(list(string)) optionalThe 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.Required: No
Default value:
nulllabel_value_case(string) optionalControls 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 thetagsinput.
Possible values:lower,title,upperandnone(no transformation).
Set this totitleand setdelimiterto""to yield Pascal Case IDs.
Default value:lower.Required: No
Default value:
nulllabels_as_tags(set(string)) optionalSet of labels (ID elements) to include as tags in the
tagsoutput.
Default is to include all labels.
Tags with empty values will not be included in thetagsoutput.
Set to[]to suppress all generated tags.
Notes:
The value of thenametag, if included, will be theid, not thename.
Unlike othernull-labelinputs, the initial setting oflabels_as_tagscannot be
changed in later chained modules. Attempts to change it will be silently ignored.Required: No
Default value:
[
"default"
]name(string) optionalID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as atag.
The "name" tag is set to the fullidstring. There is no tag with the value of thenameinput.Required: No
Default value:
nullnamespace(string) optionalID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique
Required: NoDefault value:
nullregex_replace_chars(string) optionalTerraform 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.Required: No
Default value:
nullstage(string) optionalID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'
Required: NoDefault value:
nulltags(map(string)) optionalAdditional tags (e.g.
{'BusinessUnit': 'XYZ'}).
Neither the tag keys nor the tag values will be modified by this module.Required: No
Default value:
{ }tenant(string) optionalID element (Rarely used, not included by default). A customer identifier, indicating who this instance of a resource is for
Required: NoDefault value:
null
Outputs
idID of the CloudFormation Stack
nameName of the CloudFormation Stack
nat_gateway_idsNAT Gateway IDs
nat_instance_idsNAT Instance IDs
outputsOutputs of the CloudFormation Stack
private_route_table_idsPrivate subnet route table IDs
private_subnet_idsPrivate subnet IDs
public_subnet_idsPublic subnet IDs
security_group_idSecurity group ID
vpc_cidrCIDR of the VPC created by RunsOn CloudFormation Stack
vpc_idID of the VPC created by RunsOn CloudFormation Stack
Dependencies
Requirements
terraform, version:>= 1.0.0aws, version:>= 4.9.0, < 6.0.0
Providers
aws, version:>= 4.9.0, < 6.0.0
Modules
| Name | Version | Source | Description |
|---|---|---|---|
cloudformation_stack | 0.7.1 | cloudposse/cloudformation-stack/aws | n/a |
iam_policy | 2.0.2 | cloudposse/iam-policy/aws | n/a |
iam_roles | latest | ../account-map/modules/iam-roles | n/a |
security_group | 2.2.0 | cloudposse/security-group/aws | Typically when runs-on is installed, and we're using the embedded networking stack, we need a security group. This is a batties included optional feature. |
this | 0.25.0 | cloudposse/label/null | n/a |
Resources
The following resources are used by this module:
aws_security_group_rule.this(resource)
Data Sources
The following data sources are used by this module:
aws_nat_gateways.ngws(data source)aws_subnets.private(data source)aws_subnets.public(data source)aws_vpc.this(data source)
References
- cloudposse/terraform-aws-components - Cloud Posse's upstream component