Skip to content

Commit 92a5d35

Browse files
committed
fix(modules/asg): user_data cannot be null
Change variables and outputs descriptions. Update Terraform and AWS Provider version.
1 parent 934848d commit 92a5d35

File tree

5 files changed

+49
-44
lines changed

5 files changed

+49
-44
lines changed

modules/asg/README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
| Name | Version |
77
|------|---------|
8-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6.0 |
8+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.8.4 |
9+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.51.0 |
910

1011
## Providers
1112

@@ -34,30 +35,30 @@ No modules.
3435
|------|-------------|------|---------|:--------:|
3536
| <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 |
3637
| <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 |
37-
| <a name="input_desired_capacity"></a> [desired\_capacity](#input\_desired\_capacity) | Desired capacity for the Autoscaling group | `number` | n/a | yes |
38-
| <a name="input_iam_instance_profile_name"></a> [iam\_instance\_profile\_name](#input\_iam\_instance\_profile\_name) | Name of the IAM Instance Profile | `string` | `null` | no |
39-
| <a name="input_iam_instance_profile_tags"></a> [iam\_instance\_profile\_tags](#input\_iam\_instance\_profile\_tags) | Resource Tags for the IAM Instance Profile | `map(any)` | `{}` | no |
40-
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | Name for the IAM Role | `string` | `null` | no |
41-
| <a name="input_iam_role_policy_attachments"></a> [iam\_role\_policy\_attachments](#input\_iam\_role\_policy\_attachments) | Policy ARNs to attach to the IAM Role | `list(string)` | <pre>[<br> "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"<br>]</pre> | no |
42-
| <a name="input_iam_role_tags"></a> [iam\_role\_tags](#input\_iam\_role\_tags) | Resource Tags for IAM Role | `map(any)` | `{}` | no |
38+
| <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_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_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | (Optional, Forces new resource) Friendly name of the role. | `string` | `null` | no |
42+
| <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 |
4344
| <a name="input_instances_tags"></a> [instances\_tags](#input\_instances\_tags) | Resources Tags to propagate to the Instances | `map(any)` | `{}` | no |
4445
| <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> 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 |
4546
| <a name="input_launch_template_id"></a> [launch\_template\_id](#input\_launch\_template\_id) | Identifier of the Launch Template | `string` | `null` | no |
46-
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | Max. size for the Autoscaling group | `number` | n/a | yes |
47-
| <a name="input_min_size"></a> [min\_size](#input\_min\_size) | Min. size for the Autoscaling group | `number` | n/a | yes |
48-
| <a name="input_name"></a> [name](#input\_name) | Name of the Autoscaling Group | `string` | n/a | yes |
47+
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | Maximum size of the Auto Scaling Group | `number` | n/a | yes |
48+
| <a name="input_min_size"></a> [min\_size](#input\_min\_size) | Minimum size of the Auto Scaling Group | `number` | n/a | yes |
49+
| <a name="input_name"></a> [name](#input\_name) | (Optional) Name of the Auto Scaling Group. | `string` | n/a | yes |
4950
| <a name="input_tags"></a> [tags](#input\_tags) | Resources Tags for Autoscaling group | `map(any)` | `{}` | no |
50-
| <a name="input_vpc_zone_identifier"></a> [vpc\_zone\_identifier](#input\_vpc\_zone\_identifier) | Identifiers of the VPC Subnets | `list(string)` | n/a | yes |
51+
| <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 |
5152

5253
## Outputs
5354

5455
| Name | Description |
5556
|------|-------------|
56-
| <a name="output_arn"></a> [arn](#output\_arn) | ARN of the Autoscaling group |
57-
| <a name="output_iam_instance_profile_arn"></a> [iam\_instance\_profile\_arn](#output\_iam\_instance\_profile\_arn) | ARN of the IAM Instance Profile |
58-
| <a name="output_iam_instance_profile_id"></a> [iam\_instance\_profile\_id](#output\_iam\_instance\_profile\_id) | Identifier of the IAM Instance Profile |
59-
| <a name="output_iam_role_id"></a> [iam\_role\_id](#output\_iam\_role\_id) | Identifier of the IAM Role |
60-
| <a name="output_id"></a> [id](#output\_id) | Identifier of the Autoscaling group |
61-
| <a name="output_launch_template_arn"></a> [launch\_template\_arn](#output\_launch\_template\_arn) | ARN of the Launch Template |
62-
| <a name="output_launch_template_id"></a> [launch\_template\_id](#output\_launch\_template\_id) | Identifier of the Launch Template |
57+
| <a name="output_arn"></a> [arn](#output\_arn) | ARN for this Auto Scaling Group. |
58+
| <a name="output_iam_instance_profile_arn"></a> [iam\_instance\_profile\_arn](#output\_iam\_instance\_profile\_arn) | ARN assigned by AWS to the instance profile. |
59+
| <a name="output_iam_instance_profile_id"></a> [iam\_instance\_profile\_id](#output\_iam\_instance\_profile\_id) | Instance profile's ID. |
60+
| <a name="output_iam_role_id"></a> [iam\_role\_id](#output\_iam\_role\_id) | Name of the role. |
61+
| <a name="output_id"></a> [id](#output\_id) | Auto Scaling Group id. |
62+
| <a name="output_launch_template_arn"></a> [launch\_template\_arn](#output\_launch\_template\_arn) | Amazon Resource Name (ARN) of the launch template. |
63+
| <a name="output_launch_template_id"></a> [launch\_template\_id](#output\_launch\_template\_id) | The ID of the launch template. |
6364
<!-- END_TF_DOCS -->

modules/asg/main.tf

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,11 @@ resource "aws_launch_template" "this" {
5353
name = aws_iam_instance_profile.this.name
5454
}
5555

56-
user_data = base64encode(
57-
try(
58-
var.launch_template.user_data,
59-
<<-USERDATA
60-
#!/bin/bash
61-
echo ECS_CLUSTER="${var.cluster_name}" >> /etc/ecs/ecs.config
62-
USERDATA
63-
)
56+
user_data = try(var.launch_template.user_data, null) != null ? base64encode(var.launch_template.user_data) : base64encode(
57+
<<-USERDATA
58+
#!/bin/bash
59+
echo ECS_CLUSTER="${var.cluster_name}" >> /etc/ecs/ecs.config
60+
USERDATA
6461
)
6562

6663
tags = var.launch_template.tags

modules/asg/outputs.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
output "id" {
2-
description = "Identifier of the Autoscaling group"
2+
description = "Auto Scaling Group id."
33
value = aws_autoscaling_group.this.id
44
}
55

66
output "arn" {
7-
description = "ARN of the Autoscaling group"
7+
description = "ARN for this Auto Scaling Group."
88
value = aws_autoscaling_group.this.arn
99
}
1010

@@ -13,12 +13,12 @@ output "arn" {
1313
################################################################################
1414

1515
output "launch_template_id" {
16-
description = "Identifier of the Launch Template"
16+
description = "The ID of the launch template."
1717
value = var.create_launch_template ? aws_launch_template.this[0].id : var.launch_template_id
1818
}
1919

2020
output "launch_template_arn" {
21-
description = "ARN of the Launch Template"
21+
description = "Amazon Resource Name (ARN) of the launch template."
2222
value = var.create_launch_template ? aws_launch_template.this[0].arn : null
2323
}
2424

@@ -27,16 +27,16 @@ output "launch_template_arn" {
2727
################################################################################
2828

2929
output "iam_role_id" {
30-
description = "Identifier of the IAM Role"
30+
description = "Name of the role."
3131
value = aws_iam_role.this.id
3232
}
3333

3434
output "iam_instance_profile_id" {
35-
description = "Identifier of the IAM Instance Profile"
35+
description = "Instance profile's ID."
3636
value = aws_iam_instance_profile.this.id
3737
}
3838

3939
output "iam_instance_profile_arn" {
40-
description = "ARN of the IAM Instance Profile"
40+
description = "ARN assigned by AWS to the instance profile."
4141
value = aws_iam_instance_profile.this.arn
4242
}

modules/asg/variables.tf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ variable "cluster_name" {
44
}
55

66
variable "name" {
7-
description = "Name of the Autoscaling Group"
7+
description = "(Optional) Name of the Auto Scaling Group."
88
type = string
99
}
1010

1111
variable "vpc_zone_identifier" {
12-
description = "Identifiers of the VPC Subnets"
12+
description = "(Optional) List of subnet IDs to launch resources in."
1313
type = list(string)
1414
}
1515

1616
variable "desired_capacity" {
17-
description = "Desired capacity for the Autoscaling group"
17+
description = "The number of Amazon EC2 instances that should be running in the group."
1818
type = number
1919
}
2020

2121
variable "min_size" {
22-
description = "Min. size for the Autoscaling group"
22+
description = "Minimum size of the Auto Scaling Group"
2323
type = number
2424
}
2525

2626
variable "max_size" {
27-
description = "Max. size for the Autoscaling group"
27+
description = "Maximum size of the Auto Scaling Group"
2828
type = number
2929
}
3030

@@ -75,21 +75,21 @@ variable "launch_template_id" {
7575
################################################################################
7676

7777
variable "iam_role_name" {
78-
description = "Name for the IAM Role"
78+
description = "(Optional, Forces new resource) Friendly name of the role."
7979
type = string
8080
default = null
8181
}
8282

8383
variable "iam_role_policy_attachments" {
84-
description = "Policy ARNs to attach to the IAM Role"
84+
description = "(Required) - The ARN of the policy you want to apply"
8585
type = list(string)
8686
default = [
8787
"arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
8888
]
8989
}
9090

9191
variable "iam_role_tags" {
92-
description = "Resource Tags for IAM Role"
92+
description = "Key-value mapping of tags for the IAM role."
9393
type = map(any)
9494
default = {}
9595
}
@@ -99,13 +99,13 @@ variable "iam_role_tags" {
9999
################################################################################
100100

101101
variable "iam_instance_profile_name" {
102-
description = "Name of the IAM Instance Profile"
102+
description = "(Optional, Forces new resource) Name of the instance profile."
103103
type = string
104104
default = null
105105
}
106106

107107
variable "iam_instance_profile_tags" {
108-
description = "Resource Tags for the IAM Instance Profile"
108+
description = "(Optional) Map of resource tags for the IAM Instance Profile."
109109
type = map(any)
110110
default = {}
111111
}

modules/asg/version.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
terraform {
2-
required_version = ">= 1.6.0"
2+
required_version = ">= 1.8.4"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.51.0"
8+
}
9+
}
310
}

0 commit comments

Comments
 (0)