hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.86k stars 9.21k forks source link

[Enhancement]: Support for pre/post scripts in DLM policy #35685

Open jaygridley opened 9 months ago

jaygridley commented 9 months ago

Description

AWS introduced support for running SSM Documents when taking volume snapshots with Data Lifecycle Manager, see https://aws.amazon.com/about-aws/whats-new/2023/11/amazon-data-lifecycle-manager-pre-post-script-automation-ebs-snapshots/.

The AWS API is ready for this, see https://docs.aws.amazon.com/dlm/latest/APIReference/API_Script.html.

Support for this in the aws_dlm_lifecycle_policy resource would be nice. Currently, only local-exec workarounds are possible. There is no DLM support in the Cloud Control API.

Affected Resource(s) and/or Data Source(s)

Potential Terraform Configuration

resource "aws_dlm_lifecycle_policy" "this" {
  description        = "DLM policy to create snapshots of EC2 volumes using pre/post scripts"
  execution_role_arn = "<ARN>"
  state              = "ENABLED"

  policy_details {
    resource_types = ["INSTANCE"]

    schedule {
      name = "<NAME>"

      create_rule {
        cron_expression = "cron(00 00 ? * SUN *)"

        script {
          stages = ["PRE", "POST"]
          execution_handler = "<SSM_DOCUMENT_ARN>"
        }
      }

      retain_rule {
        count = 1
      }
    }

    target_tags = {
      "backup" = "enabled"
    }
  }
}

References

Would you like to implement a fix?

None

github-actions[bot] commented 9 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

patstrom commented 2 months ago

I've tried to implement this on my branch but I don't understand how to properly write and run tests for this. Can anyone help me out with this?