get_current_dlm_policies 665 B

123456789101112131415161718
  1. #! /bin/bash
  2. # Gets the current dlm policies, if any.
  3. #
  4. # WARNING: THIS IS RUN DURRING A 'PLAN' STEP. Do not make changes. Read-only in this script.
  5. # TODO: Pass these in
  6. PROFILE=mdr-test-c2-gov
  7. REGION=us-gov-east-1
  8. ACCOUNT=738800754746
  9. POLICIES=$(aws --profile ${PROFILE} --region ${REGION} dlm get-lifecycle-policies)
  10. # Extracts the policy IDs of IMAGE_MANAGEMENT policye
  11. POLICY_IDS=$(echo $POLICIES | jq -r '[.Policies[] | select(.PolicyType=="IMAGE_MANAGEMENT") | select(.Tags.SnapshotPolicy=="Daily")] | first | .PolicyId')
  12. # jq ensures a safe json output
  13. # Will return 'null' if no matching policy
  14. jq -n --arg policy $POLICY_IDS '{ "PolicyId": $policy }'