Skip to content

Commit

Permalink
Added dynamic block for cloudwatch alarms (#75)
Browse files Browse the repository at this point in the history
* Added dynamic block for cloudwatch alarms

Signed-off-by: Mohammed Alkatheeri <mohammed.alkatheeri@umotif.com>

* chore: update pre-commit, readme and changelog

* Supress tflint messages

Signed-off-by: Mohammed Alkatheeri <mohammed.alkatheeri@umotif.com>

---------

Signed-off-by: Mohammed Alkatheeri <mohammed.alkatheeri@umotif.com>
  • Loading branch information
Mohammed-afk91 authored Dec 18, 2024
1 parent dae529d commit dcdffa0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-added-large-files
args: ['--maxkb=500']
Expand All @@ -18,7 +18,7 @@ repos:
args: ['--allow-missing-credentials']
- id: trailing-whitespace
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.81.0
rev: v1.96.2
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand Down
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ All notable changes to this project will be documented in this file.
<a name="unreleased"></a>
## [Unreleased]

- fix: protocol set to HTTP by default
- fix: setting container_name is now mandatory to utilise multiple container names set externally to module
- chore: upgrade to 5.x compatibility
- Added dynamic block for cloudwatch alarms


<a name="8.0.0"></a>
## [8.0.0] - 2023-07-24

- Upgrade to 5.x + Fixes ([#74](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/74))


<a name="7.0.0"></a>
Expand Down Expand Up @@ -278,7 +282,8 @@ All notable changes to this project will be documented in this file.
- Initial commit


[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/7.0.0...HEAD
[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/8.0.0...HEAD
[8.0.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/7.0.0...8.0.0
[7.0.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.7.1...7.0.0
[6.7.1]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.7.0...6.7.1
[6.7.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.6.0...6.7.0
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module "ecs-fargate" {

Module managed by [uMotif](https://github.com/umotif-public/).

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
Expand Down Expand Up @@ -135,6 +135,7 @@ No modules.
| <a name="input_cpu_architecture"></a> [cpu\_architecture](#input\_cpu\_architecture) | cpu architecture for the task | `string` | `"X86_64"` | no |
| <a name="input_create_repository_credentials_iam_policy"></a> [create\_repository\_credentials\_iam\_policy](#input\_create\_repository\_credentials\_iam\_policy) | Set to true if you are specifying `repository_credentials` variable, it will attach IAM policy with necessary permissions to task role. | `bool` | `false` | no |
| <a name="input_deny_egress_to_anywhere"></a> [deny\_egress\_to\_anywhere](#input\_deny\_egress\_to\_anywhere) | When this parameter is true, no default egress rule will be created | `bool` | `false` | no |
| <a name="input_deployment_alarms"></a> [deployment\_alarms](#input\_deployment\_alarms) | Information about the CloudWatch alarms | <pre>list(object({<br/> alarm_names = list(string)<br/> rollback = bool<br/> enable = bool<br/> }))</pre> | `[]` | no |
| <a name="input_deployment_controller_type"></a> [deployment\_controller\_type](#input\_deployment\_controller\_type) | Type of deployment controller. Valid values: CODE\_DEPLOY, ECS, EXTERNAL. Default: ECS. | `string` | `"ECS"` | no |
| <a name="input_deployment_maximum_percent"></a> [deployment\_maximum\_percent](#input\_deployment\_maximum\_percent) | The upper limit of the number of running tasks that can be running in a service during a deployment | `number` | `200` | no |
| <a name="input_deployment_minimum_healthy_percent"></a> [deployment\_minimum\_healthy\_percent](#input\_deployment\_minimum\_healthy\_percent) | The lower limit of the number of running tasks that must remain running and healthy in a service during a deployment | `number` | `50` | no |
Expand Down Expand Up @@ -209,7 +210,7 @@ No modules.
| <a name="output_task_definition_name"></a> [task\_definition\_name](#output\_task\_definition\_name) | The name of the task definition created |
| <a name="output_task_role_arn"></a> [task\_role\_arn](#output\_task\_role\_arn) | The Amazon Resource Name (ARN) specifying the ECS service role. |
| <a name="output_task_role_name"></a> [task\_role\_name](#output\_task\_role\_name) | The name of the Fargate task service role. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- END_TF_DOCS -->

## License

Expand Down
18 changes: 16 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ resource "aws_security_group_rule" "egress_service" {
resource "aws_lb_target_group" "task" {
for_each = var.load_balanced ? { for tg in var.target_groups : tg.target_group_name => tg } : {}

# tflint-ignore: terraform_deprecated_lookup
name = lookup(each.value, "target_group_name")
vpc_id = var.vpc_id
protocol = var.task_container_protocol
Expand Down Expand Up @@ -137,6 +138,7 @@ resource "aws_lb_target_group" "task" {
tags = merge(
var.tags,
{
# tflint-ignore: terraform_deprecated_lookup
Name = lookup(each.value, "target_group_name")
},
)
Expand Down Expand Up @@ -289,11 +291,23 @@ resource "aws_ecs_service" "service" {
}
}

dynamic "alarms" {
for_each = var.deployment_alarms != null ? var.deployment_alarms : []
content {
alarm_names = try(alarms.value.alarm_names, [])
enable = try(alarms.value.enable, false)
rollback = try(alarms.value.rollback, false)
}
}

dynamic "load_balancer" {
# tflint-ignore: terraform_deprecated_lookup
for_each = var.load_balanced ? var.target_groups : []
content {
container_name = try(load_balancer.value, "container_name") != "" ? lookup(load_balancer.value, "container_name") : var.name_prefix
container_port = lookup(load_balancer.value, "container_port", var.task_container_port)
# tflint-ignore: terraform_deprecated_lookup
container_name = try(load_balancer.value, "container_name") != "" ? lookup(load_balancer.value, "container_name") : var.name_prefix
container_port = lookup(load_balancer.value, "container_port", var.task_container_port)
# tflint-ignore: terraform_deprecated_lookup
target_group_arn = aws_lb_target_group.task[lookup(load_balancer.value, "target_group_name")].arn
}
}
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ variable "capacity_provider_strategy" {
default = []
}

variable "deployment_alarms" {
type = list(object({
alarm_names = list(string)
rollback = bool
enable = bool
}))
description = "Information about the CloudWatch alarms"
default = []
}

variable "placement_constraints" {
type = list(any)
description = "(Optional) A set of placement constraints rules that are taken into consideration during task placement. Maximum number of placement_constraints is 10. This is a list of maps, where each map should contain \"type\" and \"expression\""
Expand Down

0 comments on commit dcdffa0

Please sign in to comment.