Skip to content

Commit 832fc3f

Browse files
authored
Enable some variables to be externally provided to the computation module (#58)
* Add var compute_environment_additional_security_group_ids * Enable custom variables for compute environment * Remove duplicate doc entry and fix variable formatting * Remove unused data sources * Add new line at the end of file * Fix module docs
1 parent 4e56010 commit 832fc3f

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

modules/computation/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ To read more, see [the Metaflow docs](https://docs.metaflow.org/metaflow-on-aws/
1313
| Name | Description | Type | Default | Required |
1414
|------|-------------|------|---------|:--------:|
1515
| <a name="input_batch_type"></a> [batch\_type](#input\_batch\_type) | AWS Batch Compute Type ('ec2', 'fargate') | `string` | `"ec2"` | no |
16+
| <a name="input_compute_environment_additional_security_group_ids"></a> [compute\_environment\_additional\_security\_group\_ids](#input\_compute\_environment\_additional\_security\_group\_ids) | Additional security group ids to apply to the Batch Compute environment | `list(string)` | `[]` | no |
17+
| <a name="input_compute_environment_allocation_strategy"></a> [compute\_environment\_allocation\_strategy](#input\_compute\_environment\_allocation\_strategy) | Allocation strategy for Batch Compute environment (BEST\_FIT, BEST\_FIT\_PROGRESSIVE, SPOT\_CAPACITY\_OPTIMIZED) | `string` | `"BEST_FIT"` | no |
1618
| <a name="input_compute_environment_desired_vcpus"></a> [compute\_environment\_desired\_vcpus](#input\_compute\_environment\_desired\_vcpus) | Desired Starting VCPUs for Batch Compute Environment [0-16] for EC2 Batch Compute Environment (ignored for Fargate) | `number` | n/a | yes |
1719
| <a name="input_compute_environment_egress_cidr_blocks"></a> [compute\_environment\_egress\_cidr\_blocks](#input\_compute\_environment\_egress\_cidr\_blocks) | CIDR blocks to which egress is allowed from the Batch Compute environment's security group | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
1820
| <a name="input_compute_environment_instance_types"></a> [compute\_environment\_instance\_types](#input\_compute\_environment\_instance\_types) | The instance types for the compute environment as a comma-separated list | `list(string)` | n/a | yes |
@@ -22,6 +24,7 @@ To read more, see [the Metaflow docs](https://docs.metaflow.org/metaflow-on-aws/
2224
| <a name="input_launch_template_http_endpoint"></a> [launch\_template\_http\_endpoint](#input\_launch\_template\_http\_endpoint) | Whether the metadata service is available. Can be 'enabled' or 'disabled' | `string` | `"enabled"` | no |
2325
| <a name="input_launch_template_http_put_response_hop_limit"></a> [launch\_template\_http\_put\_response\_hop\_limit](#input\_launch\_template\_http\_put\_response\_hop\_limit) | The desired HTTP PUT response hop limit for instance metadata requests. Can be an integer from 1 to 64 | `number` | `2` | no |
2426
| <a name="input_launch_template_http_tokens"></a> [launch\_template\_http\_tokens](#input\_launch\_template\_http\_tokens) | Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2 (IMDSv2). Can be 'optional' or 'required' | `string` | `"optional"` | no |
27+
| <a name="input_launch_template_image_id"></a> [launch\_template\_image\_id](#input\_launch\_template\_image\_id) | AMI id for launch template, defaults to allow AWS Batch to decide | `string` | `null` | no |
2528
| <a name="input_metaflow_vpc_id"></a> [metaflow\_vpc\_id](#input\_metaflow\_vpc\_id) | ID of the Metaflow VPC this SageMaker notebook instance is to be deployed in | `string` | n/a | yes |
2629
| <a name="input_resource_prefix"></a> [resource\_prefix](#input\_resource\_prefix) | Prefix given to all AWS resources to differentiate between applications | `string` | n/a | yes |
2730
| <a name="input_resource_suffix"></a> [resource\_suffix](#input\_resource\_suffix) | Suffix given to all AWS resources to differentiate between environment and workspace | `string` | n/a | yes |

modules/computation/batch.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ resource "aws_batch_compute_environment" "this" {
3333
desired_vcpus = !local.enable_fargate_on_batch ? var.compute_environment_desired_vcpus : null
3434

3535
# Prefers cheap vCPU approaches
36-
allocation_strategy = !local.enable_fargate_on_batch ? "BEST_FIT" : null
36+
allocation_strategy = !local.enable_fargate_on_batch ? var.compute_environment_allocation_strategy : null
3737

3838
/* Links to a launch template who has more than the standard 8GB of disk space. So we can download training data.
3939
Always uses the "default version", which means we can update the Launch Template to a smaller or larger disk size
@@ -48,9 +48,9 @@ resource "aws_batch_compute_environment" "this" {
4848
}
4949

5050
# Security group to apply to the instances launched.
51-
security_group_ids = [
51+
security_group_ids = concat([
5252
aws_security_group.this.id,
53-
]
53+
], var.compute_environment_additional_security_group_ids)
5454

5555
# Which subnet to launch the instances into.
5656
subnets = [

modules/computation/data.tf

Lines changed: 0 additions & 5 deletions
This file was deleted.

modules/computation/ec2.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ resource "aws_launch_template" "cpu" {
1515
arn = aws_iam_instance_profile.ecs_instance_role.arn
1616
}
1717

18+
# Null image_id allows AWS Batch to decide.
19+
image_id = var.launch_template_image_id
20+
1821
block_device_mappings {
1922
device_name = "/dev/xvda"
2023

modules/computation/variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ variable "compute_environment_egress_cidr_blocks" {
3030
description = "CIDR blocks to which egress is allowed from the Batch Compute environment's security group"
3131
}
3232

33+
variable "compute_environment_additional_security_group_ids" {
34+
type = list(string)
35+
default = []
36+
description = "Additional security group ids to apply to the Batch Compute environment"
37+
}
38+
39+
variable "compute_environment_allocation_strategy" {
40+
type = string
41+
default = "BEST_FIT"
42+
description = "Allocation strategy for Batch Compute environment (BEST_FIT, BEST_FIT_PROGRESSIVE, SPOT_CAPACITY_OPTIMIZED)"
43+
}
44+
3345
variable "iam_partition" {
3446
type = string
3547
default = "aws"
@@ -83,3 +95,10 @@ variable "launch_template_http_put_response_hop_limit" {
8395
description = "The desired HTTP PUT response hop limit for instance metadata requests. Can be an integer from 1 to 64"
8496
default = 2
8597
}
98+
99+
variable "launch_template_image_id" {
100+
type = string
101+
description = "AMI id for launch template, defaults to allow AWS Batch to decide"
102+
nullable = true
103+
default = null
104+
}

0 commit comments

Comments
 (0)