|
1 | 1 | # AWS Magic Tagging Resources |
2 | 2 |
|
3 | | -Use the EventBridge to trigger a Lambda function to tag resources in AWS. |
| 3 | +This script is designed to automatically tag AWS resources when certain events occur. It is intended to be used as an AWS Lambda function, triggered by AWS EventBridge. |
4 | 4 |
|
5 | 5 | ## Prerequisites |
6 | 6 |
|
@@ -31,6 +31,8 @@ resource_tags = { |
31 | 31 | - IAM Policy |
32 | 32 | - Log Group |
33 | 33 | - EventBridge Rule |
| 34 | +- Resource Group |
| 35 | +- CloudWatch Dashboard |
34 | 36 |
|
35 | 37 | ## How to use this |
36 | 38 |
|
@@ -62,23 +64,84 @@ Deploy this terraform and verify the resource tags are created. |
62 | 64 |
|
63 | 65 | `sh multi-region-destroy.sh` |
64 | 66 |
|
| 67 | +## Functionality |
| 68 | + |
| 69 | +1. **Extracting Tag Information**: The `get_tag_information` function extracts tag information from the event, including the source IP address, event time, and user agent. It also calls the `taggers.get_event_time` and `taggers.get_identity_type` functions to get additional tag information. |
| 70 | + |
| 71 | +2. **Adding Tags**: The `lambda_handler` function is the entry point for the Lambda function. It first calls the `get_tag_information` function to get the tag information, then decides which type of AWS resource to add tags to based on the source of the event. For example, if the source of the event is "aws.ec2", it calls the `ec2_tagger.tagger` function to add tags to EC2 resources. |
| 72 | + |
65 | 73 |
|
66 | 74 | ### Support auto-tagging resources |
67 | | - |
| 75 | + |
68 | 76 | - EC2 |
69 | 77 | - ELB |
70 | 78 | - RDS |
71 | 79 | - CloudFront |
72 | 80 | - Lambda |
73 | 81 | - SNS |
74 | 82 | - IAM |
| 83 | + - AutoScaling |
75 | 84 |
|
76 | 85 |
|
77 | 86 | ### Default tags |
78 | | - |
79 | | - - Owner |
80 | | - - SourceIP |
81 | | - - UserType |
82 | | - - EventTime |
83 | | - - UserName / RoleName |
84 | 87 |
|
| 88 | + - Owner |
| 89 | + - SourceIP |
| 90 | + - UserType |
| 91 | + - EventTime |
| 92 | + - UserName / RoleName |
| 93 | + |
| 94 | + |
| 95 | +<!-- BEGIN_TF_DOCS --> |
| 96 | +## Requirements |
| 97 | + |
| 98 | +| Name | Version | |
| 99 | +|------|---------| |
| 100 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14 | |
| 101 | +| <a name="requirement_aws"></a> [aws](#requirement\_aws) | 4.22.0 | |
| 102 | + |
| 103 | +## Providers |
| 104 | + |
| 105 | +| Name | Version | |
| 106 | +|------|---------| |
| 107 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.22.0 | |
| 108 | + |
| 109 | +## Modules |
| 110 | + |
| 111 | +| Name | Source | Version | |
| 112 | +|------|--------|---------| |
| 113 | +| <a name="module_lambda"></a> [lambda](#module\_lambda) | terraform-aws-modules/lambda/aws | 3.3.1 | |
| 114 | + |
| 115 | +## Resources |
| 116 | + |
| 117 | +| Name | Type | |
| 118 | +|------|------| |
| 119 | +| [aws_cloudwatch_dashboard.dashboard](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/resources/cloudwatch_dashboard) | resource | |
| 120 | +| [aws_cloudwatch_event_rule.event_rule](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/resources/cloudwatch_event_rule) | resource | |
| 121 | +| [aws_cloudwatch_event_target.event_rule](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/resources/cloudwatch_event_target) | resource | |
| 122 | +| [aws_iam_policy.lambda_tagging_policy](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/resources/iam_policy) | resource | |
| 123 | +| [aws_iam_role.lambda_function_role](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/resources/iam_role) | resource | |
| 124 | +| [aws_iam_role_policy_attachment.lambda_basic_policy](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/resources/iam_role_policy_attachment) | resource | |
| 125 | +| [aws_iam_role_policy_attachment.lambda_tagging_policy](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/resources/iam_role_policy_attachment) | resource | |
| 126 | +| [aws_lambda_permission.event_rule](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/resources/lambda_permission) | resource | |
| 127 | +| [aws_resourcegroups_group.resource_group](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/resources/resourcegroups_group) | resource | |
| 128 | +| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/data-sources/caller_identity) | data source | |
| 129 | +| [aws_iam_role.lambda_function_role](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/data-sources/iam_role) | data source | |
| 130 | +| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/4.22.0/docs/data-sources/region) | data source | |
| 131 | + |
| 132 | +## Inputs |
| 133 | + |
| 134 | +| Name | Description | Type | Default | Required | |
| 135 | +|------|-------------|------|---------|:--------:| |
| 136 | +| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | The AWS region to use | `string` | `"us-east-1"` | no | |
| 137 | +| <a name="input_enable_cloudwatch_dashboard"></a> [enable\_cloudwatch\_dashboard](#input\_enable\_cloudwatch\_dashboard) | Enable the CloudWatch Dashboard | `bool` | `false` | no | |
| 138 | +| <a name="input_lambda_function_name"></a> [lambda\_function\_name](#input\_lambda\_function\_name) | The name of the Lambda function | `string` | `"AWSAutoTaggingFunction"` | no | |
| 139 | +| <a name="input_lambda_function_role_name"></a> [lambda\_function\_role\_name](#input\_lambda\_function\_role\_name) | The name of the Lambda function role | `string` | `"AWSAutoTaggingFunctionRole"` | no | |
| 140 | +| <a name="input_resource_tags"></a> [resource\_tags](#input\_resource\_tags) | Tags to apply to resources | `map(string)` | `null` | no | |
| 141 | + |
| 142 | +## Outputs |
| 143 | + |
| 144 | +| Name | Description | |
| 145 | +|------|-------------| |
| 146 | +| <a name="output_completed_region"></a> [completed\_region](#output\_completed\_region) | The region that the Lambda function was created | |
| 147 | +<!-- END_TF_DOCS --> |
0 commit comments