From 251fd663e45774dd78a72c7eb347694d6a06d44d Mon Sep 17 00:00:00 2001 From: Paul Montero Date: Thu, 16 May 2019 17:22:27 -0500 Subject: [PATCH 1/3] Module to enable DML lifecycle policies --- modules/dlm-lifecycle-policy/README.md | 28 ++++++++++ modules/dlm-lifecycle-policy/iam.tf | 58 ++++++++++++++++++++ modules/dlm-lifecycle-policy/main.tf | 43 +++++++++++++++ modules/dlm-lifecycle-policy/variables.tf | 67 +++++++++++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 modules/dlm-lifecycle-policy/README.md create mode 100644 modules/dlm-lifecycle-policy/iam.tf create mode 100644 modules/dlm-lifecycle-policy/main.tf create mode 100644 modules/dlm-lifecycle-policy/variables.tf diff --git a/modules/dlm-lifecycle-policy/README.md b/modules/dlm-lifecycle-policy/README.md new file mode 100644 index 00000000..0460e757 --- /dev/null +++ b/modules/dlm-lifecycle-policy/README.md @@ -0,0 +1,28 @@ +## Data Lifecycle Manager (DLM) lifecycle policy for managing snapshots + +This module creates an IAM role and a policy that manage the creation of EBS snapshots, Data Lifecycle Manager policy let you create snapshots according to the schedule that you choose. + +### Example how to use + +Define the module in your terraform project: +``` +variable "ebs_target_tags" { + description = "EBS name/tag to query" + default = "myebstagname" +} + +Define variables +... + +module "ebs-backup-policy" { + source = "github.com/fpco/terraform-aws-foundation//modules/dlm-lifecycle-policy" + + name_prefix = "${var.name}" + dml_description = "${var.dml_description}" + ebs_target_tags = "${merge(map("Name", "${var.ebs_target_tags}"), "${var.extra_tags}")}" + schedule_create_interval = "${var.schedule_create_interval}" + schedule_create_time = "${var.schedule_create_time}" + schedule_retain_rule = "${var.schedule_retain_rule}" + schedule_tags_to_add = "${merge(map("Name", "${var.name}-dlm", "SnapshotCreator", "DLM lifecycle"))}" +} +``` diff --git a/modules/dlm-lifecycle-policy/iam.tf b/modules/dlm-lifecycle-policy/iam.tf new file mode 100644 index 00000000..b241fc39 --- /dev/null +++ b/modules/dlm-lifecycle-policy/iam.tf @@ -0,0 +1,58 @@ +# Create the iam role +resource "aws_iam_role" "dlm_lifecycle_role" { + count = "${var.create_dlm_iam_role == "true" ? 1 : 0}" + + name = "${var.role_name}" + assume_role_policy = < Date: Tue, 1 Oct 2019 03:52:45 -0500 Subject: [PATCH 2/3] modules/dlm-lifecycle-policy: Update DML module to tf 0.12 and move the IAM role to another role --- modules/dlm-lifecycle-policy/README.md | 29 +++++------- modules/dlm-lifecycle-policy/iam.tf | 58 ----------------------- modules/dlm-lifecycle-policy/main.tf | 27 ++++++----- modules/dlm-lifecycle-policy/variables.tf | 36 +++++++------- modules/dlm-lifecycle-policy/versions.tf | 3 ++ 5 files changed, 51 insertions(+), 102 deletions(-) delete mode 100644 modules/dlm-lifecycle-policy/iam.tf create mode 100644 modules/dlm-lifecycle-policy/versions.tf diff --git a/modules/dlm-lifecycle-policy/README.md b/modules/dlm-lifecycle-policy/README.md index 0460e757..4f016d99 100644 --- a/modules/dlm-lifecycle-policy/README.md +++ b/modules/dlm-lifecycle-policy/README.md @@ -1,28 +1,25 @@ ## Data Lifecycle Manager (DLM) lifecycle policy for managing snapshots -This module creates an IAM role and a policy that manage the creation of EBS snapshots, Data Lifecycle Manager policy let you create snapshots according to the schedule that you choose. +This module creates the policy that manage the creation of EBS snapshots through AWS Data Lifecycle Manager, the policy let you manage the schedule of the snapshot as well as the number of snapshots. ### Example how to use -Define the module in your terraform project: -``` -variable "ebs_target_tags" { - description = "EBS name/tag to query" - default = "myebstagname" -} - Define variables -... +``` module "ebs-backup-policy" { source = "github.com/fpco/terraform-aws-foundation//modules/dlm-lifecycle-policy" - name_prefix = "${var.name}" - dml_description = "${var.dml_description}" - ebs_target_tags = "${merge(map("Name", "${var.ebs_target_tags}"), "${var.extra_tags}")}" - schedule_create_interval = "${var.schedule_create_interval}" - schedule_create_time = "${var.schedule_create_time}" - schedule_retain_rule = "${var.schedule_retain_rule}" - schedule_tags_to_add = "${merge(map("Name", "${var.name}-dlm", "SnapshotCreator", "DLM lifecycle"))}" + name_prefix = project-name-backup + description = "DLM lifecycle policy" + ebs_target_tags = "ebs-to-take-snapshot-name-ec2-volume" + policy_name = "One week of daily snapshots" + policy_interval = 24 + policy_time = ["23:45"] + policy_copy_tags = false + policy_retain_rule = 14 + policy_tags_to_add = "${merge(map("Name", "${var.name}-dlm", "SnapshotCreator", "DLM lifecycle"))}" + resource_type = ["VOLUME"] + role_name = "dlm-lifecycle-role" } ``` diff --git a/modules/dlm-lifecycle-policy/iam.tf b/modules/dlm-lifecycle-policy/iam.tf deleted file mode 100644 index b241fc39..00000000 --- a/modules/dlm-lifecycle-policy/iam.tf +++ /dev/null @@ -1,58 +0,0 @@ -# Create the iam role -resource "aws_iam_role" "dlm_lifecycle_role" { - count = "${var.create_dlm_iam_role == "true" ? 1 : 0}" - - name = "${var.role_name}" - assume_role_policy = < Date: Tue, 1 Oct 2019 04:00:20 -0500 Subject: [PATCH 3/3] modules/dlm-lifecycle-iam-role: Added DLM IAM role to allow create snapshots --- modules/dlm-lifecycle-iam-role/README.md | 15 ++++++ modules/dlm-lifecycle-iam-role/main.tf | 56 ++++++++++++++++++++++ modules/dlm-lifecycle-iam-role/versions.tf | 3 ++ modules/dlm-lifecycle-policy/main.tf | 2 +- modules/dlm-lifecycle-policy/variables.tf | 2 +- 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 modules/dlm-lifecycle-iam-role/README.md create mode 100644 modules/dlm-lifecycle-iam-role/main.tf create mode 100644 modules/dlm-lifecycle-iam-role/versions.tf diff --git a/modules/dlm-lifecycle-iam-role/README.md b/modules/dlm-lifecycle-iam-role/README.md new file mode 100644 index 00000000..301fa445 --- /dev/null +++ b/modules/dlm-lifecycle-iam-role/README.md @@ -0,0 +1,15 @@ +## Data Lifecycle Manager (DLM) lifecycle policy for managing snapshots + +This module creates the IAM role and the policy that allows the AWS Data Lifecycle Manager to create snapshots. + +### Example how to use + +Define variables + +``` +module "ebs-backup-policy" { + source = "github.com/fpco/terraform-aws-foundation//modules/dlm-lifecycle-iam" + + iam_role_name = "dlm-lifecycle-role" +} +``` diff --git a/modules/dlm-lifecycle-iam-role/main.tf b/modules/dlm-lifecycle-iam-role/main.tf new file mode 100644 index 00000000..581292e8 --- /dev/null +++ b/modules/dlm-lifecycle-iam-role/main.tf @@ -0,0 +1,56 @@ +variable "iam_role_name" { + description = "The IAM role name for the DLM lifecyle policy" + type = string + default = "dlm-lifecycle-role" +} + +# Create the iam role +resource "aws_iam_role" "dlm_lifecycle_role" { + name = var.iam_role_name + assume_role_policy = <