diff --git a/src/commcare_cloud/commands/terraform/templates/commcarehq.tf.j2 b/src/commcare_cloud/commands/terraform/templates/commcarehq.tf.j2 index ed868ddffa..c3c9382ddf 100644 --- a/src/commcare_cloud/commands/terraform/templates/commcarehq.tf.j2 +++ b/src/commcare_cloud/commands/terraform/templates/commcarehq.tf.j2 @@ -43,6 +43,44 @@ locals { } } + +data "aws_iam_role" "data_lifecycle_role" { + name = "AWSDataLifecycleManagerDefaultRole" +} + +resource "aws_dlm_lifecycle_policy" "data_volume_backups" { + description = "Data Volume Backup Policy" + execution_role_arn = "${data.aws_iam_role.data_lifecycle_role.arn}" + state = "ENABLED" + + policy_details { + resource_types = ["VOLUME"] + + schedule { + name = "Default Schedule" + + create_rule { + interval = 24 + interval_unit = "HOURS" + times = ["22:00"] + } + + retain_rule { + count = 7 + } + + tags_to_add = { + VolumeType = "backup" + } + } + + target_tags = { + Group = "couchdb2" + VolumeType = "data" + } + } +} + {% for server in servers + proxy_servers %} module "server__{{ server.server_name }}" { source = "./modules/server" diff --git a/src/commcare_cloud/terraform/modules/server/main.tf b/src/commcare_cloud/terraform/modules/server/main.tf index c2042acfbe..dd7c09c596 100644 --- a/src/commcare_cloud/terraform/modules/server/main.tf +++ b/src/commcare_cloud/terraform/modules/server/main.tf @@ -41,10 +41,11 @@ resource "aws_ebs_volume" "ebs_volume" { type = "${var.secondary_volume_type}" tags { - Name = "vol-${var.server_name}" + Name = "data-vol-${var.server_name}" ServerName = "${var.server_name}" Environment = "${var.environment}" Group = "${var.group_tag}" + VolumeType = "data" } }