Skip to content

Commit e79392b

Browse files
committed
feat!: asg sub-module integration
Use cluster sub-module to provision ECS Cluster.
1 parent ec28605 commit e79392b

File tree

4 files changed

+260
-93
lines changed

4 files changed

+260
-93
lines changed

README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,53 @@ A Terraform module to create ECS Cluster that relies on self-managed EC2 instanc
1111

1212
## Providers
1313

14-
| Name | Version |
15-
|------|---------|
16-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.57.0 |
14+
No providers.
1715

1816
## Modules
1917

20-
No modules.
18+
| Name | Source | Version |
19+
|------|--------|---------|
20+
| <a name="module_asg"></a> [asg](#module\_asg) | ./modules/asg | n/a |
21+
| <a name="module_cluster"></a> [cluster](#module\_cluster) | ./modules/cluster | n/a |
2122

2223
## Resources
2324

24-
| Name | Type |
25-
|------|------|
26-
| [aws_ecs_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster) | resource |
25+
No resources.
2726

2827
## Inputs
2928

3029
| Name | Description | Type | Default | Required |
3130
|------|-------------|------|---------|:--------:|
31+
| <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 |
32+
| <a name="input_asg_desired_capacity"></a> [asg\_desired\_capacity](#input\_asg\_desired\_capacity) | Desired capacity for the Autoscaling group | `number` | n/a | yes |
33+
| <a name="input_asg_iam_instance_profile_name"></a> [asg\_iam\_instance\_profile\_name](#input\_asg\_iam\_instance\_profile\_name) | Name of the IAM Instance Profile | `string` | `null` | no |
34+
| <a name="input_asg_iam_instance_profile_tags"></a> [asg\_iam\_instance\_profile\_tags](#input\_asg\_iam\_instance\_profile\_tags) | Resource Tags for the IAM Instance Profile | `map(any)` | `{}` | no |
35+
| <a name="input_asg_iam_role_name"></a> [asg\_iam\_role\_name](#input\_asg\_iam\_role\_name) | Name for the IAM Role | `string` | `null` | no |
36+
| <a name="input_asg_iam_role_policy_attachments"></a> [asg\_iam\_role\_policy\_attachments](#input\_asg\_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 |
37+
| <a name="input_asg_iam_role_tags"></a> [asg\_iam\_role\_tags](#input\_asg\_iam\_role\_tags) | Resource Tags for IAM Role | `map(any)` | `{}` | no |
38+
| <a name="input_asg_instances_tags"></a> [asg\_instances\_tags](#input\_asg\_instances\_tags) | Resources Tags to propagate to the Instances | `map(any)` | `{}` | no |
39+
| <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> 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 |
40+
| <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 |
41+
| <a name="input_asg_max_size"></a> [asg\_max\_size](#input\_asg\_max\_size) | Max. size for the Autoscaling group | `number` | n/a | yes |
42+
| <a name="input_asg_min_size"></a> [asg\_min\_size](#input\_asg\_min\_size) | Min. size for the Autoscaling group | `number` | n/a | yes |
43+
| <a name="input_asg_name"></a> [asg\_name](#input\_asg\_name) | Name of the Autoscaling Group | `string` | n/a | yes |
44+
| <a name="input_asg_tags"></a> [asg\_tags](#input\_asg\_tags) | Resources Tags for Autoscaling group | `map(any)` | `{}` | no |
45+
| <a name="input_asg_vpc_zone_identifier"></a> [asg\_vpc\_zone\_identifier](#input\_asg\_vpc\_zone\_identifier) | Identifiers of the VPC Subnets | `list(string)` | n/a | yes |
3246
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the ECS Cluster to create | `string` | n/a | yes |
33-
| <a name="input_execute_command_configuration"></a> [execute\_command\_configuration](#input\_execute\_command\_configuration) | Details of the execute command configuration | <pre>object({<br> kms_key_id = optional(string)<br> logging = optional(string)<br> log_configuration = optional(object({<br> cloud_watch_encryption_enabled = optional(bool)<br> cloud_watch_log_group_name = optional(string)<br> s3_bucket_name = optional(string)<br> s3_bucket_encryption_enabled = optional(bool)<br> s3_key_prefix = optional(string)<br> }))<br> })</pre> | `null` | no |
34-
| <a name="input_service_connect_defaults"></a> [service\_connect\_defaults](#input\_service\_connect\_defaults) | Default Service Connect namespace | <pre>object({<br> namespace = string<br> })</pre> | `null` | no |
35-
| <a name="input_setting"></a> [setting](#input\_setting) | Details of the setting configuration | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
36-
| <a name="input_tags"></a> [tags](#input\_tags) | Resource Tags for ECS Cluster | `map(any)` | `{}` | no |
47+
| <a name="input_cluster_setting"></a> [cluster\_setting](#input\_cluster\_setting) | Details of the setting configuration | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
48+
| <a name="input_cluster_tags"></a> [cluster\_tags](#input\_cluster\_tags) | Resource Tags for ECS Cluster | `map(any)` | `{}` | no |
3749

3850
## Outputs
3951

4052
| Name | Description |
4153
|------|-------------|
54+
| <a name="output_asg_arn"></a> [asg\_arn](#output\_asg\_arn) | ARN of the Autoscaling group |
55+
| <a name="output_asg_iam_instance_profile_arn"></a> [asg\_iam\_instance\_profile\_arn](#output\_asg\_iam\_instance\_profile\_arn) | ARN of the IAM Instance Profile being used with the Launch Template |
56+
| <a name="output_asg_iam_instance_profile_id"></a> [asg\_iam\_instance\_profile\_id](#output\_asg\_iam\_instance\_profile\_id) | Identifier of the IAM Instance Profile being used with the Launch Template |
57+
| <a name="output_asg_iam_role_id"></a> [asg\_iam\_role\_id](#output\_asg\_iam\_role\_id) | Identifier of the IAM Role being used with the IAM Instnace Profile |
58+
| <a name="output_asg_id"></a> [asg\_id](#output\_asg\_id) | Identifier of the Autoscaling group |
59+
| <a name="output_asg_launch_template_arn"></a> [asg\_launch\_template\_arn](#output\_asg\_launch\_template\_arn) | ARN of the Launch Template being used with the Autoscaling Group |
60+
| <a name="output_asg_launch_template_id"></a> [asg\_launch\_template\_id](#output\_asg\_launch\_template\_id) | Identifier of the Launch Template being used with the Autoscaling Group |
4261
| <a name="output_cluster_arn"></a> [cluster\_arn](#output\_cluster\_arn) | ARN of the ECS Cluster |
4362
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | Identifier of the ECS Cluster |
4463
| <a name="output_cluster_name"></a> [cluster\_name](#output\_cluster\_name) | Name of the ECS Cluster |

main.tf

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,42 @@
22
# ECS Cluster
33
################################################################################
44

5-
resource "aws_ecs_cluster" "this" {
6-
name = var.cluster_name
7-
8-
dynamic "configuration" {
9-
for_each = var.execute_command_configuration != null != null ? [1] : []
10-
11-
content {
12-
dynamic "execute_command_configuration" {
13-
for_each = var.execute_command_configuration != null ? [1] : []
14-
15-
content {
16-
kms_key_id = try(var.execute_command_configuration.kms_key_id, null)
17-
logging = try(var.execute_command_configuration.logging, null)
18-
19-
dynamic "log_configuration" {
20-
for_each = try(var.execute_command_configuration.log_configuration, null) != null ? [1] : []
21-
22-
content {
23-
cloud_watch_encryption_enabled = try(var.execute_command_configuration.log_configuration.cloud_watch_encryption_enabled, null)
24-
cloud_watch_log_group_name = try(var.execute_command_configuration.log_configuration.cloud_watch_log_group_name, null)
25-
s3_bucket_name = try(var.execute_command_configuration.log_configuration.s3_bucket_name, null)
26-
s3_bucket_encryption_enabled = try(var.execute_command_configuration.log_configuration.s3_bucket_encryption_enabled, null)
27-
s3_key_prefix = try(var.execute_command_configuration.log_configuration.s3_key_prefix, null)
28-
}
29-
}
30-
}
31-
}
32-
}
33-
}
34-
35-
dynamic "service_connect_defaults" {
36-
for_each = var.service_connect_defaults != null ? [1] : []
37-
38-
content {
39-
namespace = var.service_connect_defaults.namespace
40-
}
41-
}
42-
43-
dynamic "setting" {
44-
for_each = var.setting
45-
iterator = setting
46-
47-
content {
48-
name = setting.value.name
49-
value = setting.value.value
50-
}
51-
}
52-
53-
tags = var.tags
5+
module "cluster" {
6+
source = "./modules/cluster"
7+
8+
name = var.cluster_name
9+
setting = var.cluster_setting
10+
tags = var.cluster_tags
11+
}
12+
13+
################################################################################
14+
# Autoscaling Group
15+
################################################################################
16+
17+
module "asg" {
18+
source = "./modules/asg"
19+
20+
cluster_name = module.cluster.name
21+
22+
name = var.asg_name
23+
vpc_zone_identifier = var.asg_vpc_zone_identifier
24+
desired_capacity = var.asg_desired_capacity
25+
min_size = var.asg_min_size
26+
max_size = var.asg_max_size
27+
instances_tags = var.asg_instances_tags
28+
tags = var.asg_tags
29+
30+
# Launch Template
31+
create_launch_template = var.asg_create_launch_template
32+
launch_template_id = var.asg_launch_template_id
33+
launch_template = var.asg_launch_template
34+
35+
# IAM Role
36+
iam_role_name = var.asg_iam_role_name
37+
iam_role_policy_attachments = var.asg_iam_role_policy_attachments
38+
iam_role_tags = var.asg_iam_role_tags
39+
40+
# IAM Instance Profile
41+
iam_instance_profile_name = var.asg_iam_instance_profile_name
42+
iam_instance_profile_tags = var.asg_iam_instance_profile_tags
5443
}

outputs.tf

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,65 @@
1-
##############################
1+
################################################################################
22
# ECS Cluster
3-
##############################
3+
################################################################################
44

55
output "cluster_id" {
66
description = "Identifier of the ECS Cluster"
7-
value = aws_ecs_cluster.this.id
7+
value = module.cluster.id
88
}
99

1010
output "cluster_arn" {
1111
description = "ARN of the ECS Cluster"
12-
value = aws_ecs_cluster.this.arn
12+
value = module.cluster.arn
1313
}
1414

1515
output "cluster_name" {
1616
description = "Name of the ECS Cluster"
17-
value = var.cluster_name
17+
value = module.cluster.name
18+
}
19+
20+
################################################################################
21+
# Autoscaling Group
22+
################################################################################
23+
24+
output "asg_id" {
25+
description = "Identifier of the Autoscaling group"
26+
value = module.asg.id
27+
}
28+
29+
output "asg_arn" {
30+
description = "ARN of the Autoscaling group"
31+
value = module.asg.arn
32+
}
33+
34+
################################################################################
35+
# Launch Template
36+
################################################################################
37+
38+
output "asg_launch_template_id" {
39+
description = "Identifier of the Launch Template being used with the Autoscaling Group"
40+
value = module.asg.launch_template_id
41+
}
42+
43+
output "asg_launch_template_arn" {
44+
description = "ARN of the Launch Template being used with the Autoscaling Group"
45+
value = module.asg.launch_template_arn
46+
}
47+
48+
################################################################################
49+
# IAM Instance Profile
50+
################################################################################
51+
52+
output "asg_iam_role_id" {
53+
description = "Identifier of the IAM Role being used with the IAM Instnace Profile"
54+
value = module.asg.iam_role_id
55+
}
56+
57+
output "asg_iam_instance_profile_id" {
58+
description = "Identifier of the IAM Instance Profile being used with the Launch Template"
59+
value = module.asg.iam_instance_profile_id
60+
}
61+
62+
output "asg_iam_instance_profile_arn" {
63+
description = "ARN of the IAM Instance Profile being used with the Launch Template"
64+
value = module.asg.iam_instance_profile_arn
1865
}

0 commit comments

Comments
 (0)