From a013712b49467db246cc48dce3d9975969be047f Mon Sep 17 00:00:00 2001 From: Allan Denot Date: Wed, 16 Oct 2024 15:16:16 +1000 Subject: [PATCH 1/2] Fix for creating when cluster does not exist yet --- _data.tf | 8 -------- _variables.tf | 8 ++++++++ cloudwatch-alarms.tf | 2 +- cloudwatch-ecs-event-logs.tf | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/_data.tf b/_data.tf index 0636f16..28f4892 100644 --- a/_data.tf +++ b/_data.tf @@ -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 -} diff --git a/_variables.tf b/_variables.tf index bc07636..fad00e3 100644 --- a/_variables.tf +++ b/_variables.tf @@ -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 @@ -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 = "" diff --git a/cloudwatch-alarms.tf b/cloudwatch-alarms.tf index 6b2c536..76dabd5 100644 --- a/cloudwatch-alarms.tf +++ b/cloudwatch-alarms.tf @@ -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 } diff --git a/cloudwatch-ecs-event-logs.tf b/cloudwatch-ecs-event-logs.tf index ef3c9bd..4081f7d 100644 --- a/cloudwatch-ecs-event-logs.tf +++ b/cloudwatch-ecs-event-logs.tf @@ -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}"] } } @@ -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}" -} \ No newline at end of file +} From 2a462c5b4d136097ed9478346ccc819f44dd0e74 Mon Sep 17 00:00:00 2001 From: adenot Date: Wed, 16 Oct 2024 05:17:06 +0000 Subject: [PATCH 2/2] terraform-docs: automated update action --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e940269..8d8bf65 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -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 |