variables.tf 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. variable "aws_region" {
  2. description = "AWS region."
  3. type = string
  4. }
  5. variable "vpc_id" {
  6. description = "The VPC for security groups of the action runners."
  7. type = string
  8. }
  9. variable "subnet_ids" {
  10. description = "List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`."
  11. type = list(string)
  12. }
  13. variable "tags" {
  14. description = "Map of tags that will be added to created resources. By default resources will be tagged with name and environment."
  15. type = map(string)
  16. default = {}
  17. }
  18. variable "environment" {
  19. description = "A name that identifies the environment, used as prefix and for tagging."
  20. type = string
  21. default = null
  22. validation {
  23. condition = var.environment == null
  24. error_message = "The \"environment\" variable is no longer used. To migrate, set the \"prefix\" variable to the original value of \"environment\" and optionally, add \"Environment\" to the \"tags\" variable map with the same value."
  25. }
  26. }
  27. variable "prefix" {
  28. description = "The prefix used for naming resources"
  29. type = string
  30. default = "github-actions"
  31. }
  32. variable "enable_organization_runners" {
  33. description = "Register runners to organization, instead of repo level"
  34. type = bool
  35. default = false
  36. }
  37. variable "github_app" {
  38. description = "GitHub app parameters, see your github app. Ensure the key is the base64-encoded `.pem` file (the output of `base64 app.private-key.pem`, not the content of `private-key.pem`)."
  39. type = object({
  40. key_base64 = string
  41. id = string
  42. webhook_secret = string
  43. })
  44. }
  45. variable "scale_down_schedule_expression" {
  46. description = "Scheduler expression to check every x for scale down."
  47. type = string
  48. default = "cron(*/5 * * * ? *)"
  49. }
  50. variable "minimum_running_time_in_minutes" {
  51. description = "The time an ec2 action runner should be running at minimum before terminated if not busy."
  52. type = number
  53. default = null
  54. }
  55. variable "runner_boot_time_in_minutes" {
  56. description = "The minimum time for an EC2 runner to boot and register as a runner."
  57. type = number
  58. default = 5
  59. }
  60. variable "runner_extra_labels" {
  61. description = "Extra (custom) labels for the runners (GitHub). Separate each label by a comma. Labels checks on the webhook can be enforced by setting `enable_workflow_job_labels_check`. GitHub read-only labels should not be provided."
  62. type = string
  63. default = ""
  64. }
  65. variable "runner_group_name" {
  66. description = "Name of the runner group."
  67. type = string
  68. default = "Default"
  69. }
  70. variable "scale_up_reserved_concurrent_executions" {
  71. description = "Amount of reserved concurrent executions for the scale-up lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations."
  72. type = number
  73. default = 1
  74. }
  75. variable "webhook_lambda_zip" {
  76. description = "File location of the webhook lambda zip file."
  77. type = string
  78. default = null
  79. }
  80. variable "webhook_lambda_timeout" {
  81. description = "Time out of the webhook lambda in seconds."
  82. type = number
  83. default = 10
  84. }
  85. variable "runners_lambda_zip" {
  86. description = "File location of the lambda zip file for scaling runners."
  87. type = string
  88. default = null
  89. }
  90. variable "runners_scale_up_lambda_timeout" {
  91. description = "Time out for the scale up lambda in seconds."
  92. type = number
  93. default = 30
  94. }
  95. variable "runners_scale_down_lambda_timeout" {
  96. description = "Time out for the scale down lambda in seconds."
  97. type = number
  98. default = 60
  99. }
  100. variable "runner_binaries_syncer_lambda_zip" {
  101. description = "File location of the binaries sync lambda zip file."
  102. type = string
  103. default = null
  104. }
  105. variable "runner_binaries_syncer_lambda_timeout" {
  106. description = "Time out of the binaries sync lambda in seconds."
  107. type = number
  108. default = 300
  109. }
  110. variable "runner_binaries_s3_sse_configuration" {
  111. description = "Map containing server-side encryption configuration for runner-binaries S3 bucket."
  112. type = any
  113. default = {}
  114. }
  115. variable "role_permissions_boundary" {
  116. description = "Permissions boundary that will be added to the created roles."
  117. type = string
  118. default = null
  119. }
  120. variable "role_path" {
  121. description = "The path that will be added to role path for created roles, if not set the environment name will be used."
  122. type = string
  123. default = null
  124. }
  125. variable "instance_profile_path" {
  126. description = "The path that will be added to the instance_profile, if not set the environment name will be used."
  127. type = string
  128. default = null
  129. }
  130. variable "runner_as_root" {
  131. description = "Run the action runner under the root user. Variable `runner_run_as` will be ingored."
  132. type = bool
  133. default = false
  134. }
  135. variable "runner_run_as" {
  136. description = "Run the GitHub actions agent as user."
  137. type = string
  138. default = "ec2-user"
  139. }
  140. variable "runners_maximum_count" {
  141. description = "The maximum number of runners that will be created."
  142. type = number
  143. default = 3
  144. }
  145. variable "kms_key_arn" {
  146. description = "Optional CMK Key ARN to be used for Parameter Store. This key must be in the current account."
  147. type = string
  148. default = null
  149. }
  150. variable "enable_runner_detailed_monitoring" {
  151. description = "Should detailed monitoring be enabled for the runner. Set this to true if you want to use detailed monitoring. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html for details."
  152. type = bool
  153. default = false
  154. }
  155. variable "enabled_userdata" {
  156. description = "Should the userdata script be enabled for the runner. Set this to false if you are using your own prebuilt AMI."
  157. type = bool
  158. default = true
  159. }
  160. variable "userdata_template" {
  161. description = "Alternative user-data template, replacing the default template. By providing your own user_data you have to take care of installing all required software, including the action runner. Variables userdata_pre/post_install are ignored."
  162. type = string
  163. default = null
  164. }
  165. variable "userdata_pre_install" {
  166. type = string
  167. default = ""
  168. description = "Script to be ran before the GitHub Actions runner is installed on the EC2 instances"
  169. }
  170. variable "userdata_post_install" {
  171. type = string
  172. default = ""
  173. description = "Script to be ran after the GitHub Actions runner is installed on the EC2 instances"
  174. }
  175. variable "idle_config" {
  176. description = "List of time period that can be defined as cron expression to keep a minimum amount of runners active instead of scaling down to 0. By defining this list you can ensure that in time periods that match the cron expression within 5 seconds a runner is kept idle."
  177. type = list(object({
  178. cron = string
  179. timeZone = string
  180. idleCount = number
  181. }))
  182. default = []
  183. }
  184. variable "enable_ssm_on_runners" {
  185. description = "Enable to allow access the runner instances for debugging purposes via SSM. Note that this adds additional permissions to the runner instances."
  186. type = bool
  187. default = false
  188. }
  189. variable "logging_retention_in_days" {
  190. description = "Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653."
  191. type = number
  192. default = 180
  193. }
  194. variable "logging_kms_key_id" {
  195. description = "Specifies the kms key id to encrypt the logs with"
  196. type = string
  197. default = null
  198. }
  199. variable "runner_allow_prerelease_binaries" {
  200. description = "Allow the runners to update to prerelease binaries."
  201. type = bool
  202. default = false
  203. }
  204. variable "block_device_mappings" {
  205. description = "The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops`"
  206. type = list(object({
  207. device_name = string
  208. delete_on_termination = bool
  209. volume_type = string
  210. volume_size = number
  211. encrypted = bool
  212. iops = number
  213. }))
  214. default = [{
  215. device_name = "/dev/xvda"
  216. delete_on_termination = true
  217. volume_type = "gp3"
  218. volume_size = 30
  219. encrypted = true
  220. iops = null
  221. }]
  222. }
  223. variable "ami_filter" {
  224. description = "List of maps used to create the AMI filter for the action runner AMI. By default amazon linux 2 is used."
  225. type = map(list(string))
  226. default = null
  227. }
  228. variable "ami_owners" {
  229. description = "The list of owners used to select the AMI of action runner instances."
  230. type = list(string)
  231. default = ["amazon"]
  232. }
  233. variable "lambda_s3_bucket" {
  234. description = "S3 bucket from which to specify lambda functions. This is an alternative to providing local files directly."
  235. default = null
  236. }
  237. variable "syncer_lambda_s3_key" {
  238. description = "S3 key for syncer lambda function. Required if using S3 bucket to specify lambdas."
  239. default = null
  240. }
  241. variable "syncer_lambda_s3_object_version" {
  242. description = "S3 object version for syncer lambda function. Useful if S3 versioning is enabled on source bucket."
  243. default = null
  244. }
  245. variable "webhook_lambda_s3_key" {
  246. description = "S3 key for webhook lambda function. Required if using S3 bucket to specify lambdas."
  247. default = null
  248. }
  249. variable "webhook_lambda_s3_object_version" {
  250. description = "S3 object version for webhook lambda function. Useful if S3 versioning is enabled on source bucket."
  251. default = null
  252. }
  253. variable "runners_lambda_s3_key" {
  254. description = "S3 key for runners lambda function. Required if using S3 bucket to specify lambdas."
  255. default = null
  256. }
  257. variable "runners_lambda_s3_object_version" {
  258. description = "S3 object version for runners lambda function. Useful if S3 versioning is enabled on source bucket."
  259. default = null
  260. }
  261. variable "create_service_linked_role_spot" {
  262. description = "(optional) create the serviced linked role for spot instances that is required by the scale-up lambda."
  263. type = bool
  264. default = false
  265. }
  266. variable "runner_iam_role_managed_policy_arns" {
  267. description = "Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role"
  268. type = list(string)
  269. default = []
  270. }
  271. variable "enable_cloudwatch_agent" {
  272. description = "Enabling the cloudwatch agent on the ec2 runner instances, the runner contains default config. Configuration can be overridden via `cloudwatch_config`."
  273. type = bool
  274. default = true
  275. }
  276. variable "cloudwatch_config" {
  277. description = "(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."
  278. type = string
  279. default = null
  280. }
  281. variable "runner_log_files" {
  282. description = "(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."
  283. type = list(object({
  284. log_group_name = string
  285. prefix_log_group = bool
  286. file_path = string
  287. log_stream_name = string
  288. }))
  289. default = null
  290. }
  291. variable "ghes_url" {
  292. description = "GitHub Enterprise Server URL. Example: https://github.internal.co - DO NOT SET IF USING PUBLIC GITHUB"
  293. type = string
  294. default = null
  295. }
  296. variable "ghes_ssl_verify" {
  297. description = "GitHub Enterprise SSL verification. Set to 'false' when custom certificate (chains) is used for GitHub Enterprise Server (insecure)."
  298. type = bool
  299. default = true
  300. }
  301. variable "lambda_subnet_ids" {
  302. description = "List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`."
  303. type = list(string)
  304. default = []
  305. }
  306. variable "lambda_security_group_ids" {
  307. description = "List of security group IDs associated with the Lambda function."
  308. type = list(string)
  309. default = []
  310. }
  311. variable "key_name" {
  312. description = "Key pair name"
  313. type = string
  314. default = null
  315. }
  316. variable "runner_additional_security_group_ids" {
  317. description = "(optional) List of additional security groups IDs to apply to the runner"
  318. type = list(string)
  319. default = []
  320. }
  321. variable "market_options" {
  322. description = "DEPCRECATED: Replaced by `instance_target_capacity_type`."
  323. type = string
  324. default = null
  325. validation {
  326. condition = anytrue([var.market_options == null])
  327. error_message = "Deprecated, replaced by `instance_target_capacity_type`."
  328. }
  329. }
  330. variable "instance_target_capacity_type" {
  331. description = "Default lifecycle used for runner instances, can be either `spot` or `on-demand`."
  332. type = string
  333. default = "spot"
  334. validation {
  335. condition = contains(["spot", "on-demand"], var.instance_target_capacity_type)
  336. error_message = "The instance target capacity should be either spot or on-demand."
  337. }
  338. }
  339. variable "instance_allocation_strategy" {
  340. description = "The allocation strategy for spot instances. AWS recommends to use `capacity-optimized` however the AWS default is `lowest-price`."
  341. type = string
  342. default = "lowest-price"
  343. validation {
  344. condition = contains(["lowest-price", "diversified", "capacity-optimized", "capacity-optimized-prioritized"], var.instance_allocation_strategy)
  345. error_message = "The instance allocation strategy does not match the allowed values."
  346. }
  347. }
  348. variable "instance_max_spot_price" {
  349. description = "Max price price for spot intances per hour. This variable will be passed to the create fleet as max spot price for the fleet."
  350. type = string
  351. default = null
  352. }
  353. variable "instance_type" {
  354. description = "[DEPRECATED] See instance_types."
  355. type = string
  356. default = null
  357. validation {
  358. condition = anytrue([var.instance_type == null])
  359. error_message = "Deprecated, replaced by `instance_types`."
  360. }
  361. }
  362. variable "instance_types" {
  363. description = "List of instance types for the action runner. Defaults are based on runner_os (amzn2 for linux and Windows Server Core for win)."
  364. type = list(string)
  365. default = ["m5.large", "c5.large"]
  366. }
  367. variable "repository_white_list" {
  368. description = "List of repositories allowed to use the github app"
  369. type = list(string)
  370. default = []
  371. }
  372. variable "delay_webhook_event" {
  373. description = "The number of seconds the event accepted by the webhook is invisible on the queue before the scale up lambda will receive the event."
  374. type = number
  375. default = 30
  376. }
  377. variable "job_queue_retention_in_seconds" {
  378. description = "The number of seconds the job is held in the queue before it is purged"
  379. type = number
  380. default = 86400
  381. }
  382. variable "runner_egress_rules" {
  383. description = "List of egress rules for the GitHub runner instances."
  384. type = list(object({
  385. cidr_blocks = list(string)
  386. ipv6_cidr_blocks = list(string)
  387. prefix_list_ids = list(string)
  388. from_port = number
  389. protocol = string
  390. security_groups = list(string)
  391. self = bool
  392. to_port = number
  393. description = string
  394. }))
  395. default = [{
  396. cidr_blocks = ["0.0.0.0/0"]
  397. ipv6_cidr_blocks = ["::/0"]
  398. prefix_list_ids = null
  399. from_port = 0
  400. protocol = "-1"
  401. security_groups = null
  402. self = null
  403. to_port = 0
  404. description = null
  405. }]
  406. }
  407. variable "log_type" {
  408. description = "Logging format for lambda logging. Valid values are 'json', 'pretty', 'hidden'. "
  409. type = string
  410. default = "pretty"
  411. validation {
  412. condition = anytrue([
  413. var.log_type == "json",
  414. var.log_type == "pretty",
  415. var.log_type == "hidden",
  416. ])
  417. error_message = "`log_type` value not valid. Valid values are 'json', 'pretty', 'hidden'."
  418. }
  419. }
  420. variable "log_level" {
  421. description = "Logging level for lambda logging. Valid values are 'silly', 'trace', 'debug', 'info', 'warn', 'error', 'fatal'."
  422. type = string
  423. default = "info"
  424. validation {
  425. condition = anytrue([
  426. var.log_level == "silly",
  427. var.log_level == "trace",
  428. var.log_level == "debug",
  429. var.log_level == "info",
  430. var.log_level == "warn",
  431. var.log_level == "error",
  432. var.log_level == "fatal",
  433. ])
  434. error_message = "`log_level` value not valid. Valid values are 'silly', 'trace', 'debug', 'info', 'warn', 'error', 'fatal'."
  435. }
  436. }
  437. variable "runner_enable_workflow_job_labels_check" {
  438. description = "If set to true all labels in the workflow job even are matched agaist the custom labels and GitHub labels (os, architecture and `self-hosted`). When the labels are not matching the event is dropped at the webhook."
  439. type = bool
  440. default = false
  441. }
  442. variable "runner_enable_workflow_job_labels_check_all" {
  443. description = "If set to true all labels in the workflow job must match the GitHub labels (os, architecture and `self-hosted`). When false if __any__ label matches it will trigger the webhook. `runner_enable_workflow_job_labels_check` must be true for this to take effect."
  444. type = bool
  445. default = true
  446. }
  447. variable "runner_ec2_tags" {
  448. description = "Map of tags that will be added to the launch template instance tag specificatons."
  449. type = map(string)
  450. default = {}
  451. }
  452. variable "runner_metadata_options" {
  453. description = "Metadata options for the ec2 runner instances."
  454. type = map(any)
  455. default = {
  456. http_endpoint = "enabled"
  457. http_tokens = "optional"
  458. http_put_response_hop_limit = 1
  459. }
  460. }
  461. variable "enable_ephemeral_runners" {
  462. description = "Enable ephemeral runners, runners will only be used once."
  463. type = bool
  464. default = false
  465. }
  466. variable "enable_job_queued_check" {
  467. description = "Only scale if the job event received by the scale up lambda is is in the state queued. By default enabled for non ephemeral runners and disabled for ephemeral. Set this variable to overwrite the default behavior."
  468. type = bool
  469. default = null
  470. }
  471. variable "enable_managed_runner_security_group" {
  472. description = "Enabling the default managed security group creation. Unmanaged security groups can be specified via `runner_additional_security_group_ids`."
  473. type = bool
  474. default = true
  475. }
  476. variable "runner_os" {
  477. description = "The EC2 Operating System type to use for action runner instances (linux,windows)."
  478. type = string
  479. default = "linux"
  480. validation {
  481. condition = contains(["linux", "windows"], var.runner_os)
  482. error_message = "Valid values for runner_os are (linux, windows)."
  483. }
  484. }
  485. variable "lambda_principals" {
  486. description = "(Optional) add extra principals to the role created for execution of the lambda, e.g. for local testing."
  487. type = list(object({
  488. type = string
  489. identifiers = list(string)
  490. }))
  491. default = []
  492. }
  493. variable "fifo_build_queue" {
  494. description = "Enable a FIFO queue to remain the order of events received by the webhook. Suggest to set to true for repo level runners."
  495. type = bool
  496. default = false
  497. }
  498. variable "redrive_build_queue" {
  499. description = "Set options to attach (optional) a dead letter queue to the build queue, the queue between the webhook and the scale up lambda. You have the following options. 1. Disable by setting, `enalbed' to false. 2. Enable by setting `enabled` to `true`, `maxReceiveCount` to a number of max retries."
  500. type = object({
  501. enabled = bool
  502. maxReceiveCount = number
  503. })
  504. default = {
  505. enabled = false
  506. maxReceiveCount = null
  507. }
  508. validation {
  509. condition = var.redrive_build_queue.enabled && var.redrive_build_queue.maxReceiveCount != null || !var.redrive_build_queue.enabled
  510. error_message = "Ensure you have set the maxReceiveCount when enabled."
  511. }
  512. }
  513. variable "runner_architecture" {
  514. description = "The platform architecture of the runner instance_type."
  515. type = string
  516. default = "x64"
  517. validation {
  518. condition = contains(["x64", "arm64"], var.runner_architecture)
  519. error_message = "`runner_architecture` value not valid, valid values are: `x64` and `arm64`."
  520. }
  521. }
  522. variable "pool_lambda_timeout" {
  523. description = "Time out for the pool lambda lambda in seconds."
  524. type = number
  525. default = 60
  526. }
  527. variable "pool_runner_owner" {
  528. description = "The pool will deploy runners to the GitHub org ID, set this value to the org to which you want the runners deployed. Repo level is not supported."
  529. type = string
  530. default = null
  531. }
  532. variable "pool_lambda_reserved_concurrent_executions" {
  533. description = "Amount of reserved concurrent executions for the scale-up lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations."
  534. type = number
  535. default = 1
  536. }
  537. variable "pool_config" {
  538. description = "The configuration for updating the pool. The `pool_size` to adjust to by the events triggered by the 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."
  539. type = list(object({
  540. schedule_expression = string
  541. size = number
  542. }))
  543. default = []
  544. }
  545. variable "aws_partition" {
  546. description = "(optiona) partition in the arn namespace to use if not 'aws'"
  547. type = string
  548. default = "aws"
  549. }
  550. variable "disable_runner_autoupdate" {
  551. description = "Disable the auto update of the github runner agent. Be-aware there is a grace period of 30 days, see also the [GitHub article](https://github.blog/changelog/2022-02-01-github-actions-self-hosted-runners-can-now-disable-automatic-updates/)"
  552. type = bool
  553. default = false
  554. }
  555. variable "lambda_runtime" {
  556. description = "AWS Lambda runtime."
  557. type = string
  558. default = "nodejs16.x"
  559. }
  560. variable "lambda_architecture" {
  561. description = "AWS Lambda architecture. Lambda functions using Graviton processors ('arm64') tend to have better price/performance than 'x86_64' functions. "
  562. type = string
  563. default = "x86_64"
  564. validation {
  565. condition = contains(["arm64", "x86_64"], var.lambda_architecture)
  566. error_message = "`lambda_architecture` value is not valid, valid values are: `arm64` and `x86_64`."
  567. }
  568. }