-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-cdk): deploy supports CloudFormation Role (#940)
Add --role-arn parameter to the CDK toolkit to allow passing a custom role when invoking CloudFormation. Fixes #735.
- Loading branch information
Showing
4 changed files
with
106 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
scriptdir=$(cd $(dirname $0) && pwd) | ||
source ${scriptdir}/common.bash | ||
# ---------------------------------------------------------- | ||
|
||
role_name=cdk-integ-test-role | ||
delete_role() { | ||
for policy_name in $(aws iam list-role-policies --role-name $role_name --output text --query PolicyNames); do | ||
aws iam delete-role-policy --role-name $role_name --policy-name $policy_name | ||
done | ||
aws iam delete-role --role-name $role_name | ||
} | ||
|
||
delete_role || echo 'Role does not exist yet' | ||
|
||
role_arn=$(aws iam create-role \ | ||
--output text --query Role.Arn \ | ||
--role-name $role_name \ | ||
--assume-role-policy-document file://<(echo '{ | ||
"Version": "2012-10-17", | ||
"Statement": [{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { "Service": "cloudformation.amazonaws.com" }, | ||
"Effect": "Allow" | ||
}] | ||
}')) | ||
trap delete_role EXIT | ||
aws iam put-role-policy \ | ||
--role-name $role_name \ | ||
--policy-name DefaultPolicy \ | ||
--policy-document file://<(echo '{ | ||
"Version": "2012-10-17", | ||
"Statement": [{ | ||
"Action": "*", | ||
"Resource": "*", | ||
"Effect": "Allow" | ||
}] | ||
}') | ||
|
||
setup | ||
|
||
stack_arn=$(cdk --role-arn $role_arn deploy cdk-toolkit-integration-test-2) | ||
echo "Stack deployed successfully" | ||
|
||
# verify that we only deployed a single stack (there's a single ARN in the output) | ||
assert_lines "${stack_arn}" 1 | ||
|
||
# verify the number of resources in the stack | ||
response_json=$(mktemp).json | ||
aws cloudformation describe-stack-resources --stack-name ${stack_arn} > ${response_json} | ||
resource_count=$(node -e "console.log(require('${response_json}').StackResources.length)") | ||
if [ "${resource_count}" -ne 2 ]; then | ||
fail "stack has ${resource_count} resources, and we expected two" | ||
fi | ||
|
||
# destroy | ||
cdk destroy --role-arn $role_arn -f cdk-toolkit-integration-test-2 | ||
|
||
echo "✅ success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters