diff --git a/CHANGELOG.md b/CHANGELOG.md index 62c93a0..2b5babe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [5.0.0] - 2023-03-17 +### Breaking +- Now will create the ECS cluster for you unless disabled with `create_ecs_cluster = false` + ## [4.0.0] - 2022-02-15 ### Breaking - Removing the unneeded var nat_gateway_public_ip_cidrs diff --git a/main.tf b/main.tf index 7da89ea..47210f9 100644 --- a/main.tf +++ b/main.tf @@ -64,7 +64,7 @@ module "gatus" { container_port = 8080 - cluster_name = var.cluster_name + cluster_name = var.create_ecs_cluster ? aws_ecs_cluster.cluster[0].name : data.aws_ecs_cluster.cluster[0].cluster_name iam_role_path = var.iam_role_path iam_role_permissions_boundary = var.iam_role_permissions_boundary @@ -182,3 +182,19 @@ resource "aws_security_group_rule" "allow_fargate_into_efs" { security_group_id = aws_security_group.efs.id source_security_group_id = module.gatus.security_group_id } + +# Create or fetch the ECS cluster +resource "aws_ecs_cluster" "cluster" { + count = var.create_ecs_cluster ? 1 : 0 + name = var.cluster_name + + setting { + name = "containerInsights" + value = "enabled" + } +} + +data "aws_ecs_cluster" "cluster" { + count = var.create_ecs_cluster ? 0 : 1 + cluster_name = var.cluster_name +} diff --git a/variables.tf b/variables.tf index 35293e2..2c5b938 100644 --- a/variables.tf +++ b/variables.tf @@ -72,3 +72,9 @@ variable "kms_key_id" { description = "For encrypting the EFS drive; defaults to the aws managed efs key" type = string } + +variable "create_ecs_cluster" { + default = true + type = bool + description = "Toggles either creating the ECS Cluster or looking up an existing one" +}