Skip to content

Instantly share code, notes, and snippets.

@toddlers
Created April 13, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddlers/b6b26d27d1fa3bb85bf819d4901b516f to your computer and use it in GitHub Desktop.
Save toddlers/b6b26d27d1fa3bb85bf819d4901b516f to your computer and use it in GitHub Desktop.
apply nested stack policy
function protect_nested_stacks() {
local parent_stack=$1 stack_policy_file=$2
local nested_stacks=$(aws cloudformation list-stack-resources \
--stack-name ${parent_stack} \
--query "StackResourceSummaries[?ResourceType=='AWS::CloudFormation::Stack'].[PhysicalResourceId]" \
--output text
)
for stack in ${nested_stacks}; do
aws cloudformation set-stack-policy --stack-name ${stack} --stack-policy-body file://${stack_policy_file}
protect_nested_stacks ${stack} ${stack_policy_file}
done
}
{
"Statement" : [
{
"Effect" : "Allow",
"Action" : "Update:*",
"Principal": "*",
"Resource" : "*"
},
{
"Effect" : "Deny",
"Action" : ["Update:Replace", "Update:Delete"],
"Principal": "*",
"Resource" : "*",
"Condition": {
"StringEquals" : {
"ResourceType" : ["AWS::RDS::DBInstance"]
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment