Skip to content

Commit

Permalink
feat: added support for user defined filters (#11)
Browse files Browse the repository at this point in the history
Previously, the filters used for determining what AMIs are shown in the
frontend is hardcoded inside the lambda function. The aim of this PR is
to make it so the user can define it from the turbo module.

This PR is tied to this
[PR](frgrisk/turbo-deploy#41) in the Turbo
Deploy repository.
  • Loading branch information
luqmanbazran authored Oct 30, 2024
1 parent f39d4c0 commit 15f8160
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ While there are a few variables that can be configured through the module, the b
- ec2_attributes

By default, server sizes are automatically set but not AMIs and so you need to configure them
- image_filter_groups

The AMIs that are listed in the Turbo Deploy interface is configured through the use of filters that are used by the AWS API, you can look through the full list of filters in this [AWS documentation](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html)

## Example

Expand All @@ -94,5 +97,35 @@ module "my_turbo_module" {
ServerSizes = ["t3.medium", "t3.large", "t3.xlarge"]
Amis = ["ami-0583d8c7a9c35822c", "ami-06338d230ffc3fc0c"]
}
image_filter_groups = {
"alma-ami" = [
{
name = "is-public"
values = ["true"]
},
{
name = "name"
values = ["AlmaLinux OS*"]
},
{
name = "state"
values = ["available"]
}
]
"redhat-ami" = [
{
name = "is-public"
values = ["true"]
},
{
name = "name"
values = ["RHEL-9.4.0*"]
},
{
name = "state"
values = ["available"]
}
]
}
}
```
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ resource "aws_lambda_function" "database_lambda" {
WEBSERVER_HOSTNAME = var.turbo_deploy_hostname
WEBSERVER_HTTP_PORT = var.turbo_deploy_http_port
WEBSERVER_HTTPS_PORT = var.turbo_deploy_https_port
AMI_FILTERS = base64gzip(jsonencode(var.image_filter_groups))
}
}
}
Expand Down
27 changes: 26 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,29 @@ variable "public_key" {
description = "The default public key to be added to all deployed instances"
type = string
default = null
}
}

# filter types can be found here https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html
variable "image_filter_groups" {
description = "Filter groups for different images"
type = map(list(object({
name = string
values = list(string)
})))
default = {
"alma-ami" = [
{
name = "is-public"
values = ["true"]
},
{
name = "name"
values = ["AlmaLinux OS*"]
},
{
name = "state"
values = ["available"]
}
]
}
}

0 comments on commit 15f8160

Please sign in to comment.