I have a statement in terraform that is as follows:
statement {
sid = "DenyDelete"
effect = "Deny"
actions = [
"iam:Delete*"
]
resources = [
"arn:aws:iam::123456789012:user/(?!userA|userB)",
]
}
With this statement I am hoping to deny iam:delete
actions on all users except userA and userB. i.e. the regex will match any string that starts with arn:aws:iam::123456789012:user/
and is followed by anything but userA
and userB
. I have tested the regex arn:aws:iam::123456789012:user\/(?!userA|userB)
in https://regex101.com/ and I have confirmed it will match any user ARN except that of userA and userB. However, deploying this statement does not seem to give the desired results and I presume it is because I am using the regex syntax wrong in terraform - does anyone know the correct regex syntax so that resources will include all users except userA and userB? Note that I cannot use NotResource
as that will include all other resources including non-users.