Skip to content

Commit

Permalink
Autoscaling function environment variable updates (#76)
Browse files Browse the repository at this point in the history
* Added variables for setting max values for instance creation and termination

* Added information about the new variables

* Added explanation for the parameters
  • Loading branch information
eminalemdar authored Dec 1, 2023
1 parent bdc385f commit 5ed4e03
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .spacelift/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 1
module_version: 2.2.0
module_version: 2.3.0
tests:
- name: AMD64-based workerpool
project_root: examples/amd64
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ terraform {
}
module "my_workerpool" {
source = "github.com/spacelift-io/terraform-aws-spacelift-workerpool-on-ec2?ref=v2.2.0"
source = "github.com/spacelift-io/terraform-aws-spacelift-workerpool-on-ec2?ref=v2.3.0"
configuration = <<-EOT
export SPACELIFT_TOKEN="${var.worker_pool_config}"
Expand All @@ -36,6 +36,8 @@ module "my_workerpool" {

You also need to add the required values for `spacelift_api_key_endpoint`, `spacelift_api_key_id`, `spacelift_api_key_secret` and `worker_pool_id` to the module block for the Lambda Autoscaler function to set the required `SPACELIFT_API_KEY_ENDPOINT`, `SPACELIFT_API_KEY_ID`, `SPACELIFT_API_KEY_SECRET_NAME` and `SPACELIFT_WORKER_POOL_ID` parameters.

You can also set the optional `autoscaling_max_create` and `autoscaling_max_terminate` values in the module block for Lambda Autoscaler function to set the optional `AUTOSCALING_MAX_CREATE` and `AUTOSCALING_MAX_KILL` parameters. These parameters default to 1. These parameters set the maximum number of instances the utility is allowed to create or terminate in a single run.

## Default AMI

The default AMI used by this module comes from the [spacelift-worker-image](https://github.com/spacelift-io/spacelift-worker-image)
Expand Down Expand Up @@ -110,6 +112,8 @@ $ make docs
| <a name="input_ami_id"></a> [ami\_id](#input\_ami\_id) | ID of the Spacelift AMI. If left empty, the latest Spacelift AMI will be used. | `string` | `""` | no |
| <a name="input_autoscaler_architecture"></a> [autoscaler\_architecture](#input\_autoscaler\_architecture) | Instruction set architecture of the autoscaler to use | `string` | `"amd64"` | no |
| <a name="input_autoscaler_version"></a> [autoscaler\_version](#input\_autoscaler\_version) | Version of the autoscaler to deploy | `string` | `"v0.2.0"` | no |
| <a name="input_autoscaling_max_create"></a> [autoscaling\_max\_create](#input\_autoscaling\_max\_create) | The maximum number of instances the utility is allowed to create in a single run | `number` | `1` | no |
| <a name="input_autoscaling_max_terminate"></a> [autoscaling\_max\_terminate](#input\_autoscaling\_max\_terminate) | The maximum number of instances the utility is allowed to terminate in a single run | `number` | `1` | no |
| <a name="input_base_name"></a> [base\_name](#input\_base\_name) | Base name for resources. If unset, it defaults to `sp5ft-${var.worker_pool_id}`. | `string` | `null` | no |
| <a name="input_configuration"></a> [configuration](#input\_configuration) | User configuration. This allows you to decide how you want to pass your token<br> and private key to the environment - be that directly, or using SSM Parameter<br> Store, Vault etc. Ultimately, here you need to export SPACELIFT\_TOKEN and<br> SPACELIFT\_POOL\_PRIVATE\_KEY to the environment. | `string` | n/a | yes |
| <a name="input_create_iam_role"></a> [create\_iam\_role](#input\_create\_iam\_role) | Determines whether an IAM role is created or to use an existing IAM role | `bool` | `true` | no |
Expand Down
2 changes: 2 additions & 0 deletions autoscaler.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ resource "aws_lambda_function" "autoscaler" {
SPACELIFT_API_KEY_SECRET_NAME = aws_ssm_parameter.spacelift_api_key_secret[count.index].name
SPACELIFT_API_KEY_ENDPOINT = var.spacelift_api_key_endpoint
SPACELIFT_WORKER_POOL_ID = var.worker_pool_id
AUTOSCALING_MAX_CREATE = var.autoscaling_max_create
AUTOSCALING_MAX_KILL = var.autoscaling_max_terminate
}
}

Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,15 @@ variable "volume_encryption_kms_key_id" {
type = string
default = null
}

variable "autoscaling_max_create" {
description = "The maximum number of instances the utility is allowed to create in a single run"
type = number
default = 1
}

variable "autoscaling_max_terminate" {
description = "The maximum number of instances the utility is allowed to terminate in a single run"
type = number
default = 1
}

0 comments on commit 5ed4e03

Please sign in to comment.