Skip to content

Commit

Permalink
feat(modules/asg): protect_from_scale_in variable
Browse files Browse the repository at this point in the history
Add `health_check_type` variable in root module for asg.
  • Loading branch information
saumitra-dev committed Jul 25, 2024
1 parent 5a49c6a commit 04d8b6d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ No resources.
|------|-------------|------|---------|:--------:|
| <a name="input_asg_create_launch_template"></a> [asg\_create\_launch\_template](#input\_asg\_create\_launch\_template) | Either to create a Launch Template to associate with the Autoscaling group | `bool` | `true` | no |
| <a name="input_asg_desired_capacity"></a> [asg\_desired\_capacity](#input\_asg\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group. | `number` | n/a | yes |
| <a name="input_asg_health_check_type"></a> [asg\_health\_check\_type](#input\_asg\_health\_check\_type) | (Optional) "EC2" or "ELB". Controls how health checking is done. | `string` | `null` | no |
| <a name="input_asg_iam_instance_profile_name"></a> [asg\_iam\_instance\_profile\_name](#input\_asg\_iam\_instance\_profile\_name) | (Optional, Forces new resource) Name of the instance profile. | `string` | `null` | no |
| <a name="input_asg_iam_instance_profile_tags"></a> [asg\_iam\_instance\_profile\_tags](#input\_asg\_iam\_instance\_profile\_tags) | (Optional) Map of resource tags for the IAM Instance Profile. | `map(string)` | `{}` | no |
| <a name="input_asg_iam_role_name"></a> [asg\_iam\_role\_name](#input\_asg\_iam\_role\_name) | (Optional, Forces new resource) Friendly name of the role. | `string` | `null` | no |
Expand All @@ -47,6 +48,7 @@ No resources.
| <a name="input_asg_max_size"></a> [asg\_max\_size](#input\_asg\_max\_size) | Maximum size of the Auto Scaling Group | `number` | n/a | yes |
| <a name="input_asg_min_size"></a> [asg\_min\_size](#input\_asg\_min\_size) | Minimum size of the Auto Scaling Group | `number` | n/a | yes |
| <a name="input_asg_name"></a> [asg\_name](#input\_asg\_name) | (Optional) Name of the Auto Scaling Group. | `string` | n/a | yes |
| <a name="input_asg_protect_from_scale_in"></a> [asg\_protect\_from\_scale\_in](#input\_asg\_protect\_from\_scale\_in) | (Optional) Whether newly launched instances are automatically protected from termination by Amazon EC2 Auto Scaling when scaling in. | `bool` | `null` | no |
| <a name="input_asg_tags"></a> [asg\_tags](#input\_asg\_tags) | Resources Tags for Autoscaling group | `map(string)` | `{}` | no |
| <a name="input_asg_vpc_zone_identifier"></a> [asg\_vpc\_zone\_identifier](#input\_asg\_vpc\_zone\_identifier) | (Optional) List of subnet IDs to launch resources in. | `list(string)` | n/a | yes |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | (Required) Name of the cluster | `string` | n/a | yes |
Expand Down
16 changes: 9 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ module "asg" {

cluster_name = module.cluster.name

name = var.asg_name
vpc_zone_identifier = var.asg_vpc_zone_identifier
desired_capacity = var.asg_desired_capacity
min_size = var.asg_min_size
max_size = var.asg_max_size
instances_tags = var.asg_instances_tags
tags = var.asg_tags
name = var.asg_name
vpc_zone_identifier = var.asg_vpc_zone_identifier
desired_capacity = var.asg_desired_capacity
min_size = var.asg_min_size
max_size = var.asg_max_size
protect_from_scale_in = var.asg_protect_from_scale_in
health_check_type = var.asg_health_check_type
instances_tags = var.asg_instances_tags
tags = var.asg_tags

# Launch Template
create_launch_template = var.asg_create_launch_template
Expand Down
1 change: 1 addition & 0 deletions modules/asg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ No modules.
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | Maximum size of the Auto Scaling Group | `number` | n/a | yes |
| <a name="input_min_size"></a> [min\_size](#input\_min\_size) | Minimum size of the Auto Scaling Group | `number` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | (Optional) Name of the Auto Scaling Group. | `string` | `null` | no |
| <a name="input_protect_from_scale_in"></a> [protect\_from\_scale\_in](#input\_protect\_from\_scale\_in) | (Optional) Whether newly launched instances are automatically protected from termination by Amazon EC2 Auto Scaling when scaling in. | `bool` | `false` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Resources Tags for Autoscaling group | `map(string)` | `{}` | no |
| <a name="input_vpc_zone_identifier"></a> [vpc\_zone\_identifier](#input\_vpc\_zone\_identifier) | (Optional) List of subnet IDs to launch resources in. | `list(string)` | `[]` | no |

Expand Down
2 changes: 1 addition & 1 deletion modules/asg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "aws_autoscaling_group" "this" {
min_size = var.min_size
max_size = var.max_size

protect_from_scale_in = false
protect_from_scale_in = var.protect_from_scale_in
health_check_type = var.health_check_type

launch_template {
Expand Down
6 changes: 6 additions & 0 deletions modules/asg/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ variable "max_size" {
type = number
}

variable "protect_from_scale_in" {
description = " (Optional) Whether newly launched instances are automatically protected from termination by Amazon EC2 Auto Scaling when scaling in."
type = bool
default = false
}

variable "health_check_type" {
description = "(Optional) \"EC2\" or \"ELB\". Controls how health checking is done."
type = string
Expand Down
15 changes: 8 additions & 7 deletions tests/asg_unit_tests.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ run "asg_attributes_match" {
variables {
cluster_name = "example-cluster-name"

name = "example-asg-name"
vpc_zone_identifier = ["subnet-12345678901234", "subnet-12345678901235"]
desired_capacity = 7
min_size = 1
max_size = 10
health_check_type = "ELB"
name = "example-asg-name"
vpc_zone_identifier = ["subnet-12345678901234", "subnet-12345678901235"]
desired_capacity = 7
min_size = 1
max_size = 10
protect_from_scale_in = true
health_check_type = "ELB"

create_launch_template = false
launch_template_id = "lt-068f72b729example"
Expand Down Expand Up @@ -65,7 +66,7 @@ run "asg_attributes_match" {
}

assert {
condition = aws_autoscaling_group.this.protect_from_scale_in == false
condition = aws_autoscaling_group.this.protect_from_scale_in == var.protect_from_scale_in
error_message = "Protect from scale in mismatch"
}

Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ variable "asg_max_size" {
}
}

variable "asg_protect_from_scale_in" {
description = " (Optional) Whether newly launched instances are automatically protected from termination by Amazon EC2 Auto Scaling when scaling in."
type = bool
default = null
}

variable "asg_health_check_type" {
description = "(Optional) \"EC2\" or \"ELB\". Controls how health checking is done."
type = string
default = null
}

variable "asg_instances_tags" {
description = "Resources Tags to propagate to the Instances"
type = map(string)
Expand Down

0 comments on commit 04d8b6d

Please sign in to comment.