|
14 | 14 |
|
15 | 15 | GitHub: [StratusGrid/terraform-aws-config-rules](https://github.com/StratusGrid/terraform-aws-config-rules)
|
16 | 16 |
|
| 17 | + Terraform Registry: [StratusGrid/config-rules](https://registry.tf-registry-prod-use1.terraform.io/modules/StratusGrid/config-rules/aws/latest) |
| 18 | + |
17 | 19 | AWS Config rules module to put in standard policies
|
18 | 20 |
|
19 |
| - Note: Config Rule requires an existing Configuration Recorder to be present. |
| 21 | + Note: Config Rule requires an existing Configuration Recorder to be present. There is available a StratusGrid terraform module to provision it [StratusGrid/config-recorder](https://registry.tf-registry-prod-use1.terraform.io/modules/StratusGrid/config-recorder/aws/latest) |
20 | 22 |
|
21 | 23 | ## Example Single Region Configuration:
|
| 24 | + The simplest example deploy the default AWS managed rules we added in the module |
| 25 | + - ROOT_ACCOUNT_MFA_ENABLED |
| 26 | + - IAM_ROOT_ACCESS_KEY_CHECK |
| 27 | + - IAM_USER_MFA_ENABLED |
| 28 | + |
| 29 | + If you want to disable those default rules set `enable_default_aws_managed_rules = false` |
| 30 | + |
22 | 31 | ```hcl
|
23 | 32 | module "aws_config_rules_us_east_1" {
|
24 | 33 | source = "StratusGrid/config-rules/aws"
|
25 | 34 | # StratusGrid recommends pinning every module to a specific version
|
26 | 35 | version = "x.x.x"
|
27 | 36 |
|
28 |
| - include_global_resource_rules = true #only include global resource on one region to prevent duplicate rules |
29 |
| - required_tags_enabled = true |
| 37 | +} |
| 38 | + ``` |
| 39 | + --- |
| 40 | + The second example adds besides the default AWS managed rules added in the example 1 the AWS managed rule required_tags_enabled along with the required parameters |
30 | 41 |
|
| 42 | + ```hcl |
| 43 | + module "aws_config_rules_us_east_1" { |
| 44 | + source = "StratusGrid/config-rules/aws" |
| 45 | + # StratusGrid recommends pinning every module to a specific version |
| 46 | + version = "x.x.x" |
| 47 | +
|
| 48 | + required_tags_enabled = true |
31 | 49 | required_tags = { # Yes, the actual required format is tag#Key and tag#Value
|
32 | 50 | tag1Key = "Provisioner"
|
33 | 51 | tag1Value = "Terraform"
|
34 | 52 | tag2Key = "Customer"
|
35 | 53 | tag3Key = "Application"
|
36 | 54 | }
|
| 55 | +
|
| 56 | +} |
| 57 | + ``` |
| 58 | + --- |
| 59 | + The third example use the aws_managed_rules map with two defined rules. The existing AWS Managed rules can be found [here](https://docs.aws.amazon.com/config/latest/developerguide/managed-rules-by-aws-config.html), and you can map them as shown below. |
| 60 | + |
| 61 | + ```hcl |
| 62 | + module "aws_config_rules_us_east_1" { |
| 63 | + source = "StratusGrid/config-rules/aws" |
| 64 | + # StratusGrid recommends pinning every module to a specific version |
| 65 | + version = "x.x.x" |
| 66 | +
|
| 67 | + aws_managed_rules = { |
| 68 | + access-keys-rotated = { |
| 69 | + description = "Checks if active IAM access keys are rotated (changed) within the number of days specified in maxAccessKeyAge. The rule is NON_COMPLIANT if access keys are not rotated within the specified time period." |
| 70 | + identifier = "ACCESS_KEYS_ROTATED" |
| 71 | + input_parameters = { |
| 72 | + maxAccessKeyAge = "10" |
| 73 | + } |
| 74 | + } |
| 75 | + cloudtrail-security-trail-enabled = { |
| 76 | + description = "Checks that there is at least one AWS CloudTrail trail defined with security best practices. This rule is COMPLIANT if there is at least one trail that meets: https://docs.aws.amazon.com/config/latest/developerguide/cloudtrail-security-trail-enabled.html" |
| 77 | + identifier = "CLOUDTRAIL_SECURITY_TRAIL_ENABLED" |
| 78 | + input_parameters = {} |
| 79 | + } |
| 80 | + } |
37 | 81 | }
|
38 | 82 | ```
|
| 83 | +  |
| 84 | + |
39 | 85 | ---
|
| 86 | + The fourth example shows the creation of a custom rule using [Guard domain-specific language (DSL)](https://docs.aws.amazon.com/cfn-guard/latest/ug/writing-rules.html) |
| 87 | + |
| 88 | + ```hcl |
| 89 | + module "aws_config_rules_us_east_1" { |
| 90 | + source = "StratusGrid/config-rules/aws" |
| 91 | + # StratusGrid recommends pinning every module to a specific version |
| 92 | + version = "x.x.x" |
| 93 | +
|
| 94 | + custom_managed_rules = { |
| 95 | + out-of-scope-ec2-instance-families = { |
| 96 | + description = "Ensure EC2 instance configurations do not belong to out-of-scope families." |
| 97 | + scope = { |
| 98 | + compliance_resource_types = ["AWS::EC2::Instance"] |
| 99 | + } |
| 100 | + source = { |
| 101 | + source_detail = { |
| 102 | + message_type = "ConfigurationItemChangeNotification" |
| 103 | + } |
| 104 | + custom_policy_details = { |
| 105 | + policy_runtime = "guard-2.x.x" |
| 106 | + policy_text = <<POLICY |
| 107 | + rule check_out_of_scope_instance_families when resourceType == "AWS::EC2::Instance" { |
| 108 | + configuration.instanceType != /x1e\.*/ |
| 109 | + configuration.instanceType != /x2i\.*/ |
| 110 | + } |
| 111 | + POLICY |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | +} |
| 117 | + ``` |
| 118 | + |
40 | 119 | ## Example Multi Region Configuration:
|
41 | 120 | ```hcl
|
42 | 121 | module "aws_config_rules_us_east_1" {
|
@@ -131,7 +210,10 @@ module "aws_config_rules_us_west_2" {
|
131 | 210 | |------|-------------|------|---------|:--------:|
|
132 | 211 | | <a name="input_aws_managed_rules"></a> [aws\_managed\_rules](#input\_aws\_managed\_rules) | A list of AWS Managed Rules that should be enabled on the account.<br><br>See the following for a list of possible rules to enable:<br>https://docs.aws.amazon.com/config/latest/developerguide/managed-rules-by-aws-config.html | <pre>map(object({<br> description = string<br> identifier = string<br> input_parameters = any<br> }))</pre> | `{}` | no |
|
133 | 212 | | <a name="input_custom_managed_rules"></a> [custom\_managed\_rules](#input\_custom\_managed\_rules) | A list of AWS Managed Custom Rules that should be enabled on the account.<br><br>Reference<br>https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules.html | `map(any)` | `{}` | no |
|
| 213 | +| <a name="input_enable_default_aws_managed_rules"></a> [enable\_default\_aws\_managed\_rules](#input\_enable\_default\_aws\_managed\_rules) | True/False to add default Config Rules. Default is true | `bool` | `true` | no | |
134 | 214 | | <a name="input_input_tags"></a> [input\_tags](#input\_input\_tags) | Map of tags to apply to resources | `map(any)` | <pre>{<br> "Developer": "StratusGrid",<br> "Provisioner": "Terraform"<br>}</pre> | no |
|
| 215 | +| <a name="input_required_tags"></a> [required\_tags](#input\_required\_tags) | Map of tag keys, and optionally values, that are required. | `map(any)` | `{}` | no | |
| 216 | +| <a name="input_required_tags_enabled"></a> [required\_tags\_enabled](#input\_required\_tags\_enabled) | True/False to add RequiredTags to Config. Default is false | `bool` | `false` | no | |
135 | 217 |
|
136 | 218 | ## Outputs
|
137 | 219 |
|
|
0 commit comments