Skip to content

Commit dc1c123

Browse files
committed
refactor(modules/asg)!: remove unneeded configuration from block device mappings
1 parent 0b9ee11 commit dc1c123

File tree

6 files changed

+28
-31
lines changed

6 files changed

+28
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ No resources.
4141
| <a name="input_asg_iam_role_policy_attachments"></a> [asg\_iam\_role\_policy\_attachments](#input\_asg\_iam\_role\_policy\_attachments) | (Required) - The ARN of the policy you want to apply | `list(string)` | <pre>[<br> "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"<br>]</pre> | no |
4242
| <a name="input_asg_iam_role_tags"></a> [asg\_iam\_role\_tags](#input\_asg\_iam\_role\_tags) | Key-value mapping of tags for the IAM role. | `map(string)` | `{}` | no |
4343
| <a name="input_asg_instances_tags"></a> [asg\_instances\_tags](#input\_asg\_instances\_tags) | Resources Tags to propagate to the Instances | `map(string)` | `{}` | no |
44-
| <a name="input_asg_launch_template"></a> [asg\_launch\_template](#input\_asg\_launch\_template) | Launch Template to use with the Autoscaling group | <pre>object({<br> name = optional(string, null)<br> block_device_mappings = optional(list(object({<br> device_name = string<br> ebs = optional(object({<br> delete_on_termination = optional(bool, null)<br> encrypted = optional(any, null)<br> iops = optional(any, null)<br> kms_key_id = optional(string, null)<br> snapshot_id = optional(string, null)<br> throughput = optional(any, null)<br> volume_size = optional(number, null)<br> volume_type = optional(string, null)<br> }))<br> no_device = optional(any, null)<br> virtual_name = optional(string, null)<br> })), [])<br> image_id = optional(string, null)<br> instance_type = optional(string, null)<br> vpc_security_group_ids = optional(list(string), [])<br> key_name = optional(string, null)<br> user_data = optional(string, null)<br> tags = optional(map(string), {})<br> })</pre> | `{}` | no |
44+
| <a name="input_asg_launch_template"></a> [asg\_launch\_template](#input\_asg\_launch\_template) | Launch Template to use with the Autoscaling group | <pre>object({<br> name = optional(string, null)<br> block_device_mappings = optional(list(object({<br> device_name = string<br> ebs = optional(object({<br> delete_on_termination = optional(bool, null)<br> snapshot_id = optional(string, null)<br> volume_size = optional(number, null)<br> volume_type = optional(string, null)<br> }))<br> no_device = optional(any, null)<br> virtual_name = optional(string, null)<br> })), [])<br> image_id = optional(string, null)<br> instance_type = optional(string, null)<br> vpc_security_group_ids = optional(list(string), [])<br> key_name = optional(string, null)<br> user_data = optional(string, null)<br> tags = optional(map(string), {})<br> })</pre> | `{}` | no |
4545
| <a name="input_asg_launch_template_id"></a> [asg\_launch\_template\_id](#input\_asg\_launch\_template\_id) | Identifier of the Launch Template | `string` | `null` | no |
4646
| <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 |
4747
| <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 |

modules/asg/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,19 @@ No modules.
3636
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the ECS Cluster to associate with the Autoscaling Group | `string` | n/a | yes |
3737
| <a name="input_create_launch_template"></a> [create\_launch\_template](#input\_create\_launch\_template) | Either to create a Launch Template to associate with the Autoscaling group | `bool` | `true` | no |
3838
| <a name="input_desired_capacity"></a> [desired\_capacity](#input\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group. | `number` | n/a | yes |
39+
| <a name="input_health_check_type"></a> [health\_check\_type](#input\_health\_check\_type) | (Optional) "EC2" or "ELB". Controls how health checking is done. | `string` | `"EC2"` | no |
3940
| <a name="input_iam_instance_profile_name"></a> [iam\_instance\_profile\_name](#input\_iam\_instance\_profile\_name) | (Optional, Forces new resource) Name of the instance profile. | `string` | `null` | no |
40-
| <a name="input_iam_instance_profile_tags"></a> [iam\_instance\_profile\_tags](#input\_iam\_instance\_profile\_tags) | (Optional) Map of resource tags for the IAM Instance Profile. | `map(any)` | `{}` | no |
41+
| <a name="input_iam_instance_profile_tags"></a> [iam\_instance\_profile\_tags](#input\_iam\_instance\_profile\_tags) | (Optional) Map of resource tags for the IAM Instance Profile. | `map(string)` | `{}` | no |
4142
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | (Optional, Forces new resource) Friendly name of the role. | `string` | `null` | no |
4243
| <a name="input_iam_role_policy_attachments"></a> [iam\_role\_policy\_attachments](#input\_iam\_role\_policy\_attachments) | (Required) - The ARN of the policy you want to apply | `list(string)` | <pre>[<br> "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"<br>]</pre> | no |
43-
| <a name="input_iam_role_tags"></a> [iam\_role\_tags](#input\_iam\_role\_tags) | Key-value mapping of tags for the IAM role. | `map(any)` | `{}` | no |
44-
| <a name="input_instances_tags"></a> [instances\_tags](#input\_instances\_tags) | Resources Tags to propagate to the Instances | `map(any)` | `{}` | no |
45-
| <a name="input_launch_template"></a> [launch\_template](#input\_launch\_template) | Launch Template to use with the Autoscaling group | <pre>object({<br> name = optional(string, null)<br> block_device_mappings = optional(list(object({<br> device_name = string<br> ebs = optional(object({<br> delete_on_termination = optional(bool, null)<br> encrypted = optional(any, null)<br> iops = optional(any, null)<br> kms_key_id = optional(string, null)<br> snapshot_id = optional(string, null)<br> throughput = optional(any, null)<br> volume_size = optional(number, null)<br> volume_type = optional(string, null)<br> }))<br> no_device = optional(any, null)<br> virtual_name = optional(string, null)<br> })), [])<br> image_id = optional(string, null)<br> instance_type = optional(string, null)<br> vpc_security_group_ids = optional(list(string), [])<br> key_name = optional(string, null)<br> user_data = optional(string, null)<br> tags = optional(map(any), {})<br> })</pre> | `{}` | no |
44+
| <a name="input_iam_role_tags"></a> [iam\_role\_tags](#input\_iam\_role\_tags) | Key-value mapping of tags for the IAM role. | `map(string)` | `{}` | no |
45+
| <a name="input_instances_tags"></a> [instances\_tags](#input\_instances\_tags) | Resources Tags to propagate to the Instances | `map(string)` | `{}` | no |
46+
| <a name="input_launch_template"></a> [launch\_template](#input\_launch\_template) | Launch Template to use with the Autoscaling group | <pre>object({<br> name = optional(string, null)<br> block_device_mappings = optional(list(object({<br> device_name = string<br> ebs = optional(object({<br> delete_on_termination = optional(bool, null)<br> snapshot_id = optional(string, null)<br> volume_size = optional(number, null)<br> volume_type = optional(string, null)<br> }))<br> no_device = optional(any, null)<br> virtual_name = optional(string, null)<br> })), [])<br> image_id = optional(string, null)<br> instance_type = optional(string, null)<br> vpc_security_group_ids = optional(list(string), [])<br> key_name = optional(string, null)<br> user_data = optional(string, null)<br> tags = optional(map(string), {})<br> })</pre> | `{}` | no |
4647
| <a name="input_launch_template_id"></a> [launch\_template\_id](#input\_launch\_template\_id) | Identifier of the Launch Template | `string` | `null` | no |
4748
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | Maximum size of the Auto Scaling Group | `number` | n/a | yes |
4849
| <a name="input_min_size"></a> [min\_size](#input\_min\_size) | Minimum size of the Auto Scaling Group | `number` | n/a | yes |
4950
| <a name="input_name"></a> [name](#input\_name) | (Optional) Name of the Auto Scaling Group. | `string` | n/a | yes |
50-
| <a name="input_tags"></a> [tags](#input\_tags) | Resources Tags for Autoscaling group | `map(any)` | `{}` | no |
51+
| <a name="input_tags"></a> [tags](#input\_tags) | Resources Tags for Autoscaling group | `map(string)` | `{}` | no |
5152
| <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)` | n/a | yes |
5253

5354
## Outputs

modules/asg/locals.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
locals {
2+
launch_template_user_data = try(var.launch_template.user_data, null) != null ? base64encode(var.launch_template.user_data) : base64encode(
3+
<<-USERDATA
4+
#!/bin/bash
5+
echo ECS_CLUSTER="${var.cluster_name}" >> /etc/ecs/ecs.config
6+
USERDATA
7+
)
8+
}

modules/asg/main.tf

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "aws_autoscaling_group" "this" {
77
max_size = var.max_size
88

99
protect_from_scale_in = false
10-
health_check_type = "EC2"
10+
health_check_type = var.health_check_type
1111

1212
launch_template {
1313
id = var.create_launch_template ? aws_launch_template.this[0].id : var.launch_template_id
@@ -63,11 +63,7 @@ resource "aws_launch_template" "this" {
6363

6464
content {
6565
delete_on_termination = block_device_mappings.value.ebs.delete_on_termination
66-
encrypted = block_device_mappings.value.ebs.encrypted
67-
iops = block_device_mappings.value.ebs.iops
68-
kms_key_id = block_device_mappings.value.ebs.kms_key_id
6966
snapshot_id = block_device_mappings.value.ebs.snapshot_id
70-
throughput = block_device_mappings.value.ebs.throughput
7167
volume_size = block_device_mappings.value.ebs.volume_size
7268
volume_type = block_device_mappings.value.ebs.volume_type
7369
}
@@ -78,13 +74,7 @@ resource "aws_launch_template" "this" {
7874
iam_instance_profile {
7975
name = aws_iam_instance_profile.this.name
8076
}
81-
82-
user_data = try(var.launch_template.user_data, null) != null ? base64encode(var.launch_template.user_data) : base64encode(
83-
<<-USERDATA
84-
#!/bin/bash
85-
echo ECS_CLUSTER="${var.cluster_name}" >> /etc/ecs/ecs.config
86-
USERDATA
87-
)
77+
user_data = local.launch_template_user_data
8878

8979
tags = var.launch_template.tags
9080
}

modules/asg/variables.tf

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ variable "max_size" {
2828
type = number
2929
}
3030

31+
variable "health_check_type" {
32+
description = "(Optional) \"EC2\" or \"ELB\". Controls how health checking is done."
33+
type = string
34+
default = "EC2"
35+
}
36+
3137
variable "instances_tags" {
3238
description = "Resources Tags to propagate to the Instances"
33-
type = map(any)
39+
type = map(string)
3440
default = {}
3541
}
3642

3743
variable "tags" {
3844
description = "Resources Tags for Autoscaling group"
39-
type = map(any)
45+
type = map(string)
4046
default = {}
4147
}
4248

@@ -52,11 +58,7 @@ variable "launch_template" {
5258
device_name = string
5359
ebs = optional(object({
5460
delete_on_termination = optional(bool, null)
55-
encrypted = optional(any, null)
56-
iops = optional(any, null)
57-
kms_key_id = optional(string, null)
5861
snapshot_id = optional(string, null)
59-
throughput = optional(any, null)
6062
volume_size = optional(number, null)
6163
volume_type = optional(string, null)
6264
}))
@@ -68,7 +70,7 @@ variable "launch_template" {
6870
vpc_security_group_ids = optional(list(string), [])
6971
key_name = optional(string, null)
7072
user_data = optional(string, null)
71-
tags = optional(map(any), {})
73+
tags = optional(map(string), {})
7274
})
7375
default = {}
7476
}
@@ -105,7 +107,7 @@ variable "iam_role_policy_attachments" {
105107

106108
variable "iam_role_tags" {
107109
description = "Key-value mapping of tags for the IAM role."
108-
type = map(any)
110+
type = map(string)
109111
default = {}
110112
}
111113

@@ -121,6 +123,6 @@ variable "iam_instance_profile_name" {
121123

122124
variable "iam_instance_profile_tags" {
123125
description = "(Optional) Map of resource tags for the IAM Instance Profile."
124-
type = map(any)
126+
type = map(string)
125127
default = {}
126128
}

variables.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ variable "asg_launch_template" {
9797
device_name = string
9898
ebs = optional(object({
9999
delete_on_termination = optional(bool, null)
100-
encrypted = optional(any, null)
101-
iops = optional(any, null)
102-
kms_key_id = optional(string, null)
103100
snapshot_id = optional(string, null)
104-
throughput = optional(any, null)
105101
volume_size = optional(number, null)
106102
volume_type = optional(string, null)
107103
}))

0 commit comments

Comments
 (0)