ami_backups.tf 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. # At this time, terraform does not support DLM AMI policies, only snapshots.
  2. # So we do it ourselves
  3. #
  4. # NOTE: This will not update an existing policy, but will create one if it's missing.
  5. # Grab the current policy name. This turned out to be unnecessary for my purposes, but
  6. # will be useful if in the future we decide to implement a 'modify' resource.
  7. #
  8. # WARNING: External data sources are run before the apply, and even before any decision
  9. # is made whether or not to apply, so do not make changes in such a script.
  10. data "external" "get_dlm_policies" {
  11. program = ["bin/get_current_dlm_policies", var.aws_partition, var.aws_region, var.aws_account_id, var.account_name]
  12. }
  13. # useful for debugging, but don't leave it uncommented or itll report a change on second apply:
  14. #output "dlm_policies" {
  15. # value = data.external.get_dlm_policies.result
  16. #}
  17. # In rare cases, you may need/want to manually recreate this. To do so, run
  18. # terragrunt taint null_resource.create_dlm_policy
  19. resource "null_resource" "create_dlm_policy" {
  20. #count = data.external.get_dlm_policies.result["PolicyId"] == "null" ? 1 : 0
  21. #count = data.external.get_dlm_policies.result["PolicyId"] == "policy-02af49210b5b375d5" ? 1 : 0
  22. # Could maybe find some sort of trigger here, in case the DLM is deleted?
  23. provisioner "local-exec" {
  24. command = "bin/create_dlm_policy ${var.aws_partition} ${var.aws_region} ${var.aws_account_id} ${var.account_name}"
  25. }
  26. }