Skip to content

Commit

Permalink
feat!: asg sub-module integration
Browse files Browse the repository at this point in the history
Use cluster sub-module to provision ECS Cluster.
  • Loading branch information
saumitra-dev committed Jul 22, 2024
1 parent ec28605 commit e79392b
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 93 deletions.
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,53 @@ A Terraform module to create ECS Cluster that relies on self-managed EC2 instanc

## Providers

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

## Modules

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

## Resources

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

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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) | Desired capacity for the Autoscaling group | `number` | n/a | yes |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <a name="input_asg_instances_tags"></a> [asg\_instances\_tags](#input\_asg\_instances\_tags) | Resources Tags to propagate to the Instances | `map(any)` | `{}` | no |
| <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 |
| <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 |
| <a name="input_asg_max_size"></a> [asg\_max\_size](#input\_asg\_max\_size) | Max. size for the Autoscaling group | `number` | n/a | yes |
| <a name="input_asg_min_size"></a> [asg\_min\_size](#input\_asg\_min\_size) | Min. size for the Autoscaling group | `number` | n/a | yes |
| <a name="input_asg_name"></a> [asg\_name](#input\_asg\_name) | Name of the Autoscaling Group | `string` | n/a | yes |
| <a name="input_asg_tags"></a> [asg\_tags](#input\_asg\_tags) | Resources Tags for Autoscaling group | `map(any)` | `{}` | no |
| <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 |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the ECS Cluster to create | `string` | n/a | yes |
| <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 |
| <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 |
| <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 |
| <a name="input_tags"></a> [tags](#input\_tags) | Resource Tags for ECS Cluster | `map(any)` | `{}` | no |
| <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 |
| <a name="input_cluster_tags"></a> [cluster\_tags](#input\_cluster\_tags) | Resource Tags for ECS Cluster | `map(any)` | `{}` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_asg_arn"></a> [asg\_arn](#output\_asg\_arn) | ARN of the Autoscaling group |
| <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 |
| <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 |
| <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 |
| <a name="output_asg_id"></a> [asg\_id](#output\_asg\_id) | Identifier of the Autoscaling group |
| <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 |
| <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 |
| <a name="output_cluster_arn"></a> [cluster\_arn](#output\_cluster\_arn) | ARN of the ECS Cluster |
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | Identifier of the ECS Cluster |
| <a name="output_cluster_name"></a> [cluster\_name](#output\_cluster\_name) | Name of the ECS Cluster |
Expand Down
87 changes: 38 additions & 49 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,42 @@
# ECS Cluster
################################################################################

resource "aws_ecs_cluster" "this" {
name = var.cluster_name

dynamic "configuration" {
for_each = var.execute_command_configuration != null != null ? [1] : []

content {
dynamic "execute_command_configuration" {
for_each = var.execute_command_configuration != null ? [1] : []

content {
kms_key_id = try(var.execute_command_configuration.kms_key_id, null)
logging = try(var.execute_command_configuration.logging, null)

dynamic "log_configuration" {
for_each = try(var.execute_command_configuration.log_configuration, null) != null ? [1] : []

content {
cloud_watch_encryption_enabled = try(var.execute_command_configuration.log_configuration.cloud_watch_encryption_enabled, null)
cloud_watch_log_group_name = try(var.execute_command_configuration.log_configuration.cloud_watch_log_group_name, null)
s3_bucket_name = try(var.execute_command_configuration.log_configuration.s3_bucket_name, null)
s3_bucket_encryption_enabled = try(var.execute_command_configuration.log_configuration.s3_bucket_encryption_enabled, null)
s3_key_prefix = try(var.execute_command_configuration.log_configuration.s3_key_prefix, null)
}
}
}
}
}
}

dynamic "service_connect_defaults" {
for_each = var.service_connect_defaults != null ? [1] : []

content {
namespace = var.service_connect_defaults.namespace
}
}

dynamic "setting" {
for_each = var.setting
iterator = setting

content {
name = setting.value.name
value = setting.value.value
}
}

tags = var.tags
module "cluster" {
source = "./modules/cluster"

name = var.cluster_name
setting = var.cluster_setting
tags = var.cluster_tags
}

################################################################################
# Autoscaling Group
################################################################################

module "asg" {
source = "./modules/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

# Launch Template
create_launch_template = var.asg_create_launch_template
launch_template_id = var.asg_launch_template_id
launch_template = var.asg_launch_template

# IAM Role
iam_role_name = var.asg_iam_role_name
iam_role_policy_attachments = var.asg_iam_role_policy_attachments
iam_role_tags = var.asg_iam_role_tags

# IAM Instance Profile
iam_instance_profile_name = var.asg_iam_instance_profile_name
iam_instance_profile_tags = var.asg_iam_instance_profile_tags
}
57 changes: 52 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,65 @@
##############################
################################################################################
# ECS Cluster
##############################
################################################################################

output "cluster_id" {
description = "Identifier of the ECS Cluster"
value = aws_ecs_cluster.this.id
value = module.cluster.id
}

output "cluster_arn" {
description = "ARN of the ECS Cluster"
value = aws_ecs_cluster.this.arn
value = module.cluster.arn
}

output "cluster_name" {
description = "Name of the ECS Cluster"
value = var.cluster_name
value = module.cluster.name
}

################################################################################
# Autoscaling Group
################################################################################

output "asg_id" {
description = "Identifier of the Autoscaling group"
value = module.asg.id
}

output "asg_arn" {
description = "ARN of the Autoscaling group"
value = module.asg.arn
}

################################################################################
# Launch Template
################################################################################

output "asg_launch_template_id" {
description = "Identifier of the Launch Template being used with the Autoscaling Group"
value = module.asg.launch_template_id
}

output "asg_launch_template_arn" {
description = "ARN of the Launch Template being used with the Autoscaling Group"
value = module.asg.launch_template_arn
}

################################################################################
# IAM Instance Profile
################################################################################

output "asg_iam_role_id" {
description = "Identifier of the IAM Role being used with the IAM Instnace Profile"
value = module.asg.iam_role_id
}

output "asg_iam_instance_profile_id" {
description = "Identifier of the IAM Instance Profile being used with the Launch Template"
value = module.asg.iam_instance_profile_id
}

output "asg_iam_instance_profile_arn" {
description = "ARN of the IAM Instance Profile being used with the Launch Template"
value = module.asg.iam_instance_profile_arn
}
Loading

0 comments on commit e79392b

Please sign in to comment.