@@ -11,7 +11,7 @@ locals {
1111 SecurityLevel = " high"
1212 Compliance = " required"
1313 }
14-
14+
1515 vault_name = " ${ var . project_name } -${ var . environment } -secure-vault"
1616 plan_name = " ${ var . project_name } -${ var . environment } -secure-plan"
1717}
@@ -23,37 +23,37 @@ module "backup" {
2323 # Vault configuration with security controls
2424 vault_name = local. vault_name
2525 vault_kms_key_arn = aws_kms_key. backup_key . arn
26-
26+
2727 # Enable vault lock for compliance
2828 locked = var. enable_vault_lock
2929 changeable_for_days = var. vault_lock_changeable_days
30-
30+
3131 # Security-focused retention policies
3232 min_retention_days = var. min_retention_days
3333 max_retention_days = var. max_retention_days
34-
34+
3535 # Backup plan with security controls
3636 plan_name = local. plan_name
37-
37+
3838 rules = [
3939 {
4040 name = " daily-secure-backup"
41- schedule = " cron(0 5 ? * * *)" # 5 AM UTC daily
42- start_window = 480 # 8 hours
43- completion_window = 10080 # 7 days
41+ schedule = " cron(0 5 ? * * *)" # 5 AM UTC daily
42+ start_window = 480 # 8 hours
43+ completion_window = 10080 # 7 days
4444 enable_continuous_backup = var.enable_continuous_backup
45-
45+
4646 lifecycle = {
47- cold_storage_after = 30 # Move to cold storage after 30 days
47+ cold_storage_after = 30 # Move to cold storage after 30 days
4848 delete_after = var.backup_retention_days
4949 }
50-
50+
5151 # Security-focused tagging
5252 recovery_point_tags = merge (local. common_tags , {
5353 BackupType = " daily"
5454 Encrypted = " true"
5555 })
56-
56+
5757 # Cross-region backup with security controls
5858 copy_actions = var.enable_cross_region_backup ? [
5959 {
@@ -67,37 +67,37 @@ module "backup" {
6767 },
6868 {
6969 name = " weekly-secure-backup"
70- schedule = " cron(0 6 ? * SUN *)" # 6 AM UTC on Sundays
70+ schedule = " cron(0 6 ? * SUN *)" # 6 AM UTC on Sundays
7171 start_window = 480
7272 completion_window = 10080
7373 enable_continuous_backup = false
74-
74+
7575 lifecycle = {
76- cold_storage_after = 90 # Move to cold storage after 90 days
76+ cold_storage_after = 90 # Move to cold storage after 90 days
7777 delete_after = var.weekly_backup_retention_days
7878 }
79-
79+
8080 recovery_point_tags = merge (local. common_tags , {
8181 BackupType = " weekly"
8282 Encrypted = " true"
8383 })
8484 }
8585 ]
86-
86+
8787 # Secure backup selections
8888 selections = {
8989 " production-databases" = {
9090 resources = var.database_resources
91-
91+
9292 # Security-focused resource selection
9393 conditions = {
9494 " string_equals" = {
95- " aws:ResourceTag/Environment" = var.environment
96- " aws:ResourceTag/SecurityLevel" = " high"
95+ " aws:ResourceTag/Environment" = var.environment
96+ " aws:ResourceTag/SecurityLevel" = " high"
9797 " aws:ResourceTag/BackupRequired" = " true"
9898 }
9999 }
100-
100+
101101 selection_tags = [
102102 {
103103 type = " STRINGEQUALS"
@@ -111,70 +111,70 @@ module "backup" {
111111 }
112112 ]
113113 },
114-
114+
115115 " production-volumes" = {
116116 resources = var.volume_resources
117-
117+
118118 conditions = {
119119 " string_equals" = {
120- " aws:ResourceTag/Environment" = var.environment
121- " aws:ResourceTag/SecurityLevel" = " high"
120+ " aws:ResourceTag/Environment" = var.environment
121+ " aws:ResourceTag/SecurityLevel" = " high"
122122 " aws:ResourceTag/BackupRequired" = " true"
123123 }
124124 }
125125 }
126126 }
127-
127+
128128 # Security notifications
129129 notifications = {
130130 backup_vault_events = [
131131 " BACKUP_JOB_STARTED" ,
132132 " BACKUP_JOB_COMPLETED" ,
133133 " BACKUP_JOB_FAILED" ,
134- " RESTORE_JOB_STARTED" ,
134+ " RESTORE_JOB_STARTED" ,
135135 " RESTORE_JOB_COMPLETED" ,
136136 " RESTORE_JOB_FAILED"
137137 ]
138138 sns_topic_arn = aws_sns_topic.backup_notifications.arn
139139 }
140-
140+
141141 # Security-focused tagging
142142 tags = local. common_tags
143143}
144144
145145# Cross-region backup vault for disaster recovery
146146resource "aws_backup_vault" "cross_region_vault" {
147147 count = var. enable_cross_region_backup ? 1 : 0
148-
148+
149149 name = " ${ local . vault_name } -cross-region"
150150 kms_key_arn = aws_kms_key. cross_region_backup_key [0 ]. arn
151-
151+
152152 # Enable vault lock for compliance
153153 dynamic "lock_configuration" {
154154 for_each = var. enable_vault_lock ? [1 ] : []
155-
155+
156156 content {
157157 changeable_for_days = var. vault_lock_changeable_days
158158 min_retention_days = var. min_retention_days
159159 max_retention_days = var. max_retention_days
160160 }
161161 }
162-
162+
163163 tags = merge (local. common_tags , {
164164 Name = " ${ local . vault_name } -cross-region"
165165 Type = " cross-region"
166166 })
167-
167+
168168 provider = aws. cross_region
169169}
170170
171171# SNS topic for security notifications
172172resource "aws_sns_topic" "backup_notifications" {
173173 name = " ${ var . project_name } -${ var . environment } -backup-notifications"
174-
174+
175175 # Enable encryption for SNS
176176 kms_master_key_id = aws_kms_key. sns_key . arn
177-
177+
178178 tags = merge (local. common_tags , {
179179 Name = " ${ var . project_name } -${ var . environment } -backup-notifications"
180180 })
@@ -183,7 +183,7 @@ resource "aws_sns_topic" "backup_notifications" {
183183# SNS topic policy for backup service
184184resource "aws_sns_topic_policy" "backup_notifications" {
185185 arn = aws_sns_topic. backup_notifications . arn
186-
186+
187187 policy = jsonencode ({
188188 Version = " 2012-10-17"
189189 Statement = [
@@ -210,7 +210,7 @@ resource "aws_sns_topic_policy" "backup_notifications" {
210210# Email subscription for notifications
211211resource "aws_sns_topic_subscription" "backup_notifications_email" {
212212 count = var. notification_email != " " ? 1 : 0
213-
213+
214214 topic_arn = aws_sns_topic. backup_notifications . arn
215215 protocol = " email"
216216 endpoint = var. notification_email
0 commit comments