Skip to content

Commit

Permalink
feat: Spacelift worker pool enhancements (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
RoseSecurity authored May 6, 2024
1 parent 86035c3 commit ee59fd8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion modules/spacelift/worker-pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ role. This is done by adding `iam_role_arn` from the output to the `trusted_role
| <a name="input_account_map_stage_name"></a> [account\_map\_stage\_name](#input\_account\_map\_stage\_name) | The name of the stage where `account_map` is provisioned | `string` | `"root"` | no |
| <a name="input_account_map_tenant_name"></a> [account\_map\_tenant\_name](#input\_account\_map\_tenant\_name) | The name of the tenant where `account_map` is provisioned.<br><br>If the `tenant` label is not used, leave this as `null`. | `string` | `null` | no |
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
| <a name="input_architecture"></a> [architecture](#input\_architecture) | OS architecture of the EC2 instance AMI | `list(string)` | <pre>[<br> "x86_64"<br>]</pre> | no |
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
| <a name="input_aws_config_file"></a> [aws\_config\_file](#input\_aws\_config\_file) | The AWS\_CONFIG\_FILE used by the worker. Can be overridden by `/.spacelift/config.yml`. | `string` | `"/etc/aws-config/aws-config-spacelift"` | no |
| <a name="input_aws_profile"></a> [aws\_profile](#input\_aws\_profile) | The AWS\_PROFILE used by the worker. If not specified, `"${var.namespace}-identity"` will be used.<br>Can be overridden by `/.spacelift/config.yml`. | `string` | `null` | no |
Expand Down Expand Up @@ -205,13 +206,14 @@ role. This is done by adding `iam_role_arn` from the output to the `trusted_role
| <a name="input_infracost_cli_args"></a> [infracost\_cli\_args](#input\_infracost\_cli\_args) | These are the CLI args passed to infracost | `string` | `""` | no |
| <a name="input_infracost_enabled"></a> [infracost\_enabled](#input\_infracost\_enabled) | Whether to enable infracost for Spacelift stacks | `bool` | `false` | no |
| <a name="input_infracost_warn_on_failure"></a> [infracost\_warn\_on\_failure](#input\_infracost\_warn\_on\_failure) | A failure executing Infracost, or a non-zero exit code being returned from the command will cause runs to fail. If this is true, this will only warn instead of failing the stack. | `bool` | `true` | no |
| <a name="input_instance_lifetime"></a> [instance\_lifetime](#input\_instance\_lifetime) | Number of seconds after which the instance will be terminated. The default is set to 14 days. | `number` | `1209600` | no |
| <a name="input_instance_refresh"></a> [instance\_refresh](#input\_instance\_refresh) | The instance refresh definition. If this block is configured, an Instance Refresh will be started when the Auto Scaling Group is updated | <pre>object({<br> strategy = string<br> preferences = object({<br> instance_warmup = optional(number, null)<br> min_healthy_percentage = optional(number, null)<br> skip_matching = optional(bool, null)<br> auto_rollback = optional(bool, null)<br> })<br> triggers = optional(list(string), [])<br> })</pre> | `null` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | EC2 instance type to use for workers | `string` | `"r5n.large"` | no |
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br>Does not affect keys of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
| <a name="input_launch_template_version"></a> [launch\_template\_version](#input\_launch\_template\_version) | Launch template version to use for workers | `string` | `"$Latest"` | no |
| <a name="input_launch_template_version"></a> [launch\_template\_version](#input\_launch\_template\_version) | Launch template version to use for workers. Note that instance refresh settings are IGNORED unless template version is empty | `string` | `"$Latest"` | no |
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | The maximum size of the autoscale group | `number` | n/a | yes |
| <a name="input_min_size"></a> [min\_size](#input\_min\_size) | The minimum size of the autoscale group | `number` | n/a | yes |
| <a name="input_mixed_instances_policy"></a> [mixed\_instances\_policy](#input\_mixed\_instances\_policy) | Policy to use a mixed group of on-demand/spot of different types. Launch template is automatically generated. https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#mixed_instances_policy-1 | <pre>object({<br> instances_distribution = object({<br> on_demand_allocation_strategy = string<br> on_demand_base_capacity = number<br> on_demand_percentage_above_base_capacity = number<br> spot_allocation_strategy = string<br> spot_instance_pools = number<br> spot_max_price = string<br> })<br> override = list(object({<br> instance_type = string<br> weighted_capacity = number<br> }))<br> })</pre> | `null` | no |
Expand Down
2 changes: 1 addition & 1 deletion modules/spacelift/worker-pool/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ data "aws_ami" "spacelift" {

filter {
name = "architecture"
values = ["x86_64"]
values = var.architecture
}
}
7 changes: 3 additions & 4 deletions modules/spacelift/worker-pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ module "autoscale_group" {
cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent
cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent

max_instance_lifetime = var.instance_lifetime

# The instance refresh definition
# If this block is configured, an Instance Refresh will be started when the Auto Scaling Group is updated
instance_refresh = var.instance_refresh
# Note: instance refresh settings are IGNORED unless template version is empty
# See the second "NOTE" in the "instance_refresh" documentation
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#instance_refresh
instance_refresh = var.instance_refresh
launch_template_version = var.instance_refresh == null ? "$Latest" : ""

context = module.this.context
Expand Down
14 changes: 13 additions & 1 deletion modules/spacelift/worker-pool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ variable "cpu_utilization_low_threshold_percent" {
description = "CPU utilization low threshold"
}

variable "instance_lifetime" {
type = number
default = 1209600
description = "Number of seconds after which the instance will be terminated. The default is set to 14 days."
}

variable "default_cooldown" {
type = number
description = "The amount of time, in seconds, after a scaling activity completes before another scaling activity can start"
Expand Down Expand Up @@ -196,6 +202,12 @@ variable "custom_spacelift_ami" {
default = false
}

variable "architecture" {
type = list(string)
description = "OS architecture of the EC2 instance AMI"
default = ["x86_64"]
}

variable "spacelift_domain_name" {
type = string
description = "Top-level domain name to use for pulling the launcher binary"
Expand All @@ -210,7 +222,7 @@ variable "iam_attributes" {

variable "launch_template_version" {
type = string
description = "Launch template version to use for workers"
description = "Launch template version to use for workers. Note that instance refresh settings are IGNORED unless template version is empty"
default = "$Latest"
}

Expand Down

0 comments on commit ee59fd8

Please sign in to comment.