Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/aws-backup-source/backup_report_plan.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Create the reports
resource "aws_backup_report_plan" "backup_jobs" {
name = var.name_prefix != null ? "${var.name_prefix}_backup_jobs" : "backup_jobs"
name = var.name_prefix != null ? "${replace(local.resource_name_prefix, "-", "_")}_backup_jobs" : "backup_jobs"
description = "Report for showing whether backups ran successfully in the last 24 hours"

report_delivery_channel {
Expand All @@ -18,7 +18,7 @@ resource "aws_backup_report_plan" "backup_jobs" {

# Create the restore testing completion reports
resource "aws_backup_report_plan" "backup_restore_testing_jobs" {
name = var.name_prefix != null ? "${var.name_prefix}_backup_restore_testing_jobs" : "backup_restore_testing_jobs"
name = var.name_prefix != null ? "${replace(local.resource_name_prefix, "-", "_")}_backup_restore_testing_jobs" : "backup_restore_testing_jobs"
description = "Report for showing whether backup restore test ran successfully in the last 24 hours"

report_delivery_channel {
Expand All @@ -35,7 +35,7 @@ resource "aws_backup_report_plan" "backup_restore_testing_jobs" {
}

resource "aws_backup_report_plan" "resource_compliance" {
name = var.name_prefix != null ? "${var.name_prefix}_resource_compliance" : "resource_compliance"
name = var.name_prefix != null ? "${replace(local.resource_name_prefix, "-", "_")}_resource_compliance" : "resource_compliance"
description = "Report for showing whether resources are compliant with the framework"

report_delivery_channel {
Expand All @@ -55,7 +55,7 @@ resource "aws_backup_report_plan" "resource_compliance" {

resource "aws_backup_report_plan" "copy_jobs" {
count = var.backup_copy_vault_arn != "" && var.backup_copy_vault_account_id != "" ? 1 : 0
name = var.name_prefix != null ? "${var.name_prefix}_copy_jobs" : "copy_jobs"
name = var.name_prefix != null ? "${replace(local.resource_name_prefix, "-", "_")}_copy_jobs" : "copy_jobs"
description = "Report for showing whether copies ran successfully in the last 24 hours"

report_delivery_channel {
Expand Down
2 changes: 1 addition & 1 deletion modules/aws-backup-source/backup_restore_testing.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "awscc_backup_restore_testing_plan" "backup_restore_testing_plan" {
restore_testing_plan_name = var.name_prefix != null ? "${var.name_prefix}_backup_restore_testing_plan" : "backup_restore_testing_plan"
restore_testing_plan_name = var.name_prefix != null ? "${replace(local.resource_name_prefix, "-", "_")}_backup_restore_testing_plan" : "backup_restore_testing_plan"
schedule_expression = var.restore_testing_plan_scheduled_expression
start_window_hours = var.restore_testing_plan_start_window
recovery_point_selection = {
Expand Down
2 changes: 1 addition & 1 deletion modules/aws-backup-source/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data "aws_iam_policy_document" "assume_role" {
}

resource "aws_iam_role" "backup" {
name = "${var.project_name}BackupRole"
name = "${var.include_environment_in_resource_names ? "${var.project_name}-${var.environment_name}" : var.project_name}BackupRole"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
permissions_boundary = length(var.iam_role_permissions_boundary) > 0 ? var.iam_role_permissions_boundary : null
}
Expand Down
2 changes: 1 addition & 1 deletion modules/aws-backup-source/kms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "aws_kms_key" "aws_backup_key" {
}

resource "aws_kms_alias" "backup_key" {
name = var.name_prefix != null ? "alias/${var.name_prefix}/backup-key" : "alias/${var.environment_name}/backup-key"
name = var.name_prefix != null ? "alias/${var.include_environment_in_resource_names ? "${local.resource_name_prefix}" : var.name_prefix}/backup-key" : "alias/${var.environment_name}/backup-key"
target_key_id = aws_kms_key.aws_backup_key.key_id
}

Expand Down
2 changes: 1 addition & 1 deletion modules/aws-backup-source/locals.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
resource_name_prefix = var.name_prefix != null ? var.name_prefix : "${data.aws_region.current.id}-${data.aws_caller_identity.current.account_id}-backup"
resource_name_prefix = var.name_prefix != null ? (var.include_environment_in_resource_names ? "${var.name_prefix}-${var.environment_name}" : var.name_prefix) : (var.include_environment_in_resource_names ? "${data.aws_region.current.id}-${data.aws_caller_identity.current.account_id}-${var.environment_name}-backup" : "${data.aws_region.current.id}-${data.aws_caller_identity.current.account_id}-backup")
selection_tag_value_null_checked = (var.backup_plan_config.selection_tag_value == null) ? "True" : var.backup_plan_config.selection_tag_value
selection_tag_value_dynamodb_null_checked = (var.backup_plan_config_dynamodb.selection_tag_value == null) ? "True" : var.backup_plan_config_dynamodb.selection_tag_value
selection_tags_null_checked = (var.backup_plan_config.selection_tags == null) ? [{ "key" : var.backup_plan_config.selection_tag, "value" : local.selection_tag_value_null_checked }] : var.backup_plan_config.selection_tags
Expand Down
6 changes: 6 additions & 0 deletions modules/aws-backup-source/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,9 @@ variable "lambda_restore_to_s3_max_wait_minutes" {
type = number
default = 5
}

variable "include_environment_in_resource_names" {
description = "Should the environment name be included in resource names. Required for 'all resources in the same account'"
type = bool
default = false
}