Skip to content

Commit c22b48e

Browse files
Merge pull request #43 from NHSDigital/CCM-7890_BackupModuleRefactor
CCM-7890 Backup Module Refactor
2 parents 35bc1ca + bb736e8 commit c22b48e

19 files changed

Lines changed: 91 additions & 34 deletions

infrastructure/modules/aws-backup-source/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ See [terraform-aws-backup](https://github.com/NHSDigital/terraform-aws-backup.gi
77
<!-- vale on -->
88

99
## Inputs
10+
<!-- markdownlint-disable MD051 -->
1011
<!-- vale off -->
1112
| Name | Description | Type | Default | Required |
1213
|------|-------------|------|---------|:--------:|
1314
| <a name="input_backup_copy_vault_account_id"></a> [backup\_copy\_vault\_account\_id](#input\_backup\_copy\_vault\_account\_id) | The account id of the destination backup vault for allowing restores back into the source account. | `string` | `""` | no |
1415
| <a name="input_backup_copy_vault_arn"></a> [backup\_copy\_vault\_arn](#input\_backup\_copy\_vault\_arn) | The ARN of the destination backup vault for cross-account backup copies. | `string` | `""` | no |
15-
| <a name="input_backup_plan_config"></a> [backup\_plan\_config](#input\_backup\_plan\_config) | Configuration for backup plans | <pre>object({<br> selection_tag = string<br> compliance_resource_types = list(string)<br> rules = list(object({<br> name = string<br> schedule = string<br> enable_continuous_backup = optional(bool)<br> lifecycle = object({<br> delete_after = optional(number)<br> cold_storage_after = optional(number)<br> })<br> copy_action = optional(object({<br> delete_after = optional(number)<br> }))<br> }))<br> })</pre> | <pre>{<br> "compliance_resource_types": [<br> "S3"<br> ],<br> "rules": [<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "delete_after": 35<br> },<br> "name": "daily_kept_5_weeks",<br> "schedule": "cron(0 0 * * ? *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "delete_after": 90<br> },<br> "name": "weekly_kept_3_months",<br> "schedule": "cron(0 1 ? * SUN *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "cold_storage_after": 30,<br> "delete_after": 2555<br> },<br> "name": "monthly_kept_7_years",<br> "schedule": "cron(0 2 1 * ? *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "enable_continuous_backup": true,<br> "lifecycle": {<br> "delete_after": 35<br> },<br> "name": "point_in_time_recovery",<br> "schedule": "cron(0 5 * * ? *)"<br> }<br> ],<br> "selection_tag": "BackupLocal"<br>}</pre> | no |
16-
| <a name="input_backup_plan_config_dynamodb"></a> [backup\_plan\_config\_dynamodb](#input\_backup\_plan\_config\_dynamodb) | Configuration for backup plans with dynamodb | <pre>object({<br> enable = bool<br> selection_tag = string<br> compliance_resource_types = list(string)<br> rules = optional(list(object({<br> name = string<br> schedule = string<br> enable_continuous_backup = optional(bool)<br> lifecycle = object({<br> delete_after = number<br> cold_storage_after = optional(number)<br> })<br> copy_action = optional(object({<br> delete_after = optional(number)<br> }))<br> })))<br> })</pre> | <pre>{<br> "compliance_resource_types": [<br> "DynamoDB"<br> ],<br> "enable": true,<br> "rules": [<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "delete_after": 35<br> },<br> "name": "dynamodb_daily_kept_5_weeks",<br> "schedule": "cron(0 0 * * ? *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "delete_after": 90<br> },<br> "name": "dynamodb_weekly_kept_3_months",<br> "schedule": "cron(0 1 ? * SUN *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "cold_storage_after": 30,<br> "delete_after": 2555<br> },<br> "name": "dynamodb_monthly_kept_7_years",<br> "schedule": "cron(0 2 1 * ? *)"<br> }<br> ],<br> "selection_tag": "BackupDynamoDB"<br>}</pre> | no |
16+
| <a name="input_backup_plan_config"></a> [backup\_plan\_config](#input\_backup\_plan\_config) | Configuration for backup plans | <pre>object({<br> selection_tag = string<br> compliance_resource_types = list(string)<br> rules = list(object({<br> name = string<br> schedule = string<br> enable_continuous_backup = optional(bool)<br> lifecycle = object({<br> delete_after = optional(number)<br> cold_storage_after = optional(number)<br> })<br> copy_action = optional(object({<br> delete_after = optional(number)<br> }))<br> }))<br> })</pre> | <pre>{<br> "compliance_resource_types": [<br> "S3"<br> ],<br> "rules": [<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "delete_after": 35<br> },<br> "name": "daily_kept_5_weeks",<br> "schedule": "cron(0 0 ** ? *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "delete_after": 90<br> },<br> "name": "weekly_kept_3_months",<br> "schedule": "cron(0 1 ?* SUN *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "cold_storage_after": 30,<br> "delete_after": 2555<br> },<br> "name": "monthly_kept_7_years",<br> "schedule": "cron(0 2 1* ? *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "enable_continuous_backup": true,<br> "lifecycle": {<br> "delete_after": 35<br> },<br> "name": "point_in_time_recovery",<br> "schedule": "cron(0 5* *?*)"<br> }<br> ],<br> "selection_tag": "BackupLocal"<br>}</pre> | no |
17+
| <a name="input_backup_plan_config_dynamodb"></a> [backup\_plan\_config\_dynamodb](#input\_backup\_plan\_config\_dynamodb) | Configuration for backup plans with dynamodb | <pre>object({<br> enable = bool<br> selection_tag = string<br> compliance_resource_types = list(string)<br> rules = optional(list(object({<br> name = string<br> schedule = string<br> enable_continuous_backup = optional(bool)<br> lifecycle = object({<br> delete_after = number<br> cold_storage_after = optional(number)<br> })<br> copy_action = optional(object({<br> delete_after = optional(number)<br> }))<br> })))<br> })</pre> | <pre>{<br> "compliance_resource_types": [<br> "DynamoDB"<br> ],<br> "enable": true,<br> "rules": [<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "delete_after": 35<br> },<br> "name": "dynamodb_daily_kept_5_weeks",<br> "schedule": "cron(0 0 ** ? *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "delete_after": 90<br> },<br> "name": "dynamodb_weekly_kept_3_months",<br> "schedule": "cron(0 1 ?* SUN *)"<br> },<br> {<br> "copy_action": {<br> "delete_after": 365<br> },<br> "lifecycle": {<br> "cold_storage_after": 30,<br> "delete_after": 2555<br> },<br> "name": "dynamodb_monthly_kept_7_years",<br> "schedule": "cron(0 2 1* ? *)"<br> }<br> ],<br> "selection_tag": "BackupDynamoDB"<br>}</pre> | no |
1718
| <a name="input_notification_kms_key"></a> [bootstrap\_kms\_key\_arn](#input\_bootstrap\_kms\_key\_arn) | The ARN of the bootstrap KMS key used for encryption at rest of the SNS topic. | `string` | n/a | yes |
18-
| <a name="input_environment_name"></a> [environment\_name](#input\_environment\_name) | The name of the environment where AWS Backup is configured. | `string` | n/a | yes |
19+
| <a name="input_environment"></a> [environment\_name](#input\_environment\_name) | The name of the environment where AWS Backup is configured. | `string` | n/a | yes |
1920
| <a name="input_notifications_target_email_address"></a> [notifications\_target\_email\_address](#input\_notifications\_target\_email\_address) | The email address to which backup notifications will be sent via SNS. | `string` | `""` | no |
2021
| <a name="input_project_name"></a> [project\_name](#input\_project\_name) | The name of the project this relates to. | `string` | n/a | yes |
2122
| <a name="input_reports_bucket"></a> [reports\_bucket](#input\_reports\_bucket) | Bucket to drop backup reports into | `string` | n/a | yes |
@@ -26,14 +27,15 @@ See [terraform-aws-backup](https://github.com/NHSDigital/terraform-aws-backup.gi
2627
| <a name="input_restore_testing_plan_start_window"></a> [restore\_testing\_plan\_start\_window](#input\_restore\_testing\_plan\_start\_window) | Start window from the scheduled time during which the test should start | `number` | `1` | no |
2728
| <a name="input_management_ci_role_arn"></a> [terraform\_role\_arn](#input\_terraform\_role\_arn) | ARN of Terraform role used to deploy to account | `string` | n/a | yes |
2829
<!-- vale on -->
30+
<!-- markdownlint-enable MD051 -->
2931

3032
## Example
3133

3234
```terraform
3335
module "test_aws_backup" {
3436
source = "./modules/aws-backup"
3537
36-
environment_name = "environment_name"
38+
environment = "environment"
3739
notification_kms_key = kms_key[0].arn
3840
project_name = "testproject"
3941
reports_bucket = "compliance-reports"

infrastructure/modules/aws-backup-source/backup_framework_dynamodb.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ resource "aws_backup_framework" "dynamodb" {
22
count = var.backup_plan_config_dynamodb.enable ? 1 : 0
33

44
# must be underscores instead of dashes
5-
name = replace("${local.resource_name_prefix}-dynamodb-framework", "-", "_")
6-
description = "${var.project_name} DynamoDB Backup Framework"
5+
name = replace("${local.csi}-dynamodb-framework", "-", "_")
6+
description = "${var.project} DynamoDB Backup Framework"
77

88
# Evaluates if recovery points are encrypted.
99
control {
1010
name = "BACKUP_RECOVERY_POINT_ENCRYPTED"
1111

1212
scope {
1313
tags = {
14-
Environment = var.environment_name
14+
Environment = var.environment
1515
}
1616
}
1717
}
@@ -22,7 +22,7 @@ resource "aws_backup_framework" "dynamodb" {
2222

2323
scope {
2424
tags = {
25-
Environment = var.environment_name
25+
Environment = var.environment
2626
}
2727
}
2828

@@ -38,7 +38,7 @@ resource "aws_backup_framework" "dynamodb" {
3838

3939
scope {
4040
tags = {
41-
Environment = var.environment_name
41+
Environment = var.environment
4242
}
4343
}
4444

@@ -54,7 +54,7 @@ resource "aws_backup_framework" "dynamodb" {
5454

5555
scope {
5656
tags = {
57-
Environment = var.environment_name
57+
Environment = var.environment
5858
}
5959
}
6060

infrastructure/modules/aws-backup-source/backup_framework_s3.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ resource "aws_backup_framework" "s3" {
22
count = var.backup_plan_config_s3.enable ? 1 : 0
33

44
# must be underscores instead of dashes
5-
name = replace("${local.resource_name_prefix}-framework", "-", "_")
6-
description = "${var.project_name} Backup Framework"
5+
name = replace("${local.csi}-framework", "-", "_")
6+
description = "${var.project} Backup Framework"
77

88
# Evaluates if recovery points are encrypted.
99
control {
1010
name = "BACKUP_RECOVERY_POINT_ENCRYPTED"
1111

1212
scope {
1313
tags = {
14-
Environment = var.environment_name
14+
Environment = var.environment
1515
}
1616
}
1717
}
@@ -22,7 +22,7 @@ resource "aws_backup_framework" "s3" {
2222

2323
scope {
2424
tags = {
25-
Environment = var.environment_name
25+
Environment = var.environment
2626
}
2727
}
2828

@@ -38,7 +38,7 @@ resource "aws_backup_framework" "s3" {
3838

3939
scope {
4040
tags = {
41-
Environment = var.environment_name
41+
Environment = var.environment
4242
}
4343
}
4444

@@ -54,7 +54,7 @@ resource "aws_backup_framework" "s3" {
5454

5555
scope {
5656
tags = {
57-
Environment = var.environment_name
57+
Environment = var.environment
5858
}
5959
}
6060

infrastructure/modules/aws-backup-source/backup_plan_dynamodb.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
resource "aws_backup_plan" "dynamodb" {
33
count = var.backup_plan_config_dynamodb.enable ? 1 : 0
44

5-
name = "${local.resource_name_prefix}-dynamodb-plan"
5+
name = "${local.csi}-dynamodb"
66

77
dynamic "rule" {
88
for_each = var.backup_plan_config_dynamodb.rules

infrastructure/modules/aws-backup-source/backup_plan_s3.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "aws_backup_plan" "s3" {
22
count = var.backup_plan_config_s3.enable ? 1 : 0
33

4-
name = "${local.resource_name_prefix}-plan"
4+
name = "${local.csi}-s3"
55

66
dynamic "rule" {
77
for_each = var.backup_plan_config_s3.rules

infrastructure/modules/aws-backup-source/backup_report_plan_backup_jobs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Create the reports
22
resource "aws_backup_report_plan" "backup_jobs" {
3-
name = "backup_jobs"
3+
name = "${local.csi_underscore}_backup_jobs"
44
description = "Report for showing whether backups ran successfully in the last 24 hours"
55

66
report_delivery_channel {

infrastructure/modules/aws-backup-source/backup_report_plan_backup_restore_testing_jobs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Create the restore testing completion reports
22
resource "aws_backup_report_plan" "backup_restore_testing_jobs" {
3-
name = "backup_restore_testing_jobs"
3+
name = "${local.csi_underscore}_backup_restore_testing_jobs"
44
description = "Report for showing whether backup restore test ran successfully in the last 24 hours"
55

66
report_delivery_channel {

infrastructure/modules/aws-backup-source/backup_report_plan_copy_jobs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "aws_backup_report_plan" "copy_jobs" {
22
count = var.backup_copy_vault_arn != "" && var.backup_copy_vault_account_id != "" ? 1 : 0
33

4-
name = "copy_jobs"
4+
name = "${local.csi_underscore}_copy_jobs"
55
description = "Report for showing whether copies ran successfully in the last 24 hours"
66

77
report_delivery_channel {

infrastructure/modules/aws-backup-source/backup_report_plan_resource_compliance.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_backup_report_plan" "resource_compliance" {
2-
name = "resource_compliance"
2+
name = "${local.csi_underscore}_resource_compliance"
33
description = "Report for showing whether resources are compliant with the framework"
44

55
report_delivery_channel {

infrastructure/modules/aws-backup-source/backup_restore_testing_plan.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "awscc_backup_restore_testing_plan" "main" {
2-
restore_testing_plan_name = local.resource_name_prefix
2+
restore_testing_plan_name = local.csi_underscore
33
schedule_expression = var.restore_testing_plan_scheduled_expression
44
start_window_hours = var.restore_testing_plan_start_window
55
recovery_point_selection = {

0 commit comments

Comments
 (0)