Created
August 20, 2015 15:32
-
-
Save Ashex/0e3da12c0798374b593c to your computer and use it in GitHub Desktop.
Dynamic VPC restriction for IAM policy
This file contains hidden or 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
policy_condition = Join("", ["arn:aws:ec2:", Ref("AWS::AccountId"), ":vpc/" ,Ref(VPC)]) | |
t.add_resource( | |
Role( | |
"natEc2Role", | |
Path="/", | |
AssumeRolePolicyDocument= | |
{ "Statement": [ { | |
"Effect": "Allow", | |
"Principal": { "Service": [ "ec2.amazonaws.com" ] }, | |
"Action": [ "sts:AssumeRole" ] | |
} ] } | |
, | |
Policies=[ | |
Policy( | |
PolicyName="attachNetworkInterface", | |
PolicyDocument={ | |
"Statement": [ { | |
"Effect": "Allow", | |
"Action": "ec2:attachNetworkInterface", | |
"Resource": "*", | |
"Condition": { | |
"StringEquals": { | |
"ec2:VPC": policy_condition | |
}, | |
} | |
} ], | |
} | |
) | |
] | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment