8000 feat(modules/asg): `protect_from_scale_in` variable · infraspecdev/terraform-aws-ecs@04d8b6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 04d8b6d

Browse files
committed
feat(modules/asg): protect_from_scale_in variable
Add `health_check_type` variable in root module for asg.
1 parent 5a49c6a commit 04d8b6d

File tree

7 files changed

+39
-15
lines changed

7 files changed

+39
-15
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ No resources.
3535
|------|-------------|------|---------|:--------:|
3636
| <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 |
3737
| <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 |
38+
| <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 |
3839
| <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 |
3940
| <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 |
4041
| <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 |
@@ -47,6 +48,7 @@ No resources.
4748
| <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 |
4849
| <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 |
4950
| <a name="input_asg_name"></a> [asg\_name](#input\_asg\_name) | (Optional) Name of the Auto Scaling Group. | `string` | n/a | yes |
51+
| <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 |
5052
| <a name="input_asg_tags"></a> [asg\_tags](#input\_asg\_tags) | Resources Tags for Autoscaling group | `map(string)` | `{}` | no |
5153
| <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 |
5254
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | (Required) Name of the cluster | `string` | n/a | yes |

main.tf

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ module "asg" {
2020

2121
cluster_name = module.cluster.name
2222

23-
name = var.asg_name
24-
vpc_zone_identifier = var.asg_vpc_zone_identifier
25-
desired_capacity = var.asg_desired_capacity
26-
min_size = var.asg_min_size
27-
max_size = var.asg_max_size
28-
instances_tags = var.asg_instances_tags
29-
tags = var.asg_tags
23+
name = var.asg_name
24+
vpc_zone_identifier = var.asg_vpc_zone_identifier
25+
desired_capacity = var.asg_desired_capacity
26+
min_size = var.asg_min_size
27+
max_size = var.asg_max_size
28+
protect_from_scale_in = var.asg_protect_from_scale_in
29+
health_check_type = var.asg_health_check_type
30+
instances_tags = var.asg_instances_tags
31+
tags = var.asg_tags
3032

3133
# Launch Template
3234
create_launch_template = var.asg_create_launch_template

modules/asg/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ No modules.
4949
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | Maximum size of the Auto Scaling Group | `number` | n/a | yes |
5050
| <a name="input_min_size"></a> [min\_size](#input\_min\_size) | Minimum size of the Auto Scaling Group | `number` | n/a | yes |
5151
| <a name="input_name"></a> [name](#input\_name) | (Optional) Name of the Auto Scaling Group. | `string` | `null` | no |
52+
| <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 |
5253
| <a name="input_tags"></a> [tags](#input\_tags) | Resources Tags for Autoscaling group | `map(string)` | `{}` | no |
5354
| <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 |
5455

modules/asg/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resource "aws_autoscaling_group" "this" {
66
min_size = var.min_size
77
max_size = var.max_size
88

9-
protect_from_scale_in = false
9+
protect_from_scale_in = var.protect_from_scale_in
1010
health_check_type = var.health_check_type
1111

1212
launch_template {

modules/asg/variables.tf

Lines changed: 6 additions & 0 deletions
36
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ variable "max_size" {
3030
type = number
3131
}
3232

33+
variable "protect_from_scale_in" {
34+
description = " (Optional) Whether newly launched instances are automatically protected from termination by Amazon EC2 Auto Scaling when scaling in."
35+
type = bool
+
default = false
37+
}
38+
3339
variable "health_check_type" {
3440
description = "(Optional) \"EC2\" or \"ELB\". Controls how health checking is done."
3541
type = string

tests/asg_unit_tests.tftest.hcl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ run "asg_attributes_match" {
1616
variables {
1717
cluster_name = "example-cluster-name"
1818

19-
name = "example-asg-name"
20-
vpc_zone_identifier = ["subnet-12345678901234", "subnet-12345678901235"]
21-
desired_capacity = 7
22-
min_size = 1
23-
max_size = 10
24-
health_check_type = "ELB"
19+
name = "example-asg-name"
20+
vpc_zone_identifier = ["subnet-12345678901234", "subnet-12345678901235"]
21+
desired_capacity = 7
22+
min_size = 1
23+
max_size = 10
24+
protect_from_scale_in = true
25+
health_check_type = "ELB"
2526

2627
create_launch_template = false
2728
launch_template_id = "lt-068f72b729example"
@@ -65,7 +66,7 @@ run "asg_attributes_match" {
6566
}
6667

6768
assert {
68-
condition = aws_autoscaling_group.this.protect_from_scale_in == false
69+
condition = aws_autoscaling_group.this.protect_from_scale_in == var.protect_from_scale_in
6970
error_message = "Protect from scale in mismatch"
7071
}
7172

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ variable "asg_max_size" {
7373
}
7474
}
7575

76+
variable "asg_protect_from_scale_in" {
77+
description = " (Optional) Whether newly launched instances are automatically protected from termination by Amazon EC2 Auto Scaling when scaling in."
78+
type = bool
79+
default = null
80+
}
81+
82+
variable "asg_health_check_type" {
83+
description = "(Optional) \"EC2\" or \"ELB\". Controls how health checking is done."
84+
type = string
85+
default = null
86+
}
87+
7688
variable "asg_instances_tags" {
7789
description = "Resources Tags to propagate to the Instances"
7890
type = map(string)

0 commit comments

Comments
 (0)
0