Browse the Repo

file-type-icon.circleci
file-type-icon_ci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-icon_deprecated
file-type-iconauto-update
file-type-iconaws-auth
file-type-iconaws-config
file-type-iconREADME.adoc
file-type-iconcore-concepts.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconaws-organizations-config-rules
file-type-iconaws-organizations
file-type-iconcloudtrail
file-type-iconcross-account-iam-roles
file-type-iconcustom-iam-entity
file-type-iconfail2ban
file-type-iconguardduty-multi-region
file-type-iconguardduty-single-region
file-type-iconiam-groups
file-type-iconiam-policies
file-type-iconiam-user-password-policy
file-type-iconiam-users
file-type-iconip-lockdown
file-type-iconkms-master-key
file-type-iconntp
file-type-iconos-hardening
file-type-iconsaml-iam-roles
file-type-iconssh-grunt-selinux-policy
file-type-iconssh-grunt
file-type-iconssh-iam
file-type-iconssm-healthchecks-iam-permissions
file-type-icontls-cert-private
file-type-icontest
file-type-icon.editorconfig
file-type-icon.gitignore
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.adoc

Browse the Repo

file-type-icon.circleci
file-type-icon_ci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-icon_deprecated
file-type-iconauto-update
file-type-iconaws-auth
file-type-iconaws-config
file-type-iconREADME.adoc
file-type-iconcore-concepts.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconaws-organizations-config-rules
file-type-iconaws-organizations
file-type-iconcloudtrail
file-type-iconcross-account-iam-roles
file-type-iconcustom-iam-entity
file-type-iconfail2ban
file-type-iconguardduty-multi-region
file-type-iconguardduty-single-region
file-type-iconiam-groups
file-type-iconiam-policies
file-type-iconiam-user-password-policy
file-type-iconiam-users
file-type-iconip-lockdown
file-type-iconkms-master-key
file-type-iconntp
file-type-iconos-hardening
file-type-iconsaml-iam-roles
file-type-iconssh-grunt-selinux-policy
file-type-iconssh-grunt
file-type-iconssh-iam
file-type-iconssm-healthchecks-iam-permissions
file-type-icontls-cert-private
file-type-icontest
file-type-icon.editorconfig
file-type-icon.gitignore
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.adoc
AWS Config

AWS Config

Run AWS Config to assess, audit, and evaluate the configurations of your AWS resources, ensuring they meet your compliance requirements.

Code Preview

Preview the Code

mobile file icon

core-concepts.md

down

AWS Config Core Concepts

Background

What is AWS Config?

Config monitors your AWS resources (such as EC2 instances, security groups, EBS volumes, CloudFront Distributions, and a whole lot more) for configuration changes. It tracks these changes over time, and can track whether configurations are in compliance with a standard configuration. If the configuration drifts out of compliance, Config can send a notification. You can view and query Config items in the AWS Config console.

What are Config Rules?

Config rules are expressions of a desired configuration state, written in code and executed as Lambda functions. When a resource configuration changes, AWS Config fires the relevant Lambda functions to evaluate whether the configuration changes the state of compliance with the desired configuration. AWS has developed a set of pre-written rules called AWS Config Managed Rules, but you can also author your own custom rules.

This module enables AWS Config but does not manage or enable any Config Rules.

What resources does this module create?

This module creates the requisite elements to enable AWS Config in a given region. The steps include:

  1. Create a Configuration Recorder.
  2. Create an S3 Bucket and an SNS Topic to be used by AWS Config to deliver configuration snapshots and streams.
  3. Enable the configuration recorder.

To implement these steps, this module creates the following resources:

  • aws_s3_bucket: An S3 bucket used by AWS Config to store configuration items.
  • aws_sns_topic: An SNS topic for notifications from AWS Config.
  • aws_iam_role: An IAM role allowing the Config service to access the supported resources as well as to put S3 objects in the aforementioned bucket and publish notifications to the SNS topic.
  • aws_config_configuration_recorder: A configuration recorder that records resource configurations.
  • aws_config_delivery_channel: A delivery channel with the previously noted S3 bucket and SNS destinations.
  • aws_config_configuration_recorder_status: A resource to enable the configuration recorder.

The module does not create and manage Config Rules or Aggregators.

Note: AWS Config must be enabled on a per-region basis. For a complete view of your AWS resources, use this module within each region that is enabled in your account.

