Tag Enforcement
Policy Description
What this SCP does
This Service Control Policy (SCP) requires specific tags on all EC2 instances and RDS databases, ensuring proper resource categorization and cost allocation. For EC2 instances, it enforces the presence of the 'Environment' tag on the resource itself using resource-level tag conditions. For RDS databases, it enforces tagging at creation time using request-level tag conditions. This dual approach ensures effective tag enforcement while accommodating the different tagging capabilities of each service.
When users try to create EC2 instances without specifying the required 'Environment' tag in the resource tags, or RDS instances without the tag in the request, the operation will be denied. This enforces tagging discipline across all accounts in the organization while respecting service-specific tagging mechanisms.
Validation Strategy
How to test this SCP works
To validate this SCP, try to create instances with and without the required 'Environment' tag. Note that EC2 and RDS use different tagging mechanisms in the API calls.
- Invalid test: Launch an EC2 instance without specifying the 'Environment' tag in the resource tags (should be denied)
- Valid test: Launch an EC2 instance with the 'Environment' tag specified in the resource tags via tag-specifications (should succeed)
- Invalid test: Create an RDS instance without the 'Environment' tag in the request (should be denied)
- Valid test: Create an RDS instance with the 'Environment' tag in the request tags (should succeed)
We expect resource creation without the required tag to be denied with an AccessDenied error, while creation with the proper tag should succeed. For EC2, tags must be specified using the tag-specifications parameter, while for RDS they are specified directly in the request tags.
SCP Policy & Validation Scenarios
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyEC2WithoutTags",
"Effect": "Deny",
"Action": "ec2:RunInstances",
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": {
"Null": {
"ec2:ResourceTag/Environment": "true"
}
}
},
{
"Sid": "DenyRDSWithoutTags",
"Effect": "Deny",
"Action": "rds:CreateDBInstance",
"Resource": "*",
"Condition": {
"Null": {
"aws:RequestTag/Environment": "true"
}
}
}
]
}