-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5189 from sunu/feature/dlm-nfs-backup
Enable automatic backup of EBS volumes using DLM
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# ref: https://docs.aws.amazon.com/ebs/latest/userguide/snapshot-lifecycle.html | ||
# Data Lifecycle Manager (DLM) is used to automate backup of EBS volumes. | ||
|
||
resource "aws_iam_role" "dlm_lifecycle_role" { | ||
count = var.enable_nfs_backup ? 1 : 0 | ||
name = "dlm-lifecycle-role" | ||
|
||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = "sts:AssumeRole" | ||
Effect = "Allow" | ||
Principal = { | ||
Service = "dlm.amazonaws.com" | ||
} | ||
} | ||
] | ||
}) | ||
} | ||
|
||
# Attach required policy to the IAM role | ||
resource "aws_iam_role_policy" "dlm_lifecycle" { | ||
count = var.enable_nfs_backup ? 1 : 0 | ||
name = "dlm-lifecycle-policy" | ||
role = aws_iam_role.dlm_lifecycle_role.id | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Effect = "Allow" | ||
Action = [ | ||
"ec2:CreateSnapshot", | ||
"ec2:CreateSnapshots", | ||
"ec2:DeleteSnapshot", | ||
"ec2:DescribeVolumes", | ||
"ec2:DescribeInstances", | ||
"ec2:DescribeSnapshots" | ||
] | ||
Resource = "*" | ||
}, | ||
{ | ||
Effect = "Allow" | ||
Action = [ | ||
"ec2:CreateTags" | ||
] | ||
Resource = "arn:aws:ec2:*::snapshot/*" | ||
} | ||
] | ||
}) | ||
} | ||
|
||
# Create the DLM lifecycle policy for NFS home directories backup | ||
resource "aws_dlm_lifecycle_policy" "nfs_backup" { | ||
count = var.enable_nfs_backup ? 1 : 0 | ||
description = "DLM lifecycle policy for NFS home directories backup" | ||
execution_role_arn = aws_iam_role.dlm_lifecycle_role.arn | ||
state = "ENABLED" | ||
|
||
policy_details { | ||
resource_types = ["VOLUME"] | ||
|
||
schedule { | ||
name = "Daily backup" | ||
|
||
create_rule { | ||
interval = 24 | ||
interval_unit = "HOURS" | ||
times = ["23:45"] | ||
} | ||
|
||
retain_rule { | ||
count = 5 # Keep last 5 daily backups | ||
} | ||
|
||
tags_to_add = { | ||
SnapshotCreator = "DLM" | ||
Purpose = "NFS-Backup" | ||
} | ||
|
||
copy_tags = true | ||
} | ||
|
||
target_tags = { | ||
NFSBackup = "true" # Tag to identify volumes to backup | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,4 +226,6 @@ ebs_volumes = { | |
} | ||
} | ||
|
||
enable_nfs_backup = true | ||
|
||
original_single_efs_tags = { "2i2c:hub-name" : "prod" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters