Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for ASG maintenance_options and LT instance_requirements #193

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: Add support for ASG maintenance_options and LT `instance_requ…
…irements`
bryantbiggs committed May 14, 2022
commit b7a9ac419bd0812db8c1db93dcdff5c008f3f71a
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.64.1
rev: v1.71.0
hooks:
- id: terraform_fmt
- id: terraform_validate
@@ -23,7 +23,7 @@ repos:
- '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -214,13 +214,13 @@ Note: the default behavior of the module is to create an autoscaling group and l
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.7 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.14 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.7 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.14 |

## Modules

@@ -276,7 +276,8 @@ No modules.
| <a name="input_instance_market_options"></a> [instance\_market\_options](#input\_instance\_market\_options) | The market (purchasing) option for the instance | `any` | `{}` | no |
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | Name that is propogated to launched EC2 instances via a tag - if not provided, defaults to `var.name` | `string` | `""` | no |
| <a name="input_instance_refresh"></a> [instance\_refresh](#input\_instance\_refresh) | If this block is configured, start an Instance Refresh when this Auto Scaling Group is updated | `any` | `{}` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The type of the instance to launch | `string` | `""` | no |
| <a name="input_instance_requirements"></a> [instance\_requirements](#input\_instance\_requirements) | The attribute requirements for the type of instance. If present then `instance_type` cannot be present | `any` | `{}` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The type of the instance. If present then `instance_requirements` cannot be present | `string` | `null` | no |
| <a name="input_kernel_id"></a> [kernel\_id](#input\_kernel\_id) | The kernel ID | `string` | `null` | no |
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | The key name that should be used for the instance | `string` | `null` | no |
| <a name="input_launch_template"></a> [launch\_template](#input\_launch\_template) | Name of an existing launch template to be used (created outside of this module) | `string` | `null` | no |
@@ -286,6 +287,7 @@ No modules.
| <a name="input_launch_template_version"></a> [launch\_template\_version](#input\_launch\_template\_version) | Launch template version. Can be version number, `$Latest`, or `$Default` | `string` | `null` | no |
| <a name="input_license_specifications"></a> [license\_specifications](#input\_license\_specifications) | A list of license specifications to associate with | `map(string)` | `{}` | no |
| <a name="input_load_balancers"></a> [load\_balancers](#input\_load\_balancers) | A list of elastic load balancer names to add to the autoscaling group names. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead | `list(string)` | `[]` | no |
| <a name="input_maintenance_options"></a> [maintenance\_options](#input\_maintenance\_options) | The maintenance options for the instance | `any` | `{}` | no |
| <a name="input_max_instance_lifetime"></a> [max\_instance\_lifetime](#input\_max\_instance\_lifetime) | The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 86400 and 31536000 seconds | `number` | `null` | no |
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | The maximum size of the autoscaling group | `number` | `null` | no |
| <a name="input_metadata_options"></a> [metadata\_options](#input\_metadata\_options) | Customize the metadata options for the instance | `map(string)` | `{}` | no |
@@ -327,6 +329,7 @@ No modules.
| <a name="output_autoscaling_group_availability_zones"></a> [autoscaling\_group\_availability\_zones](#output\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
| <a name="output_autoscaling_group_default_cooldown"></a> [autoscaling\_group\_default\_cooldown](#output\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
| <a name="output_autoscaling_group_desired_capacity"></a> [autoscaling\_group\_desired\_capacity](#output\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
| <a name="output_autoscaling_group_enabled_metrics"></a> [autoscaling\_group\_enabled\_metrics](#output\_autoscaling\_group\_enabled\_metrics) | List of metrics enabled for collection |
| <a name="output_autoscaling_group_health_check_grace_period"></a> [autoscaling\_group\_health\_check\_grace\_period](#output\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
| <a name="output_autoscaling_group_health_check_type"></a> [autoscaling\_group\_health\_check\_type](#output\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
| <a name="output_autoscaling_group_id"></a> [autoscaling\_group\_id](#output\_autoscaling\_group\_id) | The autoscaling group id |
10 changes: 8 additions & 2 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
@@ -30,13 +30,13 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.7 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.14 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.7 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.14 |

## Modules

@@ -50,6 +50,8 @@ Note that this example may create resources which cost money. Run `terraform des
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../ | n/a |
| <a name="module_efa"></a> [efa](#module\_efa) | ../../ | n/a |
| <a name="module_external"></a> [external](#module\_external) | ../../ | n/a |
| <a name="module_instance_requirements"></a> [instance\_requirements](#module\_instance\_requirements) | ../../ | n/a |
| <a name="module_instance_requirements_accelerators"></a> [instance\_requirements\_accelerators](#module\_instance\_requirements\_accelerators) | ../../ | n/a |
| <a name="module_launch_template_only"></a> [launch\_template\_only](#module\_launch\_template\_only) | ../../ | n/a |
| <a name="module_mixed_instance"></a> [mixed\_instance](#module\_mixed\_instance) | ../../ | n/a |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
@@ -78,6 +80,7 @@ No inputs.
| <a name="output_complete_autoscaling_group_availability_zones"></a> [complete\_autoscaling\_group\_availability\_zones](#output\_complete\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
| <a name="output_complete_autoscaling_group_default_cooldown"></a> [complete\_autoscaling\_group\_default\_cooldown](#output\_complete\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
| <a name="output_complete_autoscaling_group_desired_capacity"></a> [complete\_autoscaling\_group\_desired\_capacity](#output\_complete\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
| <a name="output_complete_autoscaling_group_enabled_metrics"></a> [complete\_autoscaling\_group\_enabled\_metrics](#output\_complete\_autoscaling\_group\_enabled\_metrics) | List of metrics enabled for collection |
| <a name="output_complete_autoscaling_group_health_check_grace_period"></a> [complete\_autoscaling\_group\_health\_check\_grace\_period](#output\_complete\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
| <a name="output_complete_autoscaling_group_health_check_type"></a> [complete\_autoscaling\_group\_health\_check\_type](#output\_complete\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
| <a name="output_complete_autoscaling_group_id"></a> [complete\_autoscaling\_group\_id](#output\_complete\_autoscaling\_group\_id) | The autoscaling group id |
@@ -98,6 +101,7 @@ No inputs.
| <a name="output_default_autoscaling_group_availability_zones"></a> [default\_autoscaling\_group\_availability\_zones](#output\_default\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
| <a name="output_default_autoscaling_group_default_cooldown"></a> [default\_autoscaling\_group\_default\_cooldown](#output\_default\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
| <a name="output_default_autoscaling_group_desired_capacity"></a> [default\_autoscaling\_group\_desired\_capacity](#output\_default\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
| <a name="output_default_autoscaling_group_enabled_metrics"></a> [default\_autoscaling\_group\_enabled\_metrics](#output\_default\_autoscaling\_group\_enabled\_metrics) | List of metrics enabled for collection |
| <a name="output_default_autoscaling_group_health_check_grace_period"></a> [default\_autoscaling\_group\_health\_check\_grace\_period](#output\_default\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
| <a name="output_default_autoscaling_group_health_check_type"></a> [default\_autoscaling\_group\_health\_check\_type](#output\_default\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
| <a name="output_default_autoscaling_group_id"></a> [default\_autoscaling\_group\_id](#output\_default\_autoscaling\_group\_id) | The autoscaling group id |
@@ -116,6 +120,7 @@ No inputs.
| <a name="output_external_autoscaling_group_availability_zones"></a> [external\_autoscaling\_group\_availability\_zones](#output\_external\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
| <a name="output_external_autoscaling_group_default_cooldown"></a> [external\_autoscaling\_group\_default\_cooldown](#output\_external\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
| <a name="output_external_autoscaling_group_desired_capacity"></a> [external\_autoscaling\_group\_desired\_capacity](#output\_external\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
| <a name="output_external_autoscaling_group_enabled_metrics"></a> [external\_autoscaling\_group\_enabled\_metrics](#output\_external\_autoscaling\_group\_enabled\_metrics) | List of metrics enabled for collection |
| <a name="output_external_autoscaling_group_health_check_grace_period"></a> [external\_autoscaling\_group\_health\_check\_grace\_period](#output\_external\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
| <a name="output_external_autoscaling_group_health_check_type"></a> [external\_autoscaling\_group\_health\_check\_type](#output\_external\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
| <a name="output_external_autoscaling_group_id"></a> [external\_autoscaling\_group\_id](#output\_external\_autoscaling\_group\_id) | The autoscaling group id |
@@ -139,6 +144,7 @@ No inputs.
| <a name="output_mixed_instance_autoscaling_group_availability_zones"></a> [mixed\_instance\_autoscaling\_group\_availability\_zones](#output\_mixed\_instance\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
| <a name="output_mixed_instance_autoscaling_group_default_cooldown"></a> [mixed\_instance\_autoscaling\_group\_default\_cooldown](#output\_mixed\_instance\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
| <a name="output_mixed_instance_autoscaling_group_desired_capacity"></a> [mixed\_instance\_autoscaling\_group\_desired\_capacity](#output\_mixed\_instance\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
| <a name="output_mixed_instance_autoscaling_group_enabled_metrics"></a> [mixed\_instance\_autoscaling\_group\_enabled\_metrics](#output\_mixed\_instance\_autoscaling\_group\_enabled\_metrics) | List of metrics enabled for collection |
| <a name="output_mixed_instance_autoscaling_group_health_check_grace_period"></a> [mixed\_instance\_autoscaling\_group\_health\_check\_grace\_period](#output\_mixed\_instance\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
| <a name="output_mixed_instance_autoscaling_group_health_check_type"></a> [mixed\_instance\_autoscaling\_group\_health\_check\_type](#output\_mixed\_instance\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
| <a name="output_mixed_instance_autoscaling_group_id"></a> [mixed\_instance\_autoscaling\_group\_id](#output\_mixed\_instance\_autoscaling\_group\_id) | The autoscaling group id |
144 changes: 144 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -234,6 +234,10 @@ module "complete" {
market_type = "spot"
}

maintenance_options = {
auto_recovery = "default"
}

metadata_options = {
http_endpoint = "enabled"
http_tokens = "required"
@@ -489,6 +493,146 @@ module "efa" {
tags = local.tags
}


################################################################################
# Instance Requirements
################################################################################

module "instance_requirements" {
source = "../../"

# Needs https://github.com/hashicorp/terraform-provider-aws/issues/21566 for ASG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a special/searchable phrase to know that something is blocked by by certain issue upstream? In some projects (not Terraform), I sometimes use @ref or @seealso to be able to search across the whole codebase. In Terraform I usually use @todo: Fix this or that.

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in ffec352

create = false

# Autoscaling group
name = "instance-req-${local.name}"

vpc_zone_identifier = module.vpc.private_subnets
min_size = 0
max_size = 5
desired_capacity = 1

update_default_version = true
image_id = data.aws_ami.amazon_linux.id

use_mixed_instances_policy = true
instance_requirements = {

accelerator_manufacturers = []
accelerator_names = []
accelerator_types = []

baseline_ebs_bandwidth_mbps = {
min = 400
max = 1600
}

burstable_performance = "excluded"
cpu_manufacturers = ["amazon-web-services", "amd", "intel"]
excluded_instance_types = ["t*"]
instance_generations = ["current"]
local_storage_types = ["ssd", "hdd"]

memory_gib_per_vcpu = {
min = 4
max = 16
}

memory_mib = {
min = 24
max = 128
}

network_interface_count = {
min = 1
max = 16
}

vcpu_count = {
min = 2
max = 96
}
}

tags = local.tags
}

################################################################################
# Instance Requirements - Accelerators
################################################################################

module "instance_requirements_accelerators" {
source = "../../"

# Needs https://github.com/hashicorp/terraform-provider-aws/issues/21566 for ASG
# Requires access to g or p instance types in your account
# http://aws.amazon.com/contact-us/ec2-request
create = false

# Autoscaling group
name = "instance-req-accelerators-${local.name}"

vpc_zone_identifier = module.vpc.private_subnets
min_size = 0
max_size = 5
desired_capacity = 1

update_default_version = true
image_id = data.aws_ami.amazon_linux.id

use_mixed_instances_policy = true
instance_requirements = {
accelerator_count = {
min = 1
max = 8
}

accelerator_manufacturers = ["amazon-web-services", "amd", "nvidia"]
accelerator_names = ["a100", "v100", "k80", "t4", "m60", "radeon-pro-v520"]

# accelerator_total_memory_mib = {
# min = 4096
# max = 16384
# }

accelerator_types = ["gpu", "inference"]
bare_metal = "excluded"

# baseline_ebs_bandwidth_mbps = {
# min = 400
# max = 16384
# }

burstable_performance = "excluded"
cpu_manufacturers = ["amazon-web-services", "amd", "intel"]
excluded_instance_types = ["t*"]
instance_generations = ["current"]
local_storage_types = ["ssd", "hdd"]

# memory_gib_per_vcpu = {
# min = 4
# max = 16
# }

memory_mib = {
min = 24
max = 99999 # seems to be a provider bug
}

# network_interface_count = {
# min = 1
# max =4
# }

vcpu_count = {
min = 2
max = 999 # seems to be a provider bug
}
}

tags = local.tags
}

################################################################################
# Supporting Resources
################################################################################
20 changes: 20 additions & 0 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
@@ -121,6 +121,11 @@ output "default_autoscaling_group_target_group_arns" {
value = module.default.autoscaling_group_target_group_arns
}

output "default_autoscaling_group_enabled_metrics" {
description = "List of metrics enabled for collection"
value = module.default.autoscaling_group_enabled_metrics
}

################################################################################
# External
################################################################################
@@ -215,6 +220,11 @@ output "external_autoscaling_group_target_group_arns" {
value = module.external.autoscaling_group_target_group_arns
}

output "external_autoscaling_group_enabled_metrics" {
description = "List of metrics enabled for collection"
value = module.external.autoscaling_group_enabled_metrics
}

################################################################################
# Complete
################################################################################
@@ -319,6 +329,11 @@ output "complete_autoscaling_policy_arns" {
value = module.complete.autoscaling_policy_arns
}

output "complete_autoscaling_group_enabled_metrics" {
description = "List of metrics enabled for collection"
value = module.complete.autoscaling_group_enabled_metrics
}

################################################################################
# Mixed instance policy
################################################################################
@@ -412,3 +427,8 @@ output "mixed_instance_autoscaling_group_target_group_arns" {
description = "List of Target Group ARNs that apply to this AutoScaling Group"
value = module.mixed_instance.autoscaling_group_target_group_arns
}

output "mixed_instance_autoscaling_group_enabled_metrics" {
description = "List of metrics enabled for collection"
value = module.mixed_instance.autoscaling_group_enabled_metrics
}
2 changes: 1 addition & 1 deletion examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.7"
version = ">= 4.14"
}
}
}
Loading