I am trying to create an IAM policy that will allow the user/role to create any resource (EC2, Redshift, RDS, etc.) - only if they provide certain pre-defined tags while creating them.
Steps followed so far:
- Create an IAM Role: Let's call it role-XYZ
- Attach AWS-Managed 'ReadOnlyPolicy' to this role - this will make sure the role has read-only access to all services
- Create a new managed policy as follows. This will allow rest (including creation) of the actions based on a condition.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VitalizeTagPermission",
"Effect": "Allow",
"Action": [
"ec2:*",
"rds:*"
],
"Resource": [
"*"
],
"Condition": {
"ForAllValues:StringLike": {
"aws:TagKeys": "ProjectCode"
}
}
}
]
}
This does not work. The user is able to create the resource even without the ProjectCode tag. Any leads will be appreciated.