Day-to-day operations

What does a configuration item look like, and how do I view it?

A configuration item is a JSON-encoded description of configuration change to a resource. Configuration items are delivered by AWS Config each time a resource is created, modified, or deleted. The following snippet is an example of a configuration item (edited for brevity):

{
  "configurationItemDiff": {
    "changedProperties": {
      "Configuration.IpPermissions.1": {
        "updatedValue": {
          "fromPort": 22,
          "ipProtocol": "tcp",
          "toPort": 22,
          "ipv4Ranges": [ { ... } ],
          "ipRanges": [ ... ]
        },
        "changeType": "CREATE"
      },
      "Configuration.IpPermissions.2": {
        "previousValue": null,
        "updatedValue": {
          "fromPort": 80,
          "ipProtocol": "tcp",
          "ipv6Ranges": [],
          "prefixListIds": [],
          "toPort": 80,
          "userIdGroupPairs": [],
          "ipv4Ranges": [ { ... } ],
          "ipRanges": [ ... ]
        },
        "changeType": "CREATE"
      },
      "Configuration.IpPermissions.0": {
        "previousValue": {
          "fromPort": 22,
          "ipProtocol": "tcp",
          "toPort": 22,
          "ipv4Ranges": [ { "cidrIp": "0.0.0.0/0" } ],
          "ipRanges": [ "0.0.0.0/0" ]
        },
        "changeType": "DELETE"
      }
    },
    "changeType": "UPDATE"
  },
  "configurationItem": {
    "relationships": [
      {
        "resourceId": "vpc-09a90003b04281036",
        "resourceName": null,
        "resourceType": "AWS::EC2::VPC",
        "name": "Is contained in Vpc"
      }
    ],
    "configuration": {
      "description": "An Example Security Group",
      "groupName": "ExampleGroup",
      ...
      "groupId": "sg-040febc38b5233298",
      ],
      "vpcId": "vpc-09a90003b04281036"
    },
    "configurationItemVersion": "1.3",
    "configurationItemCaptureTime": "2019-08-22T20:35:49.316Z",
    "configurationStateId": 1566506149316,
    "configurationItemStatus": "OK",
    "resourceType": "AWS::EC2::SecurityGroup",
    "resourceId": "sg-040febc38b5233298",
    "ARN": "arn:aws:ec2:us-east-1::security-group/sg-040febc38b5233298",
    "awsRegion": "us-east-1",
    "configurationStateMd5Hash": "",
  },
  "notificationCreationTime": "2019-08-22T20:35:49.815Z",
  "messageType": "ConfigurationItemChangeNotification",
  "recordVersion": "1.3"
}

The example shows crucial information about how the configuration of a security group has changed. It shows the previous ingress rule configuration, new ingress rule configuration, and the relationship of the security group to other AWS resources, along with some metadata and resource attributes.

How does Config work with multiple AWS accounts and multiple regions?

AWS Config must be enabled on a per-region basis. Once enabled, multiple regions (and accounts) can be combined using the data aggregation features. Multi-account/region Config works both with several individual accounts and with AWS Organizations.

This module enables Config for a single region. To enable Config across multiple regions, call this module once for each desired region. This is considerably easier to accomplish with terragrunt.

To consolidate multiple regions and accounts, use the aws_config_configuration_aggregator resource in the desired destination account/region, and use the aws_config_aggregate_authorization resource in the desired source accounts/regions.

For example, if you wish to aggregate regions us-east-1 and eu-west-3 from account 012345678901 to region eu-west-1 in account 123456789012, you would first run terraform apply on account 123456789012 using the following Terraform code:

provider "aws" {
  region = "eu-west-1"
}

resource "aws_config_configuration_aggregator" "destination_account" {
  name = "AggregationExample"

  account_aggregation_source {
    account_ids = ["012345678901"]
    regions     = ["us-east-1", "eu-west-3"]
  }
}

Then you would run terraform apply on account 012345678901 using this Terraform code:

resource "aws_config_aggregate_authorization" "source_account" {
  account_id = "123456789012"
  region     = "eu-west-1"
}

Once authorized, the resources from the source regions will begin to appear in the AWS Config console at the destination.

How can I be alerted by AWS Config when the configuration of a resource changes?

Configuration items (e.g. changes in configuration) are sent to the SNS topic associated with the config recorder. You can subscribe to the SNS topic using the technique of your choice.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?