#!/usr/bin/env bash # Source: https://gist.github.com/nitrocode/0cd3db8e0a7c994fbca2a6f252ca40cf # extract and transform # purposely did not lowercase everything `tr '[:upper:]' '[:lower:]'` because we want to keep the casing rg 'permissions[\s]?=[\s]?\((.*?)\)[\s]?' \ --multiline-dotall \ --multiline \ --only-matching \ --replace '$1' \ --no-filename \ --glob '!tools/*' | tr '"' "'" | sed $'s/\', \'/\', \\\n\'/g' | tr "'" '"' | awk '{$1=$1};1' | sed '/^[[:space:]]*$/d' | grep -e '^"' | tr -d '"' | tr -d ',' | sort | uniq > perms.txt # run python script to convert to terraform python convert-extracted-cloud-custodian-perms-to-terraform.py < perms.txt > cloud-custodian-iam-policy.tf echo "Generated data.aws_iam_policy_document.custodian.json policy in cloud-custodian-iam-policy.tf"