From ef479db37d2bd8b4db5c3acff00e947a4ca4b688 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Mon, 8 Jun 2026 08:06:23 +0100 Subject: [PATCH 01/13] files todo --- infrastructure/modules/ecs-cluster-2/README.md | 2 ++ infrastructure/modules/ecs-cluster-2/main.tf | 1 + infrastructure/modules/ecs-cluster-2/outputs.tf | 1 + infrastructure/modules/ecs-cluster-2/variables.tf | 1 + 4 files changed, 5 insertions(+) create mode 100644 infrastructure/modules/ecs-cluster-2/README.md create mode 100644 infrastructure/modules/ecs-cluster-2/main.tf create mode 100644 infrastructure/modules/ecs-cluster-2/outputs.tf create mode 100644 infrastructure/modules/ecs-cluster-2/variables.tf diff --git a/infrastructure/modules/ecs-cluster-2/README.md b/infrastructure/modules/ecs-cluster-2/README.md new file mode 100644 index 00000000..6918080c --- /dev/null +++ b/infrastructure/modules/ecs-cluster-2/README.md @@ -0,0 +1,2 @@ +# DAVEH: write docs +# DAVEH: rename to replace existing module? diff --git a/infrastructure/modules/ecs-cluster-2/main.tf b/infrastructure/modules/ecs-cluster-2/main.tf new file mode 100644 index 00000000..c9fb5240 --- /dev/null +++ b/infrastructure/modules/ecs-cluster-2/main.tf @@ -0,0 +1 @@ +# DAVEH diff --git a/infrastructure/modules/ecs-cluster-2/outputs.tf b/infrastructure/modules/ecs-cluster-2/outputs.tf new file mode 100644 index 00000000..c9fb5240 --- /dev/null +++ b/infrastructure/modules/ecs-cluster-2/outputs.tf @@ -0,0 +1 @@ +# DAVEH diff --git a/infrastructure/modules/ecs-cluster-2/variables.tf b/infrastructure/modules/ecs-cluster-2/variables.tf new file mode 100644 index 00000000..c9fb5240 --- /dev/null +++ b/infrastructure/modules/ecs-cluster-2/variables.tf @@ -0,0 +1 @@ +# DAVEH From fc020e27d7138e290e4a02c8ed68e1d1ce7703bd Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Mon, 8 Jun 2026 08:07:59 +0100 Subject: [PATCH 02/13] copy in context --- .../modules/ecs-cluster-2/context.tf | 374 ++++++++++++++++++ 1 file changed, 374 insertions(+) create mode 100644 infrastructure/modules/ecs-cluster-2/context.tf diff --git a/infrastructure/modules/ecs-cluster-2/context.tf b/infrastructure/modules/ecs-cluster-2/context.tf new file mode 100644 index 00000000..e7b516e5 --- /dev/null +++ b/infrastructure/modules/ecs-cluster-2/context.tf @@ -0,0 +1,374 @@ +# +# ONLY EDIT THIS FILE IN github.com/NHSDigital/screening-terraform-modules-aws/infrastructure/modules/tags +# All other instances of this file should be a copy of that one +# +# +# Copy this file from https://github.com/NHSDigital/screening-terraform-modules-aws/blob/master/infrastructure/modules/tags/exports/context.tf +# and then place it in your Terraform module to automatically get +# tag module standard configuration inputs suitable for passing +# to other modules. +# +# curl -sL https://raw.githubusercontent.com/NHSDigital/screening-terraform-modules-aws/master/infrastructure/modules/tags/exports/context.tf -o context.tf +# +# Modules should access the whole context as `module.this.context` +# to get the input variables with nulls for defaults, +# for example `context = module.this.context`, +# and access individual variables as `module.this.`, +# with final values filled in. +# +# For example, when using defaults, `module.this.context.delimiter` +# will be null, and `module.this.delimiter` will be `-` (hyphen). +# + +module "this" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/tags" + + service = var.service + project = var.project + region = var.region + environment = var.environment + stack = var.stack + workspace = var.workspace + name = var.name + delimiter = var.delimiter + attributes = var.attributes + tags = var.tags + additional_tag_map = var.additional_tag_map + label_order = var.label_order + regex_replace_chars = var.regex_replace_chars + id_length_limit = var.id_length_limit + label_key_case = var.label_key_case + label_value_case = var.label_value_case + terraform_source = coalesce(var.terraform_source, path.module) + descriptor_formats = var.descriptor_formats + labels_as_tags = var.labels_as_tags + + context = var.context +} + +# Copy contents of screening-terraform-modules-aws/tags/variables.tf here +# tflint-ignore: terraform_unused_declarations +variable "aws_region" { + type = string + description = "The AWS region" + default = "eu-west-2" + validation { + condition = contains(["eu-west-1", "eu-west-2", "us-east-1"], var.aws_region) + error_message = "AWS Region must be one of eu-west-1, eu-west-2, us-east-1" + } +} + +variable "context" { + type = any + default = { + enabled = true + service = null + project = null + region = null + environment = null + stack = null + workspace = null + name = null + delimiter = null + attributes = [] + tags = {} + additional_tag_map = {} + regex_replace_chars = null + label_order = [] + id_length_limit = null + label_key_case = null + label_value_case = null + terraform_source = null + descriptor_formats = {} + # Note: we have to use [] instead of null for unset lists due to + # https://github.com/hashicorp/terraform/issues/28137 + # which was not fixed until Terraform 1.0.0, + # but we want the default to be all the labels in `label_order` + # and we want users to be able to prevent all tag generation + # by setting `labels_as_tags` to `[]`, so we need + # a different sentinel to indicate "default" + labels_as_tags = ["unset"] + } + description = <<-EOT + Single object for setting entire context at once. + See description of individual variables for details. + Leave string and numeric variables as `null` to use default value. + Individual variable settings (non-null) override settings in context object, + except for attributes, tags, and additional_tag_map, which are merged. + EOT + + validation { + condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"]) + error_message = "Allowed values: `lower`, `title`, `upper`." + } + + validation { + condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"]) + error_message = "Allowed values: `lower`, `title`, `upper`, `none`." + } +} + +variable "terraform_source" { + type = string + default = null + description = "Source location to record in the Terraform_source tag. Defaults to the caller module path when not set." +} + +variable "enabled" { + type = bool + default = null + description = "Set to false to prevent the module from creating any resources" +} + +variable "service" { + type = string + default = null + description = "ID element. Usually an abbreviation of your service directorate name, e.g. 'bcss' or 'csms', to help ensure generated IDs are globally unique" +} + +variable "region" { + type = string + default = null + description = "ID element _(Rarely used, not included by default)_. Usually an abbreviation of the selected AWS region e.g. 'uw2', 'ew2' or 'gbl' for resources like IAM roles that have no region" +} + +variable "project" { + type = string + default = null + description = "ID element. A project identifier, indicating the name or role of the project the resource is for, such as `website` or `api`" +} +variable "stack" { + type = string + default = null + description = "ID element. The name of the stack/component, e.g. `database`, `web`, `waf`, `eks`" +} +variable "workspace" { + type = string + default = null + description = "ID element. The Terraform workspace, to help ensure generated IDs are unique across workspaces" +} +variable "environment" { + type = string + default = null + description = "ID element. Usually used to indicate role, e.g. 'prd', 'dev', 'test', 'preprod', 'prod', 'uat'" +} + +variable "name" { + type = string + default = null + description = <<-EOT + ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'. + This is the only ID element not also included as a `tag`. + The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. + EOT +} + +variable "delimiter" { + type = string + default = null + description = <<-EOT + Delimiter to be used between ID elements. + Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. + EOT +} + +variable "attributes" { + type = list(string) + default = [] + description = <<-EOT + ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`, + in the order they appear in the list. New attributes are appended to the + end of the list. The elements of the list are joined by the `delimiter` + and treated as a single ID element. + EOT +} + +variable "labels_as_tags" { + type = set(string) + default = ["default"] + description = <<-EOT + Set of labels (ID elements) to include as tags in the `tags` output. + Default is to include all labels. + Tags with empty values will not be included in the `tags` output. + Set to `[]` to suppress all generated tags. + **Notes:** + The value of the `name` tag, if included, will be the `id`, not the `name`. + Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be + changed in later chained modules. Attempts to change it will be silently ignored. + EOT +} + +variable "tags" { + type = map(string) + default = {} + description = <<-EOT + Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`). + Neither the tag keys nor the tag values will be modified by this module. + EOT +} + +variable "additional_tag_map" { + type = map(string) + default = {} + description = <<-EOT + Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`. + This is for some rare cases where resources want additional configuration of tags + and therefore take a list of maps with tag key, value, and additional configuration. + EOT +} + +variable "label_order" { + type = list(string) + default = null + description = <<-EOT + The order in which the labels (ID elements) appear in the `id`. + Defaults to ["namespace", "environment", "stage", "name", "attributes"]. + You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. + EOT +} + +variable "regex_replace_chars" { + type = string + default = null + description = <<-EOT + Terraform regular expression (regex) string. + Characters matching the regex will be removed from the ID elements. + If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. + EOT +} + +variable "id_length_limit" { + type = number + default = null + description = <<-EOT + Limit `id` to this many characters (minimum 6). + Set to `0` for unlimited length. + Set to `null` for keep the existing setting, which defaults to `0`. + Does not affect `id_full`. + EOT + validation { + condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0 + error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length." + } +} + +variable "label_key_case" { + type = string + default = null + description = <<-EOT + Controls the letter case of the `tags` keys (label names) for tags generated by this module. + Does not affect keys of tags passed in via the `tags` input. + Possible values: `lower`, `title`, `upper`. + Default value: `title`. + EOT + + validation { + condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case) + error_message = "Allowed values: `lower`, `title`, `upper`." + } +} + +variable "label_value_case" { + type = string + default = null + description = <<-EOT + Controls the letter case of ID elements (labels) as included in `id`, + set as tag values, and output by this module individually. + Does not affect values of tags passed in via the `tags` input. + Possible values: `lower`, `title`, `upper` and `none` (no transformation). + Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs. + Default value: `lower`. + EOT + + validation { + condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case) + error_message = "Allowed values: `lower`, `title`, `upper`, `none`." + } +} + +variable "descriptor_formats" { + type = any + default = {} + description = <<-EOT + Describe additional descriptors to be output in the `descriptors` output map. + Map of maps. Keys are names of descriptors. Values are maps of the form + `{ + format = string + labels = list(string) + }` + (Type is `any` so the map values can later be enhanced to provide additional options.) + `format` is a Terraform format string to be passed to the `format()` function. + `labels` is a list of labels, in order, to pass to `format()` function. + Label values will be normalized before being passed to `format()` so they will be + identical to how they appear in `id`. + Default is `{}` (`descriptors` output will be empty). + EOT +} + +variable "owner" { + type = string + description = "The name and or NHS.net email address of the service owner" + default = "None" +} + +variable "tag_version" { + type = string + description = "Used to identify the tagging version in use" + default = "1.0" +} + +variable "data_classification" { + type = string + description = "Used to identify the data classification of the resource, e.g 1-5" + default = "n/a" + validation { + condition = contains(["n/a", "1", "2", "3", "4", "5"], var.data_classification) + error_message = "Data Classification must be \"n/a\" or between 1-5" + } +} + +variable "data_type" { + type = string + description = "The tag data_type" + default = "None" + validation { + condition = contains(["None", "PCD", "PID", "Anonymised", "UserAccount", "Audit"], var.data_type) + error_message = "Data Type must be one of None, PCD, PID, Anonymised, UserAccount, Audit" + } +} + + +variable "public_facing" { + type = bool + description = "Whether this resource is public facing" + default = false +} + +variable "service_category" { + type = string + description = "The tag service_category" + default = "n/a" + validation { + condition = contains(["n/a", "Bronze", "Silver", "Gold", "Platinum"], var.service_category) + error_message = "The Service Category must be one of n/a, Bronze, Silver, Gold, Platinum" + } +} +variable "on_off_pattern" { + type = string + description = "Used to turn resources on and off based on a time pattern" + default = "n/a" +} + +variable "application_role" { + type = string + description = "The role the application is performing" + default = "General" +} + +variable "tool" { + type = string + description = "The tool used to deploy the resource" + default = "Terraform" +} + +#### End of copy of screening-terraform-modules-aws/tags/variables.tf From 662daf8360d4c94abc07c05c2cac3b761d2da715 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Mon, 8 Jun 2026 08:12:54 +0100 Subject: [PATCH 03/13] source, gate --- infrastructure/modules/ecs-cluster-2/main.tf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/infrastructure/modules/ecs-cluster-2/main.tf b/infrastructure/modules/ecs-cluster-2/main.tf index c9fb5240..c35706eb 100644 --- a/infrastructure/modules/ecs-cluster-2/main.tf +++ b/infrastructure/modules/ecs-cluster-2/main.tf @@ -1 +1,8 @@ # DAVEH + +module "ecs_cluster" { + source = "terraform-aws-modules/ecs/aws//modules/cluster" + version = "~> 7.5.0" + + create = module.this.enabled +} From 43f5cec48f0f891e2b8583e37955f82e1cf39817 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Mon, 8 Jun 2026 08:26:27 +0100 Subject: [PATCH 04/13] name, region, tags --- infrastructure/modules/ecs-cluster-2/main.tf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/infrastructure/modules/ecs-cluster-2/main.tf b/infrastructure/modules/ecs-cluster-2/main.tf index c35706eb..abe0f02c 100644 --- a/infrastructure/modules/ecs-cluster-2/main.tf +++ b/infrastructure/modules/ecs-cluster-2/main.tf @@ -5,4 +5,8 @@ module "ecs_cluster" { version = "~> 7.5.0" create = module.this.enabled + + name = module.this.name + region = module.this.region + tags = module.this.tags } From 15764a9f7b2dbb94b770eb3d28e6e9fc74add47b Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Mon, 8 Jun 2026 08:59:24 +0100 Subject: [PATCH 05/13] specify all remaining parameters with default values --- infrastructure/modules/ecs-cluster-2/main.tf | 69 +++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/infrastructure/modules/ecs-cluster-2/main.tf b/infrastructure/modules/ecs-cluster-2/main.tf index abe0f02c..92e92375 100644 --- a/infrastructure/modules/ecs-cluster-2/main.tf +++ b/infrastructure/modules/ecs-cluster-2/main.tf @@ -1,5 +1,3 @@ -# DAVEH - module "ecs_cluster" { source = "terraform-aws-modules/ecs/aws//modules/cluster" version = "~> 7.5.0" @@ -9,4 +7,71 @@ module "ecs_cluster" { name = module.this.name region = module.this.region tags = module.this.tags + + capacity_providers = null # DAVEH + + cloudwatch_log_group_class = null # DAVEH + cloudwatch_log_group_kms_key_id = null # DAVEH + cloudwatch_log_group_name = null # DAVEH + cloudwatch_log_group_retention_in_days = 90 # DAVEH + cloudwatch_log_group_tags = {} # DAVEH + + cluster_capacity_providers = [] # DAVEH + cluster_capacity_providers_wait_duration = "20s" # DAVEH + + configuration = { "execute_command_configuration" : { "log_configuration" : { "cloud_watch_log_group_name" : "placeholder" } } } # DAVEH + + create_cloudwatch_log_group = true # DAVEH + create_infrastructure_iam_role = true # DAVEH + create_node_iam_instance_profile = true # DAVEH + create_security_group = true # DAVEH + create_task_exec_iam_role = true # DAVEH + create_task_exec_policy = true # DAVEH + + default_capacity_provider_strategy = {} # DAVEH + + infrastructure_iam_role_description = null # DAVEH + infrastructure_iam_role_name = null # DAVEH + infrastructure_iam_role_override_policy_documents = [] # DAVEH + infrastructure_iam_role_path = null # DAVEH + infrastructure_iam_role_permissions_boundary = null # DAVEH + infrastructure_iam_role_source_policy_documents = [] # DAVEH + infrastructure_iam_role_statements = null # DAVEH + infrastructure_iam_role_tags = {} # DAVEH + infrastructure_iam_role_use_name_prefix = true # DAVEH + + node_iam_role_additional_policies = {} # DAVEH + node_iam_role_description = "ECS Managed Instances node IAM role" # DAVEH + node_iam_role_name = null # DAVEH + node_iam_role_override_policy_documents = [] # DAVEH + node_iam_role_path = null # DAVEH + node_iam_role_permissions_boundary = null # DAVEH + node_iam_role_source_policy_documents = [] # DAVEH + node_iam_role_statements = null # DAVEH + node_iam_role_tags = {} # DAVEH + node_iam_role_use_name_prefix = true # DAVEH + + security_group_description = null # DAVEH + security_group_egress_rules = { "all_ipv4" : { "cidr_ipv4" : "0.0.0.0/0", "description" : "Allow all IPv4 traffic", "ip_protocol" : "-1" }, "all_ipv6" : { "cidr_ipv6" : "::/0", "description" : "Allow all IPv6 traffic", "ip_protocol" : "-1" } } # DAVEH + security_group_ingress_rules = {} # DAVEH + security_group_name = null # DAVEH + security_group_tags = {} # DAVEH + security_group_use_name_prefix = true # DAVEH + + service_connect_defaults = null # DAVEH + + setting = [{ "name" : "containerInsights", "value" : "enabled" }] # DAVEH + + task_exec_iam_role_description = null # DAVEH + task_exec_iam_role_name = null # DAVEH + task_exec_iam_role_path = null # DAVEH + task_exec_iam_role_permissions_boundary = null # DAVEH + task_exec_iam_role_policies = {} # DAVEH + task_exec_iam_role_tags = {} # DAVEH + task_exec_iam_role_use_name_prefix = true # DAVEH + task_exec_iam_statements = null # DAVEH + task_exec_secret_arns = [] # DAVEH + task_exec_ssm_param_arns = [] # DAVEH + + vpc_id = null # DAVEH } From 853a4b8ec2c1765dd1800ea4455499cce5b5179a Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Mon, 8 Jun 2026 09:16:37 +0100 Subject: [PATCH 06/13] var.capacity_providers --- infrastructure/modules/ecs-cluster-2/main.tf | 2 +- .../modules/ecs-cluster-2/variables.tf | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/infrastructure/modules/ecs-cluster-2/main.tf b/infrastructure/modules/ecs-cluster-2/main.tf index 92e92375..8d393253 100644 --- a/infrastructure/modules/ecs-cluster-2/main.tf +++ b/infrastructure/modules/ecs-cluster-2/main.tf @@ -8,7 +8,7 @@ module "ecs_cluster" { region = module.this.region tags = module.this.tags - capacity_providers = null # DAVEH + capacity_providers = var.capacity_providers cloudwatch_log_group_class = null # DAVEH cloudwatch_log_group_kms_key_id = null # DAVEH diff --git a/infrastructure/modules/ecs-cluster-2/variables.tf b/infrastructure/modules/ecs-cluster-2/variables.tf index c9fb5240..2a216117 100644 --- a/infrastructure/modules/ecs-cluster-2/variables.tf +++ b/infrastructure/modules/ecs-cluster-2/variables.tf @@ -1 +1,68 @@ # DAVEH + +variable "capacity_providers" { + type = map(object({ + auto_scaling_group_provider = optional(object({ + auto_scaling_group_arn = string + managed_draining = optional(string, "ENABLED") + managed_scaling = optional(object({ + instance_warmup_period = optional(number) + maximum_scaling_step_size = optional(number) + minimum_scaling_step_size = optional(number) + status = optional(string) + target_capacity = optional(number) + })) + managed_termination_protection = optional(string) + })) + managed_instances_provider = optional(object({ + infrastructure_role_arn = optional(string) + instance_launch_template = object({ + capacity_option_type = optional(string) + ec2_instance_profile_arn = optional(string) + instance_requirements = optional(object({ + accelerator_count = optional(object({ + max = optional(number) + min = optional(number) + })) + accelerator_manufacturers = optional(list(string)) + accelerator_names = optional(list(string)) + accelerator_total_memory_mib = optional(object({ + max = optional(number) + min = optional(number) + })) + accelerator_types = optional(list(string)) + allowed_instance_types = optional(list(string)) + bare_metal = optional(string) + baseline_ebs_bandwidth_mbps = optional(object({ + max = optional(number) + min = optional(number) + })) + burstable_performance = optional(string) + cpu_manufacturers = optional(list(string)) + excluded_instance_types = optional(list(string)) + instance_generations = optional(list(string)) + local_storage = optional(string) + local_storage_types = optional(list(string)) + max_spot_price_as_percentage_of_optimal_on_demand_price = optional(number) + memory_gib_per_vcpu = optional(object({ max = optional(number) min = optional(number) })) + memory_mib = optional(object({ max = optional(number) min = optional(number) })) + network_bandwidth_gbps = optional(object({ max = optional(number) min = optional(number) })) + network_interface_count = optional(object({ max = optional(number) min = optional(number) })) + on_demand_max_price_percentage_over_lowest_price = optional(number) + require_hibernate_support = optional(bool) + spot_max_price_percentage_over_lowest_price = optional(number) + total_local_storage_gb = optional(object({ max = optional(number) min = optional(number) })) + vcpu_count = optional(object({ max = optional(number) min = optional(number) })) + })) + monitoring = optional(string) + network_configuration = optional(object({ security_groups = optional(list(string), []) subnets = list(string) })) + storage_configuration = optional(object({ storage_size_gib = number })) + }) + propagate_tags = optional(string, "CAPACITY_PROVIDER") + })) + name = optional(string) # Will fall back to use map key if not set + tags = optional(map(string), {}) + })) + default = null + description = "Map of capacity provider definitions to create" +} From 233a356ddf3ee245aa9ea3bf761c6561a5b320b0 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Tue, 9 Jun 2026 14:32:59 +0100 Subject: [PATCH 07/13] rm unused variables, settings that were being left at default --- infrastructure/modules/ecs-cluster-2/main.tf | 67 ------------------ .../modules/ecs-cluster-2/variables.tf | 68 ------------------- 2 files changed, 135 deletions(-) delete mode 100644 infrastructure/modules/ecs-cluster-2/variables.tf diff --git a/infrastructure/modules/ecs-cluster-2/main.tf b/infrastructure/modules/ecs-cluster-2/main.tf index 8d393253..116f50d4 100644 --- a/infrastructure/modules/ecs-cluster-2/main.tf +++ b/infrastructure/modules/ecs-cluster-2/main.tf @@ -7,71 +7,4 @@ module "ecs_cluster" { name = module.this.name region = module.this.region tags = module.this.tags - - capacity_providers = var.capacity_providers - - cloudwatch_log_group_class = null # DAVEH - cloudwatch_log_group_kms_key_id = null # DAVEH - cloudwatch_log_group_name = null # DAVEH - cloudwatch_log_group_retention_in_days = 90 # DAVEH - cloudwatch_log_group_tags = {} # DAVEH - - cluster_capacity_providers = [] # DAVEH - cluster_capacity_providers_wait_duration = "20s" # DAVEH - - configuration = { "execute_command_configuration" : { "log_configuration" : { "cloud_watch_log_group_name" : "placeholder" } } } # DAVEH - - create_cloudwatch_log_group = true # DAVEH - create_infrastructure_iam_role = true # DAVEH - create_node_iam_instance_profile = true # DAVEH - create_security_group = true # DAVEH - create_task_exec_iam_role = true # DAVEH - create_task_exec_policy = true # DAVEH - - default_capacity_provider_strategy = {} # DAVEH - - infrastructure_iam_role_description = null # DAVEH - infrastructure_iam_role_name = null # DAVEH - infrastructure_iam_role_override_policy_documents = [] # DAVEH - infrastructure_iam_role_path = null # DAVEH - infrastructure_iam_role_permissions_boundary = null # DAVEH - infrastructure_iam_role_source_policy_documents = [] # DAVEH - infrastructure_iam_role_statements = null # DAVEH - infrastructure_iam_role_tags = {} # DAVEH - infrastructure_iam_role_use_name_prefix = true # DAVEH - - node_iam_role_additional_policies = {} # DAVEH - node_iam_role_description = "ECS Managed Instances node IAM role" # DAVEH - node_iam_role_name = null # DAVEH - node_iam_role_override_policy_documents = [] # DAVEH - node_iam_role_path = null # DAVEH - node_iam_role_permissions_boundary = null # DAVEH - node_iam_role_source_policy_documents = [] # DAVEH - node_iam_role_statements = null # DAVEH - node_iam_role_tags = {} # DAVEH - node_iam_role_use_name_prefix = true # DAVEH - - security_group_description = null # DAVEH - security_group_egress_rules = { "all_ipv4" : { "cidr_ipv4" : "0.0.0.0/0", "description" : "Allow all IPv4 traffic", "ip_protocol" : "-1" }, "all_ipv6" : { "cidr_ipv6" : "::/0", "description" : "Allow all IPv6 traffic", "ip_protocol" : "-1" } } # DAVEH - security_group_ingress_rules = {} # DAVEH - security_group_name = null # DAVEH - security_group_tags = {} # DAVEH - security_group_use_name_prefix = true # DAVEH - - service_connect_defaults = null # DAVEH - - setting = [{ "name" : "containerInsights", "value" : "enabled" }] # DAVEH - - task_exec_iam_role_description = null # DAVEH - task_exec_iam_role_name = null # DAVEH - task_exec_iam_role_path = null # DAVEH - task_exec_iam_role_permissions_boundary = null # DAVEH - task_exec_iam_role_policies = {} # DAVEH - task_exec_iam_role_tags = {} # DAVEH - task_exec_iam_role_use_name_prefix = true # DAVEH - task_exec_iam_statements = null # DAVEH - task_exec_secret_arns = [] # DAVEH - task_exec_ssm_param_arns = [] # DAVEH - - vpc_id = null # DAVEH } diff --git a/infrastructure/modules/ecs-cluster-2/variables.tf b/infrastructure/modules/ecs-cluster-2/variables.tf deleted file mode 100644 index 2a216117..00000000 --- a/infrastructure/modules/ecs-cluster-2/variables.tf +++ /dev/null @@ -1,68 +0,0 @@ -# DAVEH - -variable "capacity_providers" { - type = map(object({ - auto_scaling_group_provider = optional(object({ - auto_scaling_group_arn = string - managed_draining = optional(string, "ENABLED") - managed_scaling = optional(object({ - instance_warmup_period = optional(number) - maximum_scaling_step_size = optional(number) - minimum_scaling_step_size = optional(number) - status = optional(string) - target_capacity = optional(number) - })) - managed_termination_protection = optional(string) - })) - managed_instances_provider = optional(object({ - infrastructure_role_arn = optional(string) - instance_launch_template = object({ - capacity_option_type = optional(string) - ec2_instance_profile_arn = optional(string) - instance_requirements = optional(object({ - accelerator_count = optional(object({ - max = optional(number) - min = optional(number) - })) - accelerator_manufacturers = optional(list(string)) - accelerator_names = optional(list(string)) - accelerator_total_memory_mib = optional(object({ - max = optional(number) - min = optional(number) - })) - accelerator_types = optional(list(string)) - allowed_instance_types = optional(list(string)) - bare_metal = optional(string) - baseline_ebs_bandwidth_mbps = optional(object({ - max = optional(number) - min = optional(number) - })) - burstable_performance = optional(string) - cpu_manufacturers = optional(list(string)) - excluded_instance_types = optional(list(string)) - instance_generations = optional(list(string)) - local_storage = optional(string) - local_storage_types = optional(list(string)) - max_spot_price_as_percentage_of_optimal_on_demand_price = optional(number) - memory_gib_per_vcpu = optional(object({ max = optional(number) min = optional(number) })) - memory_mib = optional(object({ max = optional(number) min = optional(number) })) - network_bandwidth_gbps = optional(object({ max = optional(number) min = optional(number) })) - network_interface_count = optional(object({ max = optional(number) min = optional(number) })) - on_demand_max_price_percentage_over_lowest_price = optional(number) - require_hibernate_support = optional(bool) - spot_max_price_percentage_over_lowest_price = optional(number) - total_local_storage_gb = optional(object({ max = optional(number) min = optional(number) })) - vcpu_count = optional(object({ max = optional(number) min = optional(number) })) - })) - monitoring = optional(string) - network_configuration = optional(object({ security_groups = optional(list(string), []) subnets = list(string) })) - storage_configuration = optional(object({ storage_size_gib = number })) - }) - propagate_tags = optional(string, "CAPACITY_PROVIDER") - })) - name = optional(string) # Will fall back to use map key if not set - tags = optional(map(string), {}) - })) - default = null - description = "Map of capacity provider definitions to create" -} From 4ef2b734222d1bba5f1749741e622da3956f3883 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Tue, 9 Jun 2026 14:38:13 +0100 Subject: [PATCH 08/13] add outputs we will need --- infrastructure/modules/ecs-cluster-2/outputs.tf | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/infrastructure/modules/ecs-cluster-2/outputs.tf b/infrastructure/modules/ecs-cluster-2/outputs.tf index c9fb5240..5334d268 100644 --- a/infrastructure/modules/ecs-cluster-2/outputs.tf +++ b/infrastructure/modules/ecs-cluster-2/outputs.tf @@ -1 +1,9 @@ -# DAVEH +output "cluster_arn" { + description = "ARN that identifies the cluster" + value = module.ecs_cluster.arn +} + +output "cluster_name" { + description = "Name that identifies the cluster" + value = module.ecs_cluster.name +} From f781fefced796f43bbd9a58c2783755ff43af4f7 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Tue, 9 Jun 2026 15:31:23 +0100 Subject: [PATCH 09/13] add tfdocs placceholders --- infrastructure/modules/ecs-cluster-2/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/infrastructure/modules/ecs-cluster-2/README.md b/infrastructure/modules/ecs-cluster-2/README.md index 6918080c..448d3d04 100644 --- a/infrastructure/modules/ecs-cluster-2/README.md +++ b/infrastructure/modules/ecs-cluster-2/README.md @@ -1,2 +1,10 @@ # DAVEH: write docs # DAVEH: rename to replace existing module? + + + + +DAVEH + + + From 97fd743be02ebda1a2a1466a1f0022fadce012aa Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Tue, 9 Jun 2026 15:45:58 +0100 Subject: [PATCH 10/13] half-arsed docs --- .../modules/ecs-cluster-2/README.md | 88 ++++++++++++++++++- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/infrastructure/modules/ecs-cluster-2/README.md b/infrastructure/modules/ecs-cluster-2/README.md index 448d3d04..4028c58e 100644 --- a/infrastructure/modules/ecs-cluster-2/README.md +++ b/infrastructure/modules/ecs-cluster-2/README.md @@ -1,10 +1,92 @@ -# DAVEH: write docs -# DAVEH: rename to replace existing module? +# ECS Cluster + +NHS Screening wrapper around the community [`terraform-aws-modules/ecs/aws//modules/cluster`][1] submodule, that consumes the shared `context.tf` for naming and tagging. + +[1]: https://registry.terraform.io/modules/terraform-aws-modules/ecs/aws/latest/submodules/cluster + +## Differences between this module and the ecs-cluster module + +This module creates more stuff, whereas ecs-cluster exposes the security group id. + +## Usage + +### Minimal ECS cluster + +```hcl +module "ecs-cluster" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/ecs-cluster-2?ref=main" + + service = "bcss" + project = "platform" + environment = "prod" + name = "ecs-cluster" +} +``` -DAVEH +## Requirements + +No requirements. + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +| ---- | ------ | ------- | +| [ecs\_cluster](#module\_ecs\_cluster) | terraform-aws-modules/ecs/aws//modules/cluster | ~> 7.5.0 | +| [this](#module\_this) | git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/tags | n/a | + +## Resources + +No resources. + +## Inputs + +| Name | Description | Type | Default | Required | +| ---- | ----------- | ---- | ------- | :------: | +| [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no | +| [application\_role](#input\_application\_role) | The role the application is performing | `string` | `"General"` | no | +| [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no | +| [aws\_region](#input\_aws\_region) | The AWS region | `string` | `"eu-west-2"` | no | +| [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"project": null,
"regex_replace_chars": null,
"region": null,
"service": null,
"stack": null,
"tags": {},
"terraform_source": null,
"workspace": null
}
| no | +| [data\_classification](#input\_data\_classification) | Used to identify the data classification of the resource, e.g 1-5 | `string` | `"n/a"` | no | +| [data\_type](#input\_data\_type) | The tag data\_type | `string` | `"None"` | no | +| [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | +| [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no | +| [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no | +| [environment](#input\_environment) | ID element. Usually used to indicate role, e.g. 'prd', 'dev', 'test', 'preprod', 'prod', 'uat' | `string` | `null` | no | +| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no | +| [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no | +| [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no | +| [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no | +| [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` |
[
"default"
]
| no | +| [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | +| [on\_off\_pattern](#input\_on\_off\_pattern) | Used to turn resources on and off based on a time pattern | `string` | `"n/a"` | no | +| [owner](#input\_owner) | The name and or NHS.net email address of the service owner | `string` | `"None"` | no | +| [project](#input\_project) | ID element. A project identifier, indicating the name or role of the project the resource is for, such as `website` or `api` | `string` | `null` | no | +| [public\_facing](#input\_public\_facing) | Whether this resource is public facing | `bool` | `false` | no | +| [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | +| [region](#input\_region) | ID element \_(Rarely used, not included by default)\_. Usually an abbreviation of the selected AWS region e.g. 'uw2', 'ew2' or 'gbl' for resources like IAM roles that have no region | `string` | `null` | no | +| [service](#input\_service) | ID element. Usually an abbreviation of your service directorate name, e.g. 'bcss' or 'csms', to help ensure generated IDs are globally unique | `string` | `null` | no | +| [service\_category](#input\_service\_category) | The tag service\_category | `string` | `"n/a"` | no | +| [stack](#input\_stack) | ID element. The name of the stack/component, e.g. `database`, `web`, `waf`, `eks` | `string` | `null` | no | +| [tag\_version](#input\_tag\_version) | Used to identify the tagging version in use | `string` | `"1.0"` | no | +| [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no | +| [terraform\_source](#input\_terraform\_source) | Source location to record in the Terraform\_source tag. Defaults to the caller module path when not set. | `string` | `null` | no | +| [tool](#input\_tool) | The tool used to deploy the resource | `string` | `"Terraform"` | no | +| [workspace](#input\_workspace) | ID element. The Terraform workspace, to help ensure generated IDs are unique across workspaces | `string` | `null` | no | + +## Outputs + +| Name | Description | +| ---- | ----------- | +| [cluster\_arn](#output\_cluster\_arn) | ARN that identifies the cluster | +| [cluster\_name](#output\_cluster\_name) | Name that identifies the cluster | From f7abfa3bbc2adcfcd84c66ef638f1040d8387385 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Tue, 9 Jun 2026 17:15:01 +0100 Subject: [PATCH 11/13] source = "../tags" --- infrastructure/modules/ecs-cluster-2/context.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/modules/ecs-cluster-2/context.tf b/infrastructure/modules/ecs-cluster-2/context.tf index e7b516e5..e1afea79 100644 --- a/infrastructure/modules/ecs-cluster-2/context.tf +++ b/infrastructure/modules/ecs-cluster-2/context.tf @@ -21,7 +21,7 @@ # module "this" { - source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/tags" + source = "../tags" service = var.service project = var.project From 5f1b1755d59b5d99cc6302042e620c83197cfe01 Mon Sep 17 00:00:00 2001 From: Oliver Slater Date: Tue, 23 Jun 2026 02:14:48 +0100 Subject: [PATCH 12/13] feat(ecs-cluster): refactor ECS Cluster module from upstream - Introduced a new context.tf file to standardize tagging and naming conventions. - Removed ecs.tf and migrated ECS cluster resource definitions to main.tf using the community ECS cluster module. - Added locals.tf to derive cluster name and CloudWatch log group configurations. - Updated outputs.tf to reflect new output values from the ECS cluster module. - Removed the readme.md file as it was outdated and no longer needed. - Enhanced variables.tf with new variables for ECS cluster configuration, including CloudWatch log group settings and capacity providers. - Updated versions.tf to include the time provider and adjust the AWS provider version. BREAKING CHANGE: Removes original ecs-cluster module that had nested resources i.e. aws_security_group, aws_iam_service_linked_role, aws_sns_topic, aws_cloudwatch_metric_alarm. --- infrastructure/modules/ecs-cluster-2/main.tf | 10 -- .../modules/ecs-cluster-2/outputs.tf | 9 -- .../modules/ecs-cluster/.terraform.lock.hcl | 69 +++++++---- .../{ecs-cluster-2 => ecs-cluster}/README.md | 111 +++++++++++++++--- .../{ecs-cluster-2 => ecs-cluster}/context.tf | 2 + infrastructure/modules/ecs-cluster/ecs.tf | 101 ---------------- infrastructure/modules/ecs-cluster/locals.tf | 24 ++++ infrastructure/modules/ecs-cluster/main.tf | 50 +++++++- infrastructure/modules/ecs-cluster/outputs.tf | 33 ++++-- infrastructure/modules/ecs-cluster/readme.md | 57 --------- .../modules/ecs-cluster/variables.tf | 102 ++++++++++++---- .../modules/ecs-cluster/versions.tf | 6 +- 12 files changed, 322 insertions(+), 252 deletions(-) delete mode 100644 infrastructure/modules/ecs-cluster-2/main.tf delete mode 100644 infrastructure/modules/ecs-cluster-2/outputs.tf rename infrastructure/modules/{ecs-cluster-2 => ecs-cluster}/README.md (60%) rename infrastructure/modules/{ecs-cluster-2 => ecs-cluster}/context.tf (99%) delete mode 100644 infrastructure/modules/ecs-cluster/ecs.tf create mode 100644 infrastructure/modules/ecs-cluster/locals.tf delete mode 100644 infrastructure/modules/ecs-cluster/readme.md diff --git a/infrastructure/modules/ecs-cluster-2/main.tf b/infrastructure/modules/ecs-cluster-2/main.tf deleted file mode 100644 index 116f50d4..00000000 --- a/infrastructure/modules/ecs-cluster-2/main.tf +++ /dev/null @@ -1,10 +0,0 @@ -module "ecs_cluster" { - source = "terraform-aws-modules/ecs/aws//modules/cluster" - version = "~> 7.5.0" - - create = module.this.enabled - - name = module.this.name - region = module.this.region - tags = module.this.tags -} diff --git a/infrastructure/modules/ecs-cluster-2/outputs.tf b/infrastructure/modules/ecs-cluster-2/outputs.tf deleted file mode 100644 index 5334d268..00000000 --- a/infrastructure/modules/ecs-cluster-2/outputs.tf +++ /dev/null @@ -1,9 +0,0 @@ -output "cluster_arn" { - description = "ARN that identifies the cluster" - value = module.ecs_cluster.arn -} - -output "cluster_name" { - description = "Name that identifies the cluster" - value = module.ecs_cluster.name -} diff --git a/infrastructure/modules/ecs-cluster/.terraform.lock.hcl b/infrastructure/modules/ecs-cluster/.terraform.lock.hcl index e73b7fed..7574a855 100644 --- a/infrastructure/modules/ecs-cluster/.terraform.lock.hcl +++ b/infrastructure/modules/ecs-cluster/.terraform.lock.hcl @@ -2,29 +2,54 @@ # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { - version = "6.50.0" - constraints = ">= 6.49.0" + version = "6.51.0" + constraints = ">= 6.14.0, >= 6.34.0, >= 6.42.0" hashes = [ - "h1:8y10QFtGLHl3pF/R1/hO7VCPHTexm1whc0BfuG4uruw=", - "h1:D8uNiOpl3UkAX4zI5T47ALMiRFXTa1XfdQC+TBu3RmE=", - "h1:Uf2LlEibaBdksEUkOoiQbzEbkIgOR6tUE/0tCd36Xzk=", - "h1:gnyVeH3L2erQ/di0a4x5i0AlsIcdLjyK5+Vmbf3qyck=", - "h1:mNg4vBXXqbO0hY2jCxhOyKVrnjEO0viTG2EY4oAlWaQ=", - "zh:0072806bb262c6d86bc25b4a75750e469881144c14818afdba7b82db840e1588", - "zh:1ebc2dae335dad7a8b16a1985b69a63a14954282bb44fdba7d5103f77551ac7b", - "zh:2dab48fe8f3193b8216d578ac1e3674fa566435cc7dbce2953d55b72e31d0241", - "zh:2fc3d3029c2b7429472391ef339672e1fca8e6ff32c8a519bf3acedafa7e24fe", - "zh:38a36e64e7212f6cedac861ea4d449cce07131b3378de601bf9d49a99e000208", - "zh:3ac70758ed251ce78b7f541a5a79cc6fe56474412783ae1decef719bdd0f30bf", - "zh:4385d3903e685bddb2b8005b4eb7db89f030267d4d03c7d792d2f5e739cc874a", - "zh:4cce0760b87fbafd51f30faec2a737f4183b7c615f4a86557f7d3c893a610dc5", - "zh:4feaeed18694239b896c6415d9a1e5ef89e1da4f4ad60924aa0522adeb1f6599", - "zh:502fca2be1c95f443c3e67d0555601d1de65b4ca82d197c059e9c868360e3a0a", - "zh:57d037f6fdd045f2660909c3bdface9622d81165ce647479cba98d1f353c5eab", - "zh:5dc5a0b915c2ac5256d909458f5c8e40b35f78b3a36ea893c86624eaf6c54e37", + "h1:017ISHZZBI+yeqA4AAtgLQJC7Lhd4wYM7tEKYmlk/7Y=", + "h1:4c8zjgtGH0QgP+p/cF1UqdqkvD7V5i0ZxqslieZLTbc=", + "h1:QWxF+1ePJ4qFCHEc6PyHNeXc865wLvrWVl71d/nABa8=", + "h1:aPBmqoiYqfrIgCGwzuemljkOXuGCYQRTXo91nQxrE+s=", + "h1:bclp+xS1fYeOCil0XZO6mKvEeHFESt5K/XotVSZND54=", + "zh:03fcea0a1ea2ca81d62d4d2e2961181bef9068b1c701f2cddc4aa5fac105818a", + "zh:1213944cd623143974ea5c9b70b22ae1ccca33d743924c149ed089d34b8e08b4", + "zh:190a46da0c69082b74da48238ce134d2fc9893e09122ac249c5689f88eab7e13", + "zh:1b312a4b53fa3cf731f95e674c033865feea5455f163b86136f2614424637293", + "zh:2b319814806222c5aba196b1a78756a6b36dc5c91f85edda349234d8a2f20a6a", + "zh:2bddf92c8efc6ad445a2eb8a0e5f88742a0596392c3a4ebc350ebb4105a4a96d", + "zh:3bef0c4f675c09034ff017cf899977b1765b2c0b3d1e489bcb06a5fcac316e2d", + "zh:47c46b5aa22199638fed5c93b195bbfd1182a1408edad4e5c39d4a73a04493f6", + "zh:5f808699650f6db961964466c77f5a581eab142a91c2e54810bb09b6f2fcd3f2", "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", - "zh:b84c87c58a320adbb2c74a4cad03ae5aac7f2eae21db26f00fdde98c8c4d4523", - "zh:c895f1d5cbcbeff77850ac99efd36bde0048d4e909b296882331b9b9ebf48cfa", - "zh:ead82831683619124597a1f170dd31e9b293e9cf22f558cb166d5e734fcd11e4", + "zh:ada97e6be10164f452e278c23412b8597698a9c95ffb68fe83629d63d85906f3", + "zh:c4d73a91810d8dbcf9abbd431d41fcceebb48f8b6fd3c28a84bb3c6ed08be2e9", + "zh:c63ec875d38fc557b16b0b2b0ab1c7635852799453113240e21a52409de94a71", + "zh:cdd0209a755fc3aa14855aa013dae4b166a2fc7f6d3cbb673f7ff2142f5b63a2", + "zh:e5e665a27290391fd1bffc093ab68b596f6c507785be2e3f0949fab4fd6aec1b", + "zh:f6c42046a31d65eff2793737656b38931f90318b53661046bb84326cd4cb558f", + ] +} + +provider "registry.terraform.io/hashicorp/time" { + version = "0.14.0" + constraints = ">= 0.13.0" + hashes = [ + "h1:+nUGGWxp4gQCusc6Sa+FLSQfHUPWh7YaQV6qrWV9exo=", + "h1:/hlxsUpuN/lvPTNL9+NyVGsOyRsK5NsxwFMsj5CdOp4=", + "h1:4EThC3ocCFiFPMZQSUvSGSxoJqBcGWxMcFYmL67uS7Y=", + "h1:Gra0WVbFgIWSbXrZNd+E4zlXsMooCSKeUTrkxqT7//c=", + "h1:dk9Ywmokq1TYodG7B7QVespzwwJeUOBujLaSKgd7M4k=", + "zh:12abfd6b800e4d7fa6db7310dec8ffd440b31993861ef188c7ed5260b3073937", + "zh:23005521e800bb19e1597bf755c5f70d675d30b685d4255001ed5fa47d9df3f1", + "zh:2fea249b582ae97cd1cc10385187ea50993bb47c28cc5df0305e57ceaabf0a10", + "zh:322018d3b987b7aad08697178029a2bb667bed699e88328f0c89c52a2fd41341", + "zh:32a08e98fce2d273cb9b2c89d6c54727cc9f0a32e15bfd896be4e02cc6b48f95", + "zh:3db89aabd0e619616bd4b0f8b373a7586dfe60feffcea12a84a0bdbc445714b3", + "zh:7488f56c81d742dc020f29063626c8f07ca188aa97be61e7307e8d62397020a2", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7cb4067f2e7559b13f7562ef722f948950901eb37834873e98360ab28f66e9d7", + "zh:9d552c8345f61e1b7db8e725144981345f18ac1014d58d6f5ddf0928a195fffb", + "zh:a8e69fb6b97fc9d86fb19a9f4d42abe33c4a68e700b15387ce2e17d2b9934bed", + "zh:aeeb900eb8dd0f790c60ea5c0e0c8d42bd6e4a54f391681d4decca15b544394b", + "zh:c239c619101a8c95e1f14061eb973c57a8d15fa0e68878ced5bbd76858ee5b79", ] } diff --git a/infrastructure/modules/ecs-cluster-2/README.md b/infrastructure/modules/ecs-cluster/README.md similarity index 60% rename from infrastructure/modules/ecs-cluster-2/README.md rename to infrastructure/modules/ecs-cluster/README.md index 4028c58e..8022fdea 100644 --- a/infrastructure/modules/ecs-cluster-2/README.md +++ b/infrastructure/modules/ecs-cluster/README.md @@ -1,34 +1,96 @@ # ECS Cluster -NHS Screening wrapper around the community [`terraform-aws-modules/ecs/aws//modules/cluster`][1] submodule, that consumes the shared `context.tf` for naming and tagging. +NHS Screening wrapper around the community +[`terraform-aws-modules/ecs/aws//modules/cluster`](https://registry.terraform.io/modules/terraform-aws-modules/ecs/aws/latest/submodules/cluster) +module that enforces the platform's baseline controls. -[1]: https://registry.terraform.io/modules/terraform-aws-modules/ecs/aws/latest/submodules/cluster +## What this module enforces -## Differences between this module and the ecs-cluster module - -This module creates more stuff, whereas ecs-cluster exposes the security group id. +|Control|How it is enforced| +|---|---| +|Creation gate|`create = module.this.enabled`| +|Naming and tagging|`name` derives from context, `tags = module.this.tags`| +|Logging|ECS Exec logs are configured to use CloudWatch with explicit retention| +|Encryption at rest|Optional KMS encryption for CloudWatch Log Group and ECS Exec sessions| +|No public access by default|Module does not create security groups or ingress rules| +|Operational visibility|Container Insights enabled by default| ## Usage -### Minimal ECS cluster +### Minimal + +```hcl +module "ecs_cluster" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/ecs-cluster?ref=" + + context = module.this.context +} +``` + +### Common production-style + +```hcl +module "ecs_cluster" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/ecs-cluster?ref=" + + context = module.this.context + + cluster_capacity_providers = ["FARGATE", "FARGATE_SPOT"] + default_capacity_provider_strategy = { + FARGATE = { + base = 1 + weight = 80 + } + FARGATE_SPOT = { + weight = 20 + } + } + + cloudwatch_log_group_retention_in_days = 365 + cloudwatch_log_group_kms_key_id = module.kms.key_arn + execute_command_kms_key_id = module.kms.key_arn +} +``` + +### Advanced or edge case ```hcl -module "ecs-cluster" { - source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/ecs-cluster-2?ref=main" +module "ecs_cluster" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/ecs-cluster?ref=" + + context = module.this.context + + enable_container_insights = false + enable_execute_command = false - service = "bcss" - project = "platform" - environment = "prod" - name = "ecs-cluster" + service_connect_defaults = { + namespace = aws_service_discovery_http_namespace.shared.arn + } } ``` +## Conventions + +- Name precedence is `cluster_name` first, then context-derived `module.this.id`. +- Caller-provided tags are not accepted directly; all tags are sourced from `module.this.tags`. +- This module focuses on ECS cluster-level configuration and does not manage service/task definitions. + +## What this module does NOT do + +- Create ECS services, task definitions, or autoscaling policies. +- Create security groups, infrastructure IAM roles, or managed instance profiles. +- Validate application-level network policy for tasks/services. + ## Requirements -No requirements. +| Name | Version | +| ---- | ------- | +| [terraform](#requirement\_terraform) | >= 1.5.7 | +| [aws](#requirement\_aws) | >= 6.34 | +| [time](#requirement\_time) | >= 0.13 | ## Providers @@ -38,8 +100,8 @@ No providers. | Name | Source | Version | | ---- | ------ | ------- | -| [ecs\_cluster](#module\_ecs\_cluster) | terraform-aws-modules/ecs/aws//modules/cluster | ~> 7.5.0 | -| [this](#module\_this) | git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/tags | n/a | +| [ecs\_cluster](#module\_ecs\_cluster) | terraform-aws-modules/ecs/aws//modules/cluster | 7.5.0 | +| [this](#module\_this) | ../tags | n/a | ## Resources @@ -53,13 +115,23 @@ No resources. | [application\_role](#input\_application\_role) | The role the application is performing | `string` | `"General"` | no | | [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no | | [aws\_region](#input\_aws\_region) | The AWS region | `string` | `"eu-west-2"` | no | +| [cloudwatch\_log\_group\_class](#input\_cloudwatch\_log\_group\_class) | Optional CloudWatch Log Group class. Valid values are STANDARD or INFREQUENT\_ACCESS. | `string` | `null` | no | +| [cloudwatch\_log\_group\_kms\_key\_id](#input\_cloudwatch\_log\_group\_kms\_key\_id) | Optional KMS key ARN used to encrypt the CloudWatch Log Group. | `string` | `null` | no | +| [cloudwatch\_log\_group\_name](#input\_cloudwatch\_log\_group\_name) | Optional CloudWatch Log Group name for ECS Exec logs. Defaults to /aws/ecs//execute-command. | `string` | `null` | no | +| [cloudwatch\_log\_group\_retention\_in\_days](#input\_cloudwatch\_log\_group\_retention\_in\_days) | CloudWatch Log Group retention period in days for ECS Exec logs. | `number` | `90` | no | +| [cluster\_capacity\_providers](#input\_cluster\_capacity\_providers) | Capacity provider names to associate with the ECS cluster. | `list(string)` |
[
"FARGATE"
]
| no | +| [cluster\_name](#input\_cluster\_name) | Optional ECS cluster name. When null, this module uses module.this.id. | `string` | `null` | no | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"project": null,
"regex_replace_chars": null,
"region": null,
"service": null,
"stack": null,
"tags": {},
"terraform_source": null,
"workspace": null
}
| no | | [data\_classification](#input\_data\_classification) | Used to identify the data classification of the resource, e.g 1-5 | `string` | `"n/a"` | no | | [data\_type](#input\_data\_type) | The tag data\_type | `string` | `"None"` | no | +| [default\_capacity\_provider\_strategy](#input\_default\_capacity\_provider\_strategy) | Default capacity provider strategy definitions keyed by provider name. |
map(object({
base = optional(number)
weight = optional(number)
}))
|
{
"FARGATE": {
"weight": 100
}
}
| no | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | | [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no | +| [enable\_container\_insights](#input\_enable\_container\_insights) | Whether to enable CloudWatch Container Insights at cluster level. | `bool` | `true` | no | +| [enable\_execute\_command](#input\_enable\_execute\_command) | Whether to enable ECS Exec configuration at cluster level. | `bool` | `true` | no | | [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | [environment](#input\_environment) | ID element. Usually used to indicate role, e.g. 'prd', 'dev', 'test', 'preprod', 'prod', 'uat' | `string` | `null` | no | +| [execute\_command\_kms\_key\_id](#input\_execute\_command\_kms\_key\_id) | Optional KMS key ARN or ID for ECS Exec session data encryption. | `string` | `null` | no | | [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no | | [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no | | [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no | @@ -74,6 +146,7 @@ No resources. | [region](#input\_region) | ID element \_(Rarely used, not included by default)\_. Usually an abbreviation of the selected AWS region e.g. 'uw2', 'ew2' or 'gbl' for resources like IAM roles that have no region | `string` | `null` | no | | [service](#input\_service) | ID element. Usually an abbreviation of your service directorate name, e.g. 'bcss' or 'csms', to help ensure generated IDs are globally unique | `string` | `null` | no | | [service\_category](#input\_service\_category) | The tag service\_category | `string` | `"n/a"` | no | +| [service\_connect\_defaults](#input\_service\_connect\_defaults) | Optional default Service Connect namespace configuration. |
object({
namespace = string
})
| `null` | no | | [stack](#input\_stack) | ID element. The name of the stack/component, e.g. `database`, `web`, `waf`, `eks` | `string` | `null` | no | | [tag\_version](#input\_tag\_version) | Used to identify the tagging version in use | `string` | `"1.0"` | no | | [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no | @@ -85,8 +158,12 @@ No resources. | Name | Description | | ---- | ----------- | -| [cluster\_arn](#output\_cluster\_arn) | ARN that identifies the cluster | -| [cluster\_name](#output\_cluster\_name) | Name that identifies the cluster | +| [cloudwatch\_log\_group\_arn](#output\_cloudwatch\_log\_group\_arn) | CloudWatch Log Group ARN used for ECS Exec logs when enabled. | +| [cloudwatch\_log\_group\_name](#output\_cloudwatch\_log\_group\_name) | CloudWatch Log Group name used for ECS Exec logs when enabled. | +| [cluster\_arn](#output\_cluster\_arn) | ARN that identifies the ECS cluster. | +| [cluster\_capacity\_providers](#output\_cluster\_capacity\_providers) | Map of cluster capacity provider attributes. | +| [cluster\_id](#output\_cluster\_id) | ID that identifies the ECS cluster. | +| [cluster\_name](#output\_cluster\_name) | Name that identifies the ECS cluster. | diff --git a/infrastructure/modules/ecs-cluster-2/context.tf b/infrastructure/modules/ecs-cluster/context.tf similarity index 99% rename from infrastructure/modules/ecs-cluster-2/context.tf rename to infrastructure/modules/ecs-cluster/context.tf index e1afea79..e934a84f 100644 --- a/infrastructure/modules/ecs-cluster-2/context.tf +++ b/infrastructure/modules/ecs-cluster/context.tf @@ -1,3 +1,4 @@ +# tflint-ignore-file: terraform_standard_module_structure, terraform_unused_declarations # # ONLY EDIT THIS FILE IN github.com/NHSDigital/screening-terraform-modules-aws/infrastructure/modules/tags # All other instances of this file should be a copy of that one @@ -23,6 +24,7 @@ module "this" { source = "../tags" + enabled = var.enabled service = var.service project = var.project region = var.region diff --git a/infrastructure/modules/ecs-cluster/ecs.tf b/infrastructure/modules/ecs-cluster/ecs.tf deleted file mode 100644 index 184a8834..00000000 --- a/infrastructure/modules/ecs-cluster/ecs.tf +++ /dev/null @@ -1,101 +0,0 @@ -## ecs cluster -resource "aws_ecs_cluster" "ecs_cluster" { - name = "${var.name_prefix}-${var.name}" - - setting { - name = "containerInsights" - value = "enabled" - } - - depends_on = [data.aws_iam_role.ecs] -} - -# ------------------------------------------------------------------------------ -# Security Group for ECS app -# ------------------------------------------------------------------------------ -resource "aws_security_group" "ecs_sg" { - vpc_id = var.vpc_id - name = "${var.name_prefix}-${var.name}" - description = "Security group for ECS app" - revoke_rules_on_delete = true -} - -# ------------------------------------------------------------------------------ -# ECS app Security Group Rules - OUTBOUND -# ------------------------------------------------------------------------------ -resource "aws_security_group_rule" "ecs_all_egress" { - type = "egress" - from_port = 0 - to_port = 0 - protocol = "-1" - description = "Allow outbound traffic from ECS" - security_group_id = aws_security_group.ecs_sg.id - cidr_blocks = ["0.0.0.0/0"] -} - -resource "aws_iam_service_linked_role" "ecs" { - count = var.create_ecs_service_role ? 1 : 0 - aws_service_name = "ecs.amazonaws.com" -} - -# to allow referencing the existing service linked role if not created -data "aws_iam_role" "ecs" { - name = "AWSServiceRoleForECS" - depends_on = [aws_iam_service_linked_role.ecs] -} -# sns topic for cloudwatch alarms -data "aws_sns_topic" "alert" { - name = var.name_prefix -} - -# ############################################################## -# # CloudWatch Alarm for ECS Cluster -# ############################################################## - -resource "aws_cloudwatch_metric_alarm" "task_cpu_utilization_alarm" { - # Intent : "This alarm is used to detect high CPU utilization for tasks in the ECS cluster. Consistent high CPU utilization can indicate that the tasks are under stress and might need more CPU resources or optimization to maintain performance." - # Threshold Justification : "Set the threshold to about 80% of the task's CPU reservation. You can adjust this value based on your acceptable CPU utilization for the tasks. For some workloads, consistently high CPU utilization might be normal, while for others, it might indicate performance issues or the need for more resources." - - alarm_name = "${var.name_prefix}-${var.name}-task-cpu-utilization-alarm" - alarm_description = "This alarm helps you detect high CPU utilization of tasks in your ECS cluster. If task CPU utilization is consistently high, you might need to optimize your tasks or increase their CPU reservation." - actions_enabled = true - alarm_actions = [data.aws_sns_topic.alert.arn] - ok_actions = [data.aws_sns_topic.alert.arn] - insufficient_data_actions = [] - metric_name = "TaskCpuUtilization" - namespace = "ECS/ContainerInsights" - statistic = "Average" - period = 60 - dimensions = { - ClusterName = "${var.name_prefix}-${var.name}" - } - evaluation_periods = 5 - datapoints_to_alarm = 5 - threshold = 80 - comparison_operator = "GreaterThanThreshold" - treat_missing_data = "notBreaching" -} - -resource "aws_cloudwatch_metric_alarm" "task_memory_utilization_alarm" { - # Intent : "This alarm is used to detect high memory utilization for tasks in the ECS cluster. Consistent high memory utilization can indicate that the task is under memory pressure and might need more memory resources or optimization to maintain stability." - # Threshold Justification : "Set the threshold to about 80% of the task's memory reservation. You can adjust this value based on your acceptable memory utilization for the tasks. For some workloads, consistently high memory utilization might be normal, while for others, it might indicate memory pressure or the need for more resources." - - alarm_name = "${var.name_prefix}-${var.name}-task-memory-utilization-alarm" - alarm_description = "This alarm helps you detect high memory utilization of tasks in your ECS cluster. If memory utilization is consistently high, you might need to optimize your tasks or increase the memory reservation." - actions_enabled = true - alarm_actions = [data.aws_sns_topic.alert.arn] - ok_actions = [data.aws_sns_topic.alert.arn] - insufficient_data_actions = [] - metric_name = "TaskMemoryUtilization" - namespace = "ECS/ContainerInsights" - statistic = "Average" - period = 60 - dimensions = { - ClusterName = "${var.name_prefix}-${var.name}" - } - evaluation_periods = 5 - datapoints_to_alarm = 5 - threshold = 80 - comparison_operator = "GreaterThanThreshold" - treat_missing_data = "notBreaching" -} diff --git a/infrastructure/modules/ecs-cluster/locals.tf b/infrastructure/modules/ecs-cluster/locals.tf new file mode 100644 index 00000000..0f413811 --- /dev/null +++ b/infrastructure/modules/ecs-cluster/locals.tf @@ -0,0 +1,24 @@ +locals { + # Derive the cluster name from context when no explicit override is provided. + cluster_name = var.cluster_name != null ? var.cluster_name : module.this.id + + cloudwatch_log_group_name = var.cloudwatch_log_group_name != null ? var.cloudwatch_log_group_name : "/aws/ecs/${local.cluster_name}/execute-command" + + cluster_settings = var.enable_container_insights ? [ + { + name = "containerInsights" + value = "enabled" + } + ] : [] + + cluster_configuration = var.enable_execute_command ? { + execute_command_configuration = { + kms_key_id = var.execute_command_kms_key_id + logging = "OVERRIDE" + log_configuration = { + cloud_watch_encryption_enabled = var.cloudwatch_log_group_kms_key_id != null + cloud_watch_log_group_name = local.cloudwatch_log_group_name + } + } + } : null +} diff --git a/infrastructure/modules/ecs-cluster/main.tf b/infrastructure/modules/ecs-cluster/main.tf index 3f7992a5..752e1c15 100644 --- a/infrastructure/modules/ecs-cluster/main.tf +++ b/infrastructure/modules/ecs-cluster/main.tf @@ -1,2 +1,48 @@ -# Primary entrypoint for module structure consistency. -# Resources are defined in ecs.tf. +################################################################ +# ECS cluster +# +# Thin NHS wrapper around the community ECS cluster module that +# enforces the screening platform's baseline controls: +# +# * Creation is gated by module.this.enabled +# * Naming and tagging are enforced via context.tf +# * CloudWatch Container Insights enabled by default +# * ECS Exec logging uses an explicit CloudWatch Log Group +# +# Naming and tagging are derived from context.tf via module.this. +################################################################ + +module "ecs_cluster" { + source = "terraform-aws-modules/ecs/aws//modules/cluster" + version = "7.5.0" + + create = module.this.enabled + name = local.cluster_name + + setting = local.cluster_settings + + configuration = local.cluster_configuration + + # The CloudWatch Log Group is created only when ECS Exec is enabled. + # Consider moving the CloudWatch Log Group creation to a separate module + # so that it can be created independently of the ECS cluster. + create_cloudwatch_log_group = var.enable_execute_command + cloudwatch_log_group_name = local.cloudwatch_log_group_name + cloudwatch_log_group_kms_key_id = var.cloudwatch_log_group_kms_key_id + cloudwatch_log_group_retention_in_days = var.cloudwatch_log_group_retention_in_days + cloudwatch_log_group_class = var.cloudwatch_log_group_class + + cluster_capacity_providers = var.cluster_capacity_providers + default_capacity_provider_strategy = var.default_capacity_provider_strategy + service_connect_defaults = var.service_connect_defaults + + # Keep the module focused on the cluster itself; callers should + # manage IAM/security group resources separately in dedicated modules. + create_security_group = false + create_infrastructure_iam_role = false + create_node_iam_instance_profile = false + create_task_exec_iam_role = false + create_task_exec_policy = false + + tags = module.this.tags +} diff --git a/infrastructure/modules/ecs-cluster/outputs.tf b/infrastructure/modules/ecs-cluster/outputs.tf index 4dfe82ef..e5f10ea6 100644 --- a/infrastructure/modules/ecs-cluster/outputs.tf +++ b/infrastructure/modules/ecs-cluster/outputs.tf @@ -1,14 +1,29 @@ -output "ecs_cluster_name" { - description = "Name of the ECS cluster" - value = aws_ecs_cluster.ecs_cluster.name +output "cluster_arn" { + description = "ARN that identifies the ECS cluster." + value = module.ecs_cluster.arn } -output "ecs_sg_id" { - description = "Security group ID for the ECS cluster" - value = aws_security_group.ecs_sg.id +output "cluster_id" { + description = "ID that identifies the ECS cluster." + value = module.ecs_cluster.id } -output "ecs_cluster_arn" { - description = "ARN of the ECS cluster" - value = aws_ecs_cluster.ecs_cluster.arn +output "cluster_name" { + description = "Name that identifies the ECS cluster." + value = module.ecs_cluster.name +} + +output "cluster_capacity_providers" { + description = "Map of cluster capacity provider attributes." + value = module.ecs_cluster.cluster_capacity_providers +} + +output "cloudwatch_log_group_name" { + description = "CloudWatch Log Group name used for ECS Exec logs when enabled." + value = module.ecs_cluster.cloudwatch_log_group_name +} + +output "cloudwatch_log_group_arn" { + description = "CloudWatch Log Group ARN used for ECS Exec logs when enabled." + value = module.ecs_cluster.cloudwatch_log_group_arn } diff --git a/infrastructure/modules/ecs-cluster/readme.md b/infrastructure/modules/ecs-cluster/readme.md deleted file mode 100644 index fd1866d2..00000000 --- a/infrastructure/modules/ecs-cluster/readme.md +++ /dev/null @@ -1,57 +0,0 @@ -# ECS-Cluster - - - - -## Requirements - -| Name | Version | -| ---- | ------- | -| [terraform](#requirement\_terraform) | >= 1.5.7 | -| [aws](#requirement\_aws) | >= 6.49.0 | - -## Providers - -| Name | Version | -| ---- | ------- | -| [aws](#provider\_aws) | 6.50.0 | - -## Modules - -No modules. - -## Resources - -| Name | Type | -| ---- | ---- | -| [aws_cloudwatch_metric_alarm.task_cpu_utilization_alarm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource | -| [aws_cloudwatch_metric_alarm.task_memory_utilization_alarm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource | -| [aws_ecs_cluster.ecs_cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster) | resource | -| [aws_iam_service_linked_role.ecs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_service_linked_role) | resource | -| [aws_security_group.ecs_sg](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource | -| [aws_security_group_rule.ecs_all_egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource | -| [aws_iam_role.ecs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_role) | data source | -| [aws_sns_topic.alert](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/sns_topic) | data source | - -## Inputs - -| Name | Description | Type | Default | Required | -| ---- | ----------- | ---- | ------- | :------: | -| [aws\_account\_id](#input\_aws\_account\_id) | The AWS account ID | `string` | n/a | yes | -| [container\_port](#input\_container\_port) | Container port for ECS workloads | `number` | `4000` | no | -| [create\_ecs\_service\_role](#input\_create\_ecs\_service\_role) | The service role can only be created once per account, only enable it in one stack | `bool` | `true` | no | -| [environment](#input\_environment) | The name of the Environment this is deployed into, for example CICD, NFT, UAT or PROD | `string` | n/a | yes | -| [name](#input\_name) | the unique name of the resource | `string` | `"ecs"` | no | -| [name\_prefix](#input\_name\_prefix) | The account, environment etc | `string` | n/a | yes | -| [vpc\_id](#input\_vpc\_id) | id of the vpc | `string` | n/a | yes | - -## Outputs - -| Name | Description | -| ---- | ----------- | -| [ecs\_cluster\_arn](#output\_ecs\_cluster\_arn) | ARN of the ECS cluster | -| [ecs\_cluster\_name](#output\_ecs\_cluster\_name) | Name of the ECS cluster | -| [ecs\_sg\_id](#output\_ecs\_sg\_id) | Security group ID for the ECS cluster | - - - diff --git a/infrastructure/modules/ecs-cluster/variables.tf b/infrastructure/modules/ecs-cluster/variables.tf index 45baeaea..9673c3c3 100644 --- a/infrastructure/modules/ecs-cluster/variables.tf +++ b/infrastructure/modules/ecs-cluster/variables.tf @@ -1,42 +1,96 @@ -variable "name_prefix" { - description = "The account, environment etc" +################################################################ +# ECS cluster-specific inputs. +# +# Naming, tagging and the master `enabled` switch come from +# context.tf via `module.this`. +################################################################ + +variable "cluster_name" { + description = "Optional ECS cluster name. When null, this module uses module.this.id." type = string + default = null + + validation { + condition = var.cluster_name == null ? true : can(regex("^[A-Za-z0-9_-]{1,255}$", var.cluster_name)) + error_message = "cluster_name must be 1-255 characters and contain only letters, numbers, underscores, and hyphens." + } +} + +variable "enable_container_insights" { + description = "Whether to enable CloudWatch Container Insights at cluster level." + type = bool + default = true } -# tflint-ignore: terraform_unused_declarations -variable "aws_account_id" { - sensitive = true - description = "The AWS account ID" +variable "enable_execute_command" { + description = "Whether to enable ECS Exec configuration at cluster level." + type = bool + default = true +} + +variable "execute_command_kms_key_id" { + description = "Optional KMS key ARN or ID for ECS Exec session data encryption." type = string + default = null } -variable "name" { - default = "ecs" - description = "the unique name of the resource" +variable "cloudwatch_log_group_name" { + description = "Optional CloudWatch Log Group name for ECS Exec logs. Defaults to /aws/ecs//execute-command." type = string + default = null } -# tflint-ignore: terraform_unused_declarations -variable "container_port" { - description = "Container port for ECS workloads" - type = number - default = 4000 +variable "cloudwatch_log_group_kms_key_id" { + description = "Optional KMS key ARN used to encrypt the CloudWatch Log Group." + type = string + default = null } +variable "cloudwatch_log_group_retention_in_days" { + description = "CloudWatch Log Group retention period in days for ECS Exec logs." + type = number + default = 90 -variable "vpc_id" { - description = "id of the vpc" - type = string + validation { + condition = contains([1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1096, 1827, 2192, 2557, 2922, 3288, 3653], var.cloudwatch_log_group_retention_in_days) + error_message = "cloudwatch_log_group_retention_in_days must be a valid CloudWatch retention value." + } } -# tflint-ignore: terraform_unused_declarations -variable "environment" { - description = "The name of the Environment this is deployed into, for example CICD, NFT, UAT or PROD" +variable "cloudwatch_log_group_class" { + description = "Optional CloudWatch Log Group class. Valid values are STANDARD or INFREQUENT_ACCESS." type = string + default = null + + validation { + condition = var.cloudwatch_log_group_class == null ? true : contains(["STANDARD", "INFREQUENT_ACCESS"], var.cloudwatch_log_group_class) + error_message = "cloudwatch_log_group_class must be STANDARD, INFREQUENT_ACCESS, or null." + } } -variable "create_ecs_service_role" { - description = "The service role can only be created once per account, only enable it in one stack" - type = bool - default = true +variable "cluster_capacity_providers" { + description = "Capacity provider names to associate with the ECS cluster." + type = list(string) + default = ["FARGATE"] +} + +variable "default_capacity_provider_strategy" { + description = "Default capacity provider strategy definitions keyed by provider name." + type = map(object({ + base = optional(number) + weight = optional(number) + })) + default = { + FARGATE = { + weight = 100 + } + } +} + +variable "service_connect_defaults" { + description = "Optional default Service Connect namespace configuration." + type = object({ + namespace = string + }) + default = null } diff --git a/infrastructure/modules/ecs-cluster/versions.tf b/infrastructure/modules/ecs-cluster/versions.tf index 858a8355..44593774 100644 --- a/infrastructure/modules/ecs-cluster/versions.tf +++ b/infrastructure/modules/ecs-cluster/versions.tf @@ -4,7 +4,11 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 6.49.0" + version = ">= 6.34" + } + time = { + source = "hashicorp/time" + version = ">= 0.13" } } } From 87bcbc492563f2dd010766c66b2da100d0721a2b Mon Sep 17 00:00:00 2001 From: Oliver Slater Date: Tue, 23 Jun 2026 02:19:44 +0100 Subject: [PATCH 13/13] feat(gitleaks): enhance gitleaks configuration for IPv4 and IPv6 rules --- .gitleaksignore | 4 ++++ scripts/config/gitleaks.toml | 27 +++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.gitleaksignore b/.gitleaksignore index f97f5c8a..bf9d628a 100644 --- a/.gitleaksignore +++ b/.gitleaksignore @@ -5,3 +5,7 @@ e876843351a025eb754ec61982c8b7d95deeb709:.pre-commit-config.yaml:ipv4:119 e364bc1869c67729653c7efb4d6169f2294e68de:.pre-commit-config.yaml:ipv4:110 62088509f98ce02ce379adef2168b867eecfb5da:.pre-commit-config.yaml:ipv4:110 a3fa25da4e8f9eaa2e28c29f6196f23bfe87a58d:.pre-commit-config.yaml:ipv4:119 +# Historical false positive: example ARN comment in tags/main.tf contained hex-like content +# which triggered the ipv6 rule. Comment updated in later commit; old commits suppressed here. +7b49758d98757e8f404cb2c540c1f146afd6e395:infrastructure/modules/tags/main.tf:ipv6:131 +091dcd76884ffd307aee6c6b306b015c065f4896:infrastructure/modules/tags/main.tf:ipv6:131 diff --git a/scripts/config/gitleaks.toml b/scripts/config/gitleaks.toml index af5f0bb7..8371dcbc 100644 --- a/scripts/config/gitleaks.toml +++ b/scripts/config/gitleaks.toml @@ -11,8 +11,31 @@ regex = '''[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}''' [rules.allowlist] regexTarget = "match" regexes = [ - # Exclude the private network IPv4 addresses as well as the DNS servers for Google and OpenDNS - '''(127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|172\.(1[6-9]|2[0-9]|3[0-1])\.[0-9]{1,3}\.[0-9]{1,3}|192\.168\.[0-9]{1,3}\.[0-9]{1,3}|0\.0\.0\.0|255\.255\.255\.255|8\.8\.8\.8|8\.8\.4\.4|208\.67\.222\.222|208\.67\.220\.220)''', + # Exclude private/reserved IPv4 addresses and well-known DNS servers used in docs/examples. + # Includes RFC5737 TEST-NET ranges: 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 + '''(127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|172\.(1[6-9]|2[0-9]|3[0-1])\.[0-9]{1,3}\.[0-9]{1,3}|192\.168\.[0-9]{1,3}\.[0-9]{1,3}|192\.0\.2\.[0-9]{1,3}|198\.51\.100\.[0-9]{1,3}|203\.0\.113\.[0-9]{1,3}|0\.0\.0\.0|255\.255\.255\.255|8\.8\.8\.8|8\.8\.4\.4|1\.1\.1\.1|1\.0\.0\.1)''', +] + +[[rules]] +description = "IPv6" +id = "ipv6" +# Matches valid IPv6 forms requiring at least 2 groups on each side of :: to +# avoid false positives from AWS ARNs (which use :: between region and account). +# full: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 +# compressed: 2001:db8::1, fe80:db8::1 +# trailing :: fe80:db8:: (2+ groups required before ::) +# leading :: ::db8:1 (2+ groups required after ::) +# Note: RE2 does not support lookahead/lookbehind so boundary enforcement is +# achieved structurally via minimum repetition counts. +regex = '''(?i)(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|(?:[0-9a-f]{1,4}:){2,7}:|(?:[0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}|(?:[0-9a-f]{1,4}:){1,5}(?::[0-9a-f]{1,4}){1,2}|(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,3}|(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,4}|(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,5}|[0-9a-f]{1,4}:(?::[0-9a-f]{1,4}){1,6}|:(?::[0-9a-f]{1,4}){2,7}''' + +[rules.allowlist] +regexTarget = "match" +regexes = [ + # Exclude IPv6 documentation prefixes used in examples. + # RFC3849: 2001:db8::/32 + # RFC9637: 3fff::/20 (3fff:0000:: to 3fff:0fff::) + '''(?i)(^|[^0-9a-f])(2001:db8:|3fff:0[0-9a-f]{0,3}:)''', ] [allowlist]