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