From 6efc52bbc3b3893e0a60b42bcf2bbcbdf23d0588 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 10 Jun 2026 14:25:00 +0100 Subject: [PATCH 01/13] fix .tool-versions --- .tool-versions | 2 -- 1 file changed, 2 deletions(-) diff --git a/.tool-versions b/.tool-versions index f7161f0..3cf3785 100644 --- a/.tool-versions +++ b/.tool-versions @@ -8,7 +8,6 @@ vale 3.6.0 gitleaks 8.30.1 nodejs 24.16.0 - # ============================================================================== # The section below is reserved for Docker image versions. @@ -25,4 +24,3 @@ nodejs 24.16.0 # docker/koalaman/shellcheck latest@sha256:e40388688bae0fcffdddb7e4dea49b900c18933b452add0930654b2dea3e7d5c # SEE: https://hub.docker.com/r/koalaman/shellcheck/tags # docker/mstruebing/editorconfig-checker 2.7.1@sha256:dd3ca9ea50ef4518efe9be018d669ef9cf937f6bb5cfe2ef84ff2a620b5ddc24 # SEE: https://hub.docker.com/r/mstruebing/editorconfig-checker/tags # docker/sonarsource/sonar-scanner-cli 5.0.1@sha256:494ecc3b5b1ee1625bd377b3905c4284e4f0cc155cff397805a244dee1c7d575 # SEE: https://hub.docker.com/r/sonarsource/sonar-scanner-cli/tags - From 67b6f0fe6b9b6149e485a628bdda0098cfa88190 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 10 Jun 2026 14:25:54 +0100 Subject: [PATCH 02/13] add context --- infrastructure/modules/ec2/context.tf | 374 ++++++++++++++++++++++++++ 1 file changed, 374 insertions(+) create mode 100644 infrastructure/modules/ec2/context.tf diff --git a/infrastructure/modules/ec2/context.tf b/infrastructure/modules/ec2/context.tf new file mode 100644 index 0000000..e1afea7 --- /dev/null +++ b/infrastructure/modules/ec2/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 = "../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 4fb4cd417e54eb6d2d75a079b0f3ce262fe0e823 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 10 Jun 2026 14:27:21 +0100 Subject: [PATCH 03/13] add placeholder files --- infrastructure/modules/ec2/README.md | 1 + infrastructure/modules/ec2/main.tf | 1 + infrastructure/modules/ec2/outputs.tf | 1 + infrastructure/modules/ec2/variables.tf | 1 + 4 files changed, 4 insertions(+) create mode 100644 infrastructure/modules/ec2/README.md create mode 100644 infrastructure/modules/ec2/main.tf create mode 100644 infrastructure/modules/ec2/outputs.tf create mode 100644 infrastructure/modules/ec2/variables.tf diff --git a/infrastructure/modules/ec2/README.md b/infrastructure/modules/ec2/README.md new file mode 100644 index 0000000..c9fb524 --- /dev/null +++ b/infrastructure/modules/ec2/README.md @@ -0,0 +1 @@ +# DAVEH diff --git a/infrastructure/modules/ec2/main.tf b/infrastructure/modules/ec2/main.tf new file mode 100644 index 0000000..c9fb524 --- /dev/null +++ b/infrastructure/modules/ec2/main.tf @@ -0,0 +1 @@ +# DAVEH diff --git a/infrastructure/modules/ec2/outputs.tf b/infrastructure/modules/ec2/outputs.tf new file mode 100644 index 0000000..c9fb524 --- /dev/null +++ b/infrastructure/modules/ec2/outputs.tf @@ -0,0 +1 @@ +# DAVEH diff --git a/infrastructure/modules/ec2/variables.tf b/infrastructure/modules/ec2/variables.tf new file mode 100644 index 0000000..c9fb524 --- /dev/null +++ b/infrastructure/modules/ec2/variables.tf @@ -0,0 +1 @@ +# DAVEH From 2264133998cf74e4ee812ad4d355d4421d8efc8a Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 10 Jun 2026 14:34:00 +0100 Subject: [PATCH 04/13] module bare bones --- infrastructure/modules/ec2/main.tf | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/infrastructure/modules/ec2/main.tf b/infrastructure/modules/ec2/main.tf index c9fb524..c9de3bb 100644 --- a/infrastructure/modules/ec2/main.tf +++ b/infrastructure/modules/ec2/main.tf @@ -1 +1,10 @@ -# DAVEH +module "ec2_instance" { + source = "terraform-aws-modules/ec2-instance/aws" + version = "6.4.0" + + create = module.this.enabled + name = module.this.id + tags = module.this.tags + + # DAVEH +} From 4a276f34c647d30344cfc397cd51dfcfdc00ca38 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 10 Jun 2026 15:36:36 +0100 Subject: [PATCH 05/13] rename module ec2 -> ec2-instance --- infrastructure/modules/{ec2 => ec2-instance}/README.md | 0 infrastructure/modules/{ec2 => ec2-instance}/context.tf | 0 infrastructure/modules/{ec2 => ec2-instance}/main.tf | 0 infrastructure/modules/{ec2 => ec2-instance}/outputs.tf | 0 infrastructure/modules/{ec2 => ec2-instance}/variables.tf | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename infrastructure/modules/{ec2 => ec2-instance}/README.md (100%) rename infrastructure/modules/{ec2 => ec2-instance}/context.tf (100%) rename infrastructure/modules/{ec2 => ec2-instance}/main.tf (100%) rename infrastructure/modules/{ec2 => ec2-instance}/outputs.tf (100%) rename infrastructure/modules/{ec2 => ec2-instance}/variables.tf (100%) diff --git a/infrastructure/modules/ec2/README.md b/infrastructure/modules/ec2-instance/README.md similarity index 100% rename from infrastructure/modules/ec2/README.md rename to infrastructure/modules/ec2-instance/README.md diff --git a/infrastructure/modules/ec2/context.tf b/infrastructure/modules/ec2-instance/context.tf similarity index 100% rename from infrastructure/modules/ec2/context.tf rename to infrastructure/modules/ec2-instance/context.tf diff --git a/infrastructure/modules/ec2/main.tf b/infrastructure/modules/ec2-instance/main.tf similarity index 100% rename from infrastructure/modules/ec2/main.tf rename to infrastructure/modules/ec2-instance/main.tf diff --git a/infrastructure/modules/ec2/outputs.tf b/infrastructure/modules/ec2-instance/outputs.tf similarity index 100% rename from infrastructure/modules/ec2/outputs.tf rename to infrastructure/modules/ec2-instance/outputs.tf diff --git a/infrastructure/modules/ec2/variables.tf b/infrastructure/modules/ec2-instance/variables.tf similarity index 100% rename from infrastructure/modules/ec2/variables.tf rename to infrastructure/modules/ec2-instance/variables.tf From 9a9fe9473eb1d63c73baa419af1dcd9c01f61a1a Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 10 Jun 2026 15:41:53 +0100 Subject: [PATCH 06/13] note underlying ec2_instance fields we currently set --- infrastructure/modules/ec2-instance/main.tf | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/infrastructure/modules/ec2-instance/main.tf b/infrastructure/modules/ec2-instance/main.tf index c9de3bb..b22fd73 100644 --- a/infrastructure/modules/ec2-instance/main.tf +++ b/infrastructure/modules/ec2-instance/main.tf @@ -6,5 +6,38 @@ module "ec2_instance" { name = module.this.id tags = module.this.tags + ami = DAVEH + instance_type = DAVEH + key_name = DAVEH + disable_api_termination = DAVEH + ebs_optimized = DAVEH + monitoring = true + subnet_id = DAVEH + + vpc_security_group_ids = DAVEH + + iam_instance_profile = DAVEH + + # root_block_device { + # encrypted = true + # kms_key_id = data.terraform_remote_state.shared_resources.outputs.oracle_ebs_snapshot_kms_key_arn + # volume_size = var.oracle19_root_volume_size + # volume_type = "gp3" + # } + + # metadata_options { + # http_tokens = "required" + # http_endpoint = "enabled" + # http_put_response_hop_limit = 1 + # instance_metadata_tags = "disabled" + # } + + user_data = DAVEH + user_data_replace_on_change = false + + # lifecycle { + # ignore_changes = [user_data] + # } + # DAVEH } From 9fc14289ac1ff367e745254f348d00054ac6e58e Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 10 Jun 2026 16:36:20 +0100 Subject: [PATCH 07/13] add some variables --- infrastructure/modules/ec2-instance/main.tf | 12 +++--- .../modules/ec2-instance/variables.tf | 43 ++++++++++++++++++- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/infrastructure/modules/ec2-instance/main.tf b/infrastructure/modules/ec2-instance/main.tf index b22fd73..08bb4cd 100644 --- a/infrastructure/modules/ec2-instance/main.tf +++ b/infrastructure/modules/ec2-instance/main.tf @@ -6,13 +6,13 @@ module "ec2_instance" { name = module.this.id tags = module.this.tags - ami = DAVEH - instance_type = DAVEH - key_name = DAVEH - disable_api_termination = DAVEH - ebs_optimized = DAVEH + ami = var.ami + instance_type = var.instance_type + key_name = var.key_name + disable_api_termination = var.disable_api_termination + ebs_optimized = var.ebs_optimized monitoring = true - subnet_id = DAVEH + subnet_id = var.subnet_id vpc_security_group_ids = DAVEH diff --git a/infrastructure/modules/ec2-instance/variables.tf b/infrastructure/modules/ec2-instance/variables.tf index c9fb524..b91d2f6 100644 --- a/infrastructure/modules/ec2-instance/variables.tf +++ b/infrastructure/modules/ec2-instance/variables.tf @@ -1 +1,42 @@ -# DAVEH +################################################################ +# EC2 instance-specific inputs. +# +# Naming, tagging and the master `enabled` switch come from +# context.tf via `module.this`. +################################################################ + +variable "ami" { + description = "ID of AMI to use for the instance" + type = string + default = null +} + +variable "instance_type" { + description = "The type of instance to start" + type = string + default = "t3.micro" +} + +variable "key_name" { + description = "Name of the Key Pair to use for the instance; which can be managed using the `aws_key_pair` resource" + type = string + default = null +} + +variable "disable_api_termination" { + description = "If true, enables EC2 Instance Termination Protection" + type = bool + default = null +} + +variable "ebs_optimized" { + description = "If true, the launched EC2 instance will be EBS-optimized" + type = bool + default = null +} + +variable "subnet_id" { + description = "The VPC Subnet ID to launch in" + type = string + default = null +} From c6ca0dfa22a2b9aa983891c8d1345d8597b7d840 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 10 Jun 2026 16:53:12 +0100 Subject: [PATCH 08/13] add more variables --- infrastructure/modules/ec2-instance/main.tf | 6 +++--- .../modules/ec2-instance/variables.tf | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/infrastructure/modules/ec2-instance/main.tf b/infrastructure/modules/ec2-instance/main.tf index 08bb4cd..70220db 100644 --- a/infrastructure/modules/ec2-instance/main.tf +++ b/infrastructure/modules/ec2-instance/main.tf @@ -14,9 +14,9 @@ module "ec2_instance" { monitoring = true subnet_id = var.subnet_id - vpc_security_group_ids = DAVEH + vpc_security_group_ids = var.vpc_security_group_ids - iam_instance_profile = DAVEH + iam_instance_profile = var.iam_instance_profile # root_block_device { # encrypted = true @@ -32,7 +32,7 @@ module "ec2_instance" { # instance_metadata_tags = "disabled" # } - user_data = DAVEH + user_data = var.user_data user_data_replace_on_change = false # lifecycle { diff --git a/infrastructure/modules/ec2-instance/variables.tf b/infrastructure/modules/ec2-instance/variables.tf index b91d2f6..668bbd8 100644 --- a/infrastructure/modules/ec2-instance/variables.tf +++ b/infrastructure/modules/ec2-instance/variables.tf @@ -40,3 +40,21 @@ variable "subnet_id" { type = string default = null } + +variable "vpc_security_group_ids" { + description = "List of VPC Security Group IDs to associate with" + type = list(string) + default = [] +} + +variable "iam_instance_profile" { + description = "IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile" + type = string + default = null +} + +variable "user_data" { + description = "The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument" + type = string + default = null +} From faeb34c2992854622c0f1c099e26707ef109f902 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Thu, 11 Jun 2026 09:00:08 +0100 Subject: [PATCH 09/13] root_block_device --- infrastructure/modules/ec2-instance/main.tf | 7 +------ infrastructure/modules/ec2-instance/variables.tf | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/infrastructure/modules/ec2-instance/main.tf b/infrastructure/modules/ec2-instance/main.tf index 70220db..7d97604 100644 --- a/infrastructure/modules/ec2-instance/main.tf +++ b/infrastructure/modules/ec2-instance/main.tf @@ -18,12 +18,7 @@ module "ec2_instance" { iam_instance_profile = var.iam_instance_profile - # root_block_device { - # encrypted = true - # kms_key_id = data.terraform_remote_state.shared_resources.outputs.oracle_ebs_snapshot_kms_key_arn - # volume_size = var.oracle19_root_volume_size - # volume_type = "gp3" - # } + root_block_device = var.root_block_device # metadata_options { # http_tokens = "required" diff --git a/infrastructure/modules/ec2-instance/variables.tf b/infrastructure/modules/ec2-instance/variables.tf index 668bbd8..d6823e0 100644 --- a/infrastructure/modules/ec2-instance/variables.tf +++ b/infrastructure/modules/ec2-instance/variables.tf @@ -58,3 +58,18 @@ variable "user_data" { type = string default = null } + +variable "root_block_device" { + description = "Customize details about the root block device of the instance" + type = object({ + delete_on_termination = optional(bool) + encrypted = optional(bool) + iops = optional(number) + kms_key_id = optional(string) + tags = optional(map(string)) + throughput = optional(number) + size = optional(number) + type = optional(string) + }) + default = null +} From 3f8aa864f316cc17488059204f2800f1fd8020fb Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Thu, 11 Jun 2026 09:15:34 +0100 Subject: [PATCH 10/13] metadata_options --- infrastructure/modules/ec2-instance/main.tf | 7 +------ infrastructure/modules/ec2-instance/variables.tf | 12 ++++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/infrastructure/modules/ec2-instance/main.tf b/infrastructure/modules/ec2-instance/main.tf index 7d97604..7af70c5 100644 --- a/infrastructure/modules/ec2-instance/main.tf +++ b/infrastructure/modules/ec2-instance/main.tf @@ -20,12 +20,7 @@ module "ec2_instance" { root_block_device = var.root_block_device - # metadata_options { - # http_tokens = "required" - # http_endpoint = "enabled" - # http_put_response_hop_limit = 1 - # instance_metadata_tags = "disabled" - # } + metadata_options = var.metadata_options user_data = var.user_data user_data_replace_on_change = false diff --git a/infrastructure/modules/ec2-instance/variables.tf b/infrastructure/modules/ec2-instance/variables.tf index d6823e0..3e2cfac 100644 --- a/infrastructure/modules/ec2-instance/variables.tf +++ b/infrastructure/modules/ec2-instance/variables.tf @@ -73,3 +73,15 @@ variable "root_block_device" { }) default = null } + +variable "metadata_options" { + description = "Customize the metadata options of the instance" + type = object({ + http_endpoint = optional(string, "enabled") + http_protocol_ipv6 = optional(string) + http_put_response_hop_limit = optional(number, 1) + http_tokens = optional(string, "required") + instance_metadata_tags = optional(string) + }) + default = {} +} From 450e7ac0ec1f6a1f7092e6ddf001b1db1f834569 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Thu, 11 Jun 2026 15:19:48 +0100 Subject: [PATCH 11/13] add outputs used in existing stack --- infrastructure/modules/ec2-instance/outputs.tf | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/infrastructure/modules/ec2-instance/outputs.tf b/infrastructure/modules/ec2-instance/outputs.tf index c9fb524..d9095bf 100644 --- a/infrastructure/modules/ec2-instance/outputs.tf +++ b/infrastructure/modules/ec2-instance/outputs.tf @@ -1 +1,9 @@ -# DAVEH +output "ec2_instance_id" { + description = "The ID of the EC2 instance" + value = module.ec2_instance.id +} + +output "private_ip" { + description = "The private IP address of the EC2 instance" + value = module.ec2_instance.private_ip +} From 15a90166d7deb08a87c6b2ca17f13396cafcaf01 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Fri, 12 Jun 2026 07:58:49 +0100 Subject: [PATCH 12/13] explain blocker --- infrastructure/modules/ec2-instance/main.tf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/infrastructure/modules/ec2-instance/main.tf b/infrastructure/modules/ec2-instance/main.tf index 7af70c5..b364d65 100644 --- a/infrastructure/modules/ec2-instance/main.tf +++ b/infrastructure/modules/ec2-instance/main.tf @@ -25,9 +25,10 @@ module "ec2_instance" { user_data = var.user_data user_data_replace_on_change = false + # DAVEH: can't set lifecycle hooks on module calls, want it set on the + # underlying resource anyway. vague plan is to fork the module, but + # not there yet # lifecycle { # ignore_changes = [user_data] # } - - # DAVEH } From 0dde744de31b452f0e7e3f91ffb2a97a59fd3025 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Fri, 12 Jun 2026 08:09:09 +0100 Subject: [PATCH 13/13] add tags for autogenerated docs --- infrastructure/modules/ec2-instance/README.md | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/infrastructure/modules/ec2-instance/README.md b/infrastructure/modules/ec2-instance/README.md index c9fb524..efc36a3 100644 --- a/infrastructure/modules/ec2-instance/README.md +++ b/infrastructure/modules/ec2-instance/README.md @@ -1 +1,80 @@ # DAVEH + + + + +## Requirements + +No requirements. + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +| ---- | ------ | ------- | +| [ec2\_instance](#module\_ec2\_instance) | terraform-aws-modules/ec2-instance/aws | 6.4.0 | +| [this](#module\_this) | ../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 | +| [ami](#input\_ami) | ID of AMI to use for the instance | `string` | `null` | 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 | +| [disable\_api\_termination](#input\_disable\_api\_termination) | If true, enables EC2 Instance Termination Protection | `bool` | `null` | no | +| [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `null` | 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 | +| [iam\_instance\_profile](#input\_iam\_instance\_profile) | IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile | `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 | +| [instance\_type](#input\_instance\_type) | The type of instance to start | `string` | `"t3.micro"` | no | +| [key\_name](#input\_key\_name) | Name of the Key Pair to use for the instance; which can be managed using the `aws_key_pair` resource | `string` | `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 | +| [metadata\_options](#input\_metadata\_options) | Customize the metadata options of the instance |
object({
http_endpoint = optional(string, "enabled")
http_protocol_ipv6 = optional(string)
http_put_response_hop_limit = optional(number, 1)
http_tokens = optional(string, "required")
instance_metadata_tags = optional(string)
})
| `{}` | 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 | +| [root\_block\_device](#input\_root\_block\_device) | Customize details about the root block device of the instance |
object({
delete_on_termination = optional(bool)
encrypted = optional(bool)
iops = optional(number)
kms_key_id = optional(string)
tags = optional(map(string))
throughput = optional(number)
size = optional(number)
type = optional(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 | +| [subnet\_id](#input\_subnet\_id) | The VPC Subnet ID to launch in | `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 | +| [user\_data](#input\_user\_data) | The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument | `string` | `null` | no | +| [vpc\_security\_group\_ids](#input\_vpc\_security\_group\_ids) | List of VPC Security Group IDs to associate with | `list(string)` | `[]` | no | +| [workspace](#input\_workspace) | ID element. The Terraform workspace, to help ensure generated IDs are unique across workspaces | `string` | `null` | no | + +## Outputs + +| Name | Description | +| ---- | ----------- | +| [ec2\_instance\_id](#output\_ec2\_instance\_id) | The ID of the EC2 instance | +| [private\_ip](#output\_private\_ip) | The private IP address of the EC2 instance | + + +