This repository provides an automated solution to enforce mandatory tags on AWS resources using AWS Config Rules and Lambda functions.
This project is for demonstration purposes and should be thoroughly reviewed and tested before using in production environments. You should work with your organisation’s security team to comply with the standards set if you are to deploy this solution in Production environment.
The solution automatically detects resources that are not compliant with the organization's tagging standards and applies the required tags. This helps maintain consistent resource tagging across your AWS environment with minimal manual intervention.
The solution works as follows:
- AWS Config Rule continuously monitors resources for required tags
- When non-compliant resources are detected, EventBridge triggers the remediation workflow
- Events are queued in SQS for reliable processing
- Lambda function retrieves the required tag values from SSM Parameter Store and applies them to the non-compliant resources
- AWS Config must be enabled in your AWS account
- Terraform installed locally
- Required IAM permissions to create the necessary resources
-
Clone this repository
-
Initialize Terraform:
terraform init
-
Review and modify variables in
terraform.tfvars
if needed:cost_center_value = "" department_value = "" compliance_resource_types = [ "AWS::SQS::Queue", "AWS::DynamoDB::Table" ]
-
Deploy the solution:
terraform plan terraform apply
-
To modify the set of mandatory tags:
- Modify or add SSM Parameters in the Terraform code
- The current mandatory tags are:
- CostCenter
- Department
-
To add support for additional resource types:
- Update the
compliance_resource_types
variable - Add service-specific tagging logic in the remediation Lambda function if needed
- Update the
-
Consider storing the Terraform state in a remote backend such as S3. An example commented out code is included in
providers.tf
.
- This solution works for resources that are supported by AWS Config. See AWS documentation for a full list of supported AWS resource types. Examples of unsupported services: ElastiCache, Managed Workflows for Apache Airflow (MWAA)
- The remediation function in this solution leverages AWS Resource Groups Tagging API to apply tags to resources. See AWS documentation. For resource types that are not supported, you can add a custom function to use the service-specific APIs to apply tags. In this respository, an example implementation for EventBridge Rule is included for reference.
- Resource types must be explicitly defined in the Config Rule scope
- Maximum tag value length and character restrictions apply as per AWS limits