From 288c496ab12aa0608e2fb8a78174a720b094fe0c Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 17 Jun 2026 10:44:04 +0100 Subject: [PATCH 1/9] feat(iam-policy): add bare bones wrapper (no inputs, not outputs) --- infrastructure/modules/iam-policy/main.tf | 6 ++++++ infrastructure/modules/iam-policy/outputs.tf | 1 + infrastructure/modules/iam-policy/variables.tf | 1 + infrastructure/modules/iam-policy/versions.tf | 10 ++++++++++ 4 files changed, 18 insertions(+) create mode 100644 infrastructure/modules/iam-policy/main.tf create mode 100644 infrastructure/modules/iam-policy/outputs.tf create mode 100644 infrastructure/modules/iam-policy/variables.tf create mode 100644 infrastructure/modules/iam-policy/versions.tf diff --git a/infrastructure/modules/iam-policy/main.tf b/infrastructure/modules/iam-policy/main.tf new file mode 100644 index 00000000..52c7c07b --- /dev/null +++ b/infrastructure/modules/iam-policy/main.tf @@ -0,0 +1,6 @@ +# DAVEH + +module "iam_policy" { + source = "terraform-aws-modules/iam/aws//modules/iam-policy" + version = "6.6.1" +} diff --git a/infrastructure/modules/iam-policy/outputs.tf b/infrastructure/modules/iam-policy/outputs.tf new file mode 100644 index 00000000..c9fb5240 --- /dev/null +++ b/infrastructure/modules/iam-policy/outputs.tf @@ -0,0 +1 @@ +# DAVEH diff --git a/infrastructure/modules/iam-policy/variables.tf b/infrastructure/modules/iam-policy/variables.tf new file mode 100644 index 00000000..c9fb5240 --- /dev/null +++ b/infrastructure/modules/iam-policy/variables.tf @@ -0,0 +1 @@ +# DAVEH diff --git a/infrastructure/modules/iam-policy/versions.tf b/infrastructure/modules/iam-policy/versions.tf new file mode 100644 index 00000000..d2afd5f9 --- /dev/null +++ b/infrastructure/modules/iam-policy/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.5.7" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 6.28" + } + } +} From 864092fa251b96def165d1212767a203d34d66c6 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 17 Jun 2026 11:25:25 +0100 Subject: [PATCH 2/9] feat(iam-policy): add and use context --- infrastructure/modules/iam-policy/context.tf | 377 +++++++++++++++++++ infrastructure/modules/iam-policy/main.tf | 4 + 2 files changed, 381 insertions(+) create mode 100644 infrastructure/modules/iam-policy/context.tf diff --git a/infrastructure/modules/iam-policy/context.tf b/infrastructure/modules/iam-policy/context.tf new file mode 100644 index 00000000..9a4652b0 --- /dev/null +++ b/infrastructure/modules/iam-policy/context.tf @@ -0,0 +1,377 @@ +# 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 +# +# +# 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" { + # tflint-ignore: terraform_module_pinned_source + source = "../tags" + + enabled = var.enabled + 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 diff --git a/infrastructure/modules/iam-policy/main.tf b/infrastructure/modules/iam-policy/main.tf index 52c7c07b..3f7c7c26 100644 --- a/infrastructure/modules/iam-policy/main.tf +++ b/infrastructure/modules/iam-policy/main.tf @@ -3,4 +3,8 @@ module "iam_policy" { source = "terraform-aws-modules/iam/aws//modules/iam-policy" version = "6.6.1" + + create = module.this.enabled + name = module.this.id + tags = module.this.tags } From 8843820e1c5ad25df0881a29edfff731d75de616 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 17 Jun 2026 11:53:11 +0100 Subject: [PATCH 3/9] feat(iam-policy): add input variables --- infrastructure/modules/iam-policy/main.tf | 6 ++++++ infrastructure/modules/iam-policy/variables.tf | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/infrastructure/modules/iam-policy/main.tf b/infrastructure/modules/iam-policy/main.tf index 3f7c7c26..fe11d973 100644 --- a/infrastructure/modules/iam-policy/main.tf +++ b/infrastructure/modules/iam-policy/main.tf @@ -7,4 +7,10 @@ module "iam_policy" { create = module.this.enabled name = module.this.id tags = module.this.tags + + description = var.description + path = var.path + policy = var.policy + + # `name_prefix` conflicts with `name`, hence we omit it } diff --git a/infrastructure/modules/iam-policy/variables.tf b/infrastructure/modules/iam-policy/variables.tf index c9fb5240..513b94c5 100644 --- a/infrastructure/modules/iam-policy/variables.tf +++ b/infrastructure/modules/iam-policy/variables.tf @@ -1 +1,17 @@ -# DAVEH +variable "description" { + description = "The description of the policy" + type = string + default = null +} + +variable "path" { + description = "The path of the policy" + type = string + default = "/" +} + +variable "policy" { + description = "Policy document. This is a JSON formatted string." + type = string + default = null +} From 8553b3ad1143f6098ab5167dd9226cb39968b55c Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 17 Jun 2026 12:04:11 +0100 Subject: [PATCH 4/9] feat(iam-policy): add outputs --- infrastructure/modules/iam-policy/outputs.tf | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/infrastructure/modules/iam-policy/outputs.tf b/infrastructure/modules/iam-policy/outputs.tf index c9fb5240..3e87da23 100644 --- a/infrastructure/modules/iam-policy/outputs.tf +++ b/infrastructure/modules/iam-policy/outputs.tf @@ -1 +1,19 @@ -# DAVEH +output "iam_policy_arn" { + description = "The ARN assigned by AWS to this policy" + value = module.iam_policy.arn +} + +output "iam_policy_id" { + description = "The policy's ID" + value = module.iam_policy.id +} + +output "iam_policy_name" { + description = "The name of the policy" + value = module.iam_policy.name +} + +output "iam_policy" { + description = "The policy document" + value = module.iam_policy.policy +} From 933101c84ed5c017aa815b7e8499411c3b422dd6 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 17 Jun 2026 13:53:13 +0100 Subject: [PATCH 5/9] docs(iam-policy): autogenerated --- infrastructure/modules/iam-policy/README.md | 77 +++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 infrastructure/modules/iam-policy/README.md diff --git a/infrastructure/modules/iam-policy/README.md b/infrastructure/modules/iam-policy/README.md new file mode 100644 index 00000000..9354b31a --- /dev/null +++ b/infrastructure/modules/iam-policy/README.md @@ -0,0 +1,77 @@ +# iam Policy + + + + +## Requirements + +| Name | Version | +| ---- | ------- | +| [terraform](#requirement\_terraform) | >= 1.5.7 | +| [aws](#requirement\_aws) | >= 6.28 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +| ---- | ------ | ------- | +| [iam\_policy](#module\_iam\_policy) | terraform-aws-modules/iam/aws//modules/iam-policy | 6.6.1 | +| [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 | +| [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 | +| [description](#input\_description) | The description of the policy | `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 | +| [path](#input\_path) | The path of the policy | `string` | `"/"` | no | +| [policy](#input\_policy) | Policy document. This is a JSON formatted string. | `string` | `null` | 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 | +| ---- | ----------- | +| [iam\_policy](#output\_iam\_policy) | The policy document | +| [iam\_policy\_arn](#output\_iam\_policy\_arn) | The ARN assigned by AWS to this policy | +| [iam\_policy\_id](#output\_iam\_policy\_id) | The policy's ID | +| [iam\_policy\_name](#output\_iam\_policy\_name) | The name of the policy | + + + From 9bb602aaeec91ea8e8cc5fa98cb742037cb7b43e Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 17 Jun 2026 13:53:59 +0100 Subject: [PATCH 6/9] chore(iam-policy): rm obsolete todo --- infrastructure/modules/iam-policy/main.tf | 2 -- 1 file changed, 2 deletions(-) diff --git a/infrastructure/modules/iam-policy/main.tf b/infrastructure/modules/iam-policy/main.tf index fe11d973..e8b7cdba 100644 --- a/infrastructure/modules/iam-policy/main.tf +++ b/infrastructure/modules/iam-policy/main.tf @@ -1,5 +1,3 @@ -# DAVEH - module "iam_policy" { source = "terraform-aws-modules/iam/aws//modules/iam-policy" version = "6.6.1" From a113422bb1d6967a6822e9bf149bb86db2d4885d Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 17 Jun 2026 14:06:53 +0100 Subject: [PATCH 7/9] docs(iam-policy): add intro --- infrastructure/modules/iam-policy/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/infrastructure/modules/iam-policy/README.md b/infrastructure/modules/iam-policy/README.md index 9354b31a..3cb8770b 100644 --- a/infrastructure/modules/iam-policy/README.md +++ b/infrastructure/modules/iam-policy/README.md @@ -1,5 +1,17 @@ # iam Policy +NHS Screening wrapper around the community +[`terraform-aws-modules/iam/aws//modules/iam-policy`](https://registry.terraform.io/modules/terraform-aws-modules/iam/aws/latest/submodules/iam-policy) +submodule that enforces the platform's baseline controls and consumes +the shared `context.tf` for naming and tagging. + +## What this module enforces + +| Control | How it is enforced | +| ------------------------ | --------------------------------------------------------------------------------- | +| Globally unique name | Default name is `-` | +| Tagging | Via `module.this.tags` | + From 064b3b98264fb8bdd8fad8c06666781c06b9c541 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 17 Jun 2026 14:13:03 +0100 Subject: [PATCH 8/9] docs(iam-policy): add examples --- infrastructure/modules/iam-policy/README.md | 86 +++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/infrastructure/modules/iam-policy/README.md b/infrastructure/modules/iam-policy/README.md index 3cb8770b..8b631cc4 100644 --- a/infrastructure/modules/iam-policy/README.md +++ b/infrastructure/modules/iam-policy/README.md @@ -12,6 +12,92 @@ the shared `context.tf` for naming and tagging. | Globally unique name | Default name is `-` | | Tagging | Via `module.this.tags` | +## Usage + +### Minimal managed policy (inline JSON) + +```hcl +module "read_only_s3_policy" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/iam-policy?ref=main" + + service = "bcss" + project = "ingest" + environment = "development" + name = "s3-readonly" + + description = "Read-only access to a specific S3 bucket" + + policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Sid = "ListBucket" + Effect = "Allow" + Action = ["s3:ListBucket"] + Resource = [ + "arn:aws:s3:::example-data-bucket" + ] + }, + { + Sid = "GetObjects" + Effect = "Allow" + Action = ["s3:GetObject"] + Resource = [ + "arn:aws:s3:::example-data-bucket/*" + ] + } + ] + }) +} +``` + +### Managed policy from `aws_iam_policy_document` + +```hcl +data "aws_iam_policy_document" "assume_read_secrets" { + statement { + sid = "ReadParameterStore" + effect = "Allow" + + actions = [ + "ssm:GetParameter", + "ssm:GetParameters", + "ssm:GetParametersByPath" + ] + + resources = [ + "arn:aws:ssm:eu-west-2:123456789012:parameter/bcss/prod/*" + ] + } + + statement { + sid = "ReadSecretsManager" + effect = "Allow" + + actions = [ + "secretsmanager:GetSecretValue", + "secretsmanager:DescribeSecret" + ] + + resources = [ + "arn:aws:secretsmanager:eu-west-2:123456789012:secret:bcss/prod/*" + ] + } +} + +module "runtime_secrets_read_policy" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/iam-policy?ref=main" + + service = "bcss" + project = "runtime" + environment = "prod" + name = "runtime-secrets-read" + + description = "Read application runtime secrets and parameters" + policy = data.aws_iam_policy_document.assume_read_secrets.json +} +``` + From c35b626bb5b542f783cb44af0a7acc834ac2c0e8 Mon Sep 17 00:00:00 2001 From: Dave Hinton Date: Wed, 17 Jun 2026 16:45:47 +0100 Subject: [PATCH 9/9] fix(iam-policy): add terraform lock file --- .../modules/iam-policy/.terraform.lock.hcl | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 infrastructure/modules/iam-policy/.terraform.lock.hcl diff --git a/infrastructure/modules/iam-policy/.terraform.lock.hcl b/infrastructure/modules/iam-policy/.terraform.lock.hcl new file mode 100644 index 00000000..bcdf2549 --- /dev/null +++ b/infrastructure/modules/iam-policy/.terraform.lock.hcl @@ -0,0 +1,30 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "6.50.0" + constraints = ">= 6.14.0, >= 6.28.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", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:b84c87c58a320adbb2c74a4cad03ae5aac7f2eae21db26f00fdde98c8c4d4523", + "zh:c895f1d5cbcbeff77850ac99efd36bde0048d4e909b296882331b9b9ebf48cfa", + "zh:ead82831683619124597a1f170dd31e9b293e9cf22f558cb166d5e734fcd11e4", + ] +}