Skip to content

Commit

Permalink
Fix for creating when cluster does not exist yet (#54)
Browse files Browse the repository at this point in the history
* Fix for creating when cluster does not exist yet

* terraform-docs: automated update action

---------

Co-authored-by: adenot <[email protected]>
  • Loading branch information
adenot and adenot authored Oct 16, 2024
1 parent 6dfab31 commit 0ee07b9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ In addition you have the option to create or not :
| alarm\_min\_healthy\_tasks | Alarm when the number of healthy tasks is less than this number (use 0 to disable this alarm) | `number` | `2` | no |
| alarm\_prefix | String prefix for cloudwatch alarms. (Optional) | `string` | `"alarm"` | no |
| alarm\_sns\_topics | Alarm topics to create and alert on ECS service metrics. Leaving empty disables all alarms. | `list` | `[]` | no |
| alb\_arn | ALB ARN created by ECS cluster module | `any` | n/a | yes |
| alb\_dns\_name | ALB DNS Name | `string` | `""` | no |
| alb\_listener\_https\_arn | ALB HTTPS Listener created by ECS cluster module | `any` | n/a | yes |
| alb\_name | ALB name - Required if it is an internal one | `string` | `""` | no |
Expand Down Expand Up @@ -93,6 +94,7 @@ In addition you have the option to create or not :
| cloudwatch\_logs\_create | Whether to create cloudwatch log resources or not | `bool` | `true` | no |
| cloudwatch\_logs\_export | Whether to mark the log group to export to an S3 bucket (needs terraform-aws-log-exporter to be deployed in the account/region) | `bool` | `false` | no |
| cloudwatch\_logs\_retention | Specifies the number of days you want to retain log events in the specified log group. Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653. | `number` | `120` | no |
| cluster\_arn | n/a | `string` | `"ARN of existing ECS Cluster to deploy this app to"` | no |
| cluster\_name | n/a | `string` | `"Name of existing ECS Cluster to deploy this app to"` | no |
| command | Command to run on container | `list(string)` | `null` | no |
| compat\_keep\_target\_group\_naming | Keeps old naming convention for target groups to avoid recreation of resource in production environments | `bool` | `false` | no |
Expand Down
8 changes: 0 additions & 8 deletions _data.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
data "aws_region" "current" {}

data "aws_lb_listener" "ecs" {
arn = var.alb_listener_https_arn
}

data "aws_iam_account_alias" "current" {
count = var.alarm_prefix == "" ? 1 : 0
}

data "aws_ecs_cluster" "ecs_cluster" {
cluster_name = var.cluster_name
}
8 changes: 8 additions & 0 deletions _variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ variable "cluster_name" {
default = "Name of existing ECS Cluster to deploy this app to"
}

variable "cluster_arn" {
default = "ARN of existing ECS Cluster to deploy this app to"
}

variable "service_role_arn" {
description = "Existing service role ARN created by ECS cluster module"
default = null
Expand Down Expand Up @@ -135,6 +139,10 @@ variable "alb_listener_https_arn" {
description = "ALB HTTPS Listener created by ECS cluster module"
}

variable "alb_arn" {
description = "ALB ARN created by ECS cluster module"
}

variable "alb_dns_name" {
description = "ALB DNS Name"
default = ""
Expand Down
2 changes: 1 addition & 1 deletion cloudwatch-alarms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resource "aws_cloudwatch_metric_alarm" "min_healthy_tasks" {
unit = "Count"

dimensions = {
LoadBalancer = join("/", slice(split("/", data.aws_lb_listener.ecs.load_balancer_arn), 1, 4))
LoadBalancer = join("/", slice(split("/", var.alb_arn), 1, 4))
TargetGroup = aws_lb_target_group.green.arn_suffix
}

Expand Down
4 changes: 2 additions & 2 deletions cloudwatch-ecs-event-logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource "aws_cloudwatch_event_rule" "ecs_events" {
"source": ["aws.ecs"],
"detail-type": ["ECS Task State Change", "ECS Container Instance State Change"],
"detail": {
"clusterArn": ["${data.aws_ecs_cluster.ecs_cluster.arn}"],
"clusterArn": ["${var.cluster_arn}"],
"group": ["service:${var.name}"]
}
}
Expand Down Expand Up @@ -59,4 +59,4 @@ resource "aws_cloudwatch_log_resource_policy" "ecs_events" {
policy_document = data.aws_iam_policy_document.ecs_events[0].json
policy_name = "capture-ecs-events-${var.cluster_name}-${var.name}"

}
}

0 comments on commit 0ee07b9

Please sign in to comment.