Skip to content

AWS Config Terraform module

Enables AWS Config and adds managed config rules with good defaults.

Supported AWS Config Rules

ACM

  • acm-certificate-expiration-check: Ensure ACM Certificates in your account are marked for expiration within the specified number of days.

AMI

  • approved-amis-by-tag: Checks whether running instances are using specified AMIs.

CloudTrail

  • cloudtrail-enabled: Ensure CloudTrail is enabled.
  • cloud-trail-encryption-enabled: Ensure CloudTrail is configured to use server side encryption (SSE) with AWS KMS or CMK encryption.
  • cloud-trail-log-file-validation-enabled: Checks whether AWS CloudTrail creates a signed digest file with logs.
  • multi-region-cloud-trail-enabled: Ensure that there is at least one multi-region AWS CloudTrail enabled.
  • cloud-trail-cloud-watch-logs-enabled: Checks whether AWS CloudTrail trails are configured to send logs to Amazon CloudWatch logs.

CloudWatch Logs

  • cloudwatch-log-group-encrypted: Ensure that CloudWatch Logs are encrypted.
  • cw-loggroup-retention-period-check: Checks whether Amazon CloudWatch LogGroup retention period is set to specific number of days.

DynamoDB

  • dynamodb-table-encryption-enabled: Checks if the Amazon DynamoDB tables are encrypted and checks their status. The rule is COMPLIANT if the status is enabled or enabling. Not supported in all regions
  • dynamodb-table-encrypted-kms: Checks if Amazon DynamoDB table is encrypted with AWS Key Management Service (KMS)

EC2

  • ec2-encrypted-volumes: Evaluates whether EBS volumes that are in an attached state are encrypted.
  • ec2-volume-inuse-check: Checks whether EBS volumes are attached to EC2 instances.
  • ebs-snapshot-public-restorable-check: Checks whether Amazon Elastic Block Store snapshots are not publicly restorable.
  • ebs-optimized-instance: Checks if EBS optimization is enabled for your EC2 instances that can be EBS-optimized.

ECR

  • ecr-private-image-scanning-enabled: Checks if a private Amazon Elastic Container Registry (ECR) repository has image scanning enabled. Not supported in all regions
  • ecr-private-lifecycle-policy-configured: Checks if a private Amazon Elastic Container Registry (ECR) repository has at least one lifecycle policy configured. Not supported in all regions

ECS

  • ecs-awsvpc-networking-enabled: Checks if the networking mode for active ECSTaskDefinitions is set to ‘awsvpc’. Not supported in all regions
  • ecs-containers-nonprivileged: Checks if the privileged parameter in the container definition of ECSTaskDefinitions is set to ‘true’. Not supported in all regions
  • ecs-containers-readonly-access: Checks if Amazon Elastic Container Service (Amazon ECS) Containers only have read-only access to its root filesystems. Not supported in all regions
  • ecs-no-environment-secrets: Checks if secrets are passed as container environment variables. Not supported in all regions

EFS

  • efs-encrypted-check: Checks if Amazon Elastic File System is configured to encrypt file data using AWS Key Management Service.

ELB

  • elb-logging-enabled: Checks if the Application Load Balancer and the Classic Load Balancer have logging enabled.
  • elb-deletion-protection-enabled: Checks if Elastic Load Balancing has deletion protection enabled.

VPC

  • eip-attached: Checks whether all EIP addresses that are allocated to a VPC are attached to EC2 or in-use ENIs.
  • instances-in-vpc: Ensure all EC2 instances run in a VPC.
  • vpc-default-security-group-closed: Checks that the default security group of any Amazon Virtual Private Cloud (VPC) does not allow inbound or outbound traffic.
  • vpc-sg-open-only-to-authorized-ports: Checks whether any security groups with inbound 0.0.0.0/0 have TCP or UDP ports accessible.
  • restricted-common-ports: Checks if the security groups in use do not allow unrestricted incoming TCP traffic to the specified ports.

GuardDuty

  • guardduty-enabled-centralized: Checks whether Amazon GuardDuty is enabled in your AWS account and region.

IAM

  • iam-password-policy: Ensure the account password policy for IAM users meets the specified requirements.
  • iam-user-no-policies-check: Ensure that none of your IAM users have policies attached; IAM users must inherit permissions from IAM groups or roles.
  • iam-group-has-users-check: Checks whether IAM groups have at least one IAM user.
  • root-account-mfa-enabled: Ensure root AWS account has MFA enabled.
  • iam-root-access-key: Ensure root AWS account does not have Access Keys.
  • mfa_enabled_for_iam_console_access: Checks whether AWS Multi-Factor Authentication (MFA) is enabled for all AWS Identity and Access Management (IAM) users that use a console password.
  • iam-policy-no-statements-with-admin-access: Checks the IAM policies that you create for Allow statements that grant permissions to all actions on all resources.
  • iam-policy-no-statements-with-full-access: Checks if AWS Identity and Access Management (IAM) policies grant permissions to all actions on individual AWS resources. Not supported in all regions

Misc Security

  • restricted-ssh: Checks whether security groups that are in use disallow unrestricted incoming SSH traffic.
  • access_keys_rotated: Checks if the active access keys are rotated within the number of days specified in maxAccessKeyAge.
  • cmk_backing_key_rotation_enabled: Checks if automatic key rotation is enabled for every AWS Key Management Service customer managed symmetric encryption key.
  • nacl-no-unrestricted-ssh-rdp: Checks if default ports for SSH/RDP ingress traffic for network access control lists (NACLs) is unrestricted. Not supported in all regions
  • internet-gateway-authorized-vpc-only: Checks that Internet gateways (IGWs) are only attached to an authorized Amazon Virtual Private Cloud (VPCs).

Tagging

  • required-tags: Checks if resources are deployed with configured tags.

RDS

  • rds-instance-public-access-check: Checks whether the Amazon Relational Database Service (RDS) instances are not publicly accessible.
  • rds-snapshots-public-prohibited: Checks if Amazon Relational Database Service (Amazon RDS) snapshots are public.
  • rds-storage-encrypted: Checks whether storage encryption is enabled for your RDS DB instances.
  • rds-snapshot-encrypted: Checks whether Amazon Relational Database Service (Amazon RDS) DB snapshots are encrypted.
  • rds-cluster-deletion-protection-enabled: Checks if an Amazon Relational Database Service (Amazon RDS) cluster has deletion protection enabled. Not supported in all regions
  • db-instance-backup-enabled: Checks if RDS DB instances have backups enabled.

S3

  • s3-bucket-public-write-prohibited: Checks that your S3 buckets do not allow public write access.
  • s3-bucket-public-read-prohibited: Checks if your Amazon S3 buckets do not allow public read access.
  • s3-bucket-ssl-requests-only: Checks whether S3 buckets have policies that require requests to use Secure Socket Layer (SSL).
  • s3-bucket-level-public-access-prohibited: Checks if Amazon Simple Storage Service (Amazon S3) buckets are publicly accessible. Not supported in all regions
  • s3-bucket-acl-prohibited: Checks if Amazon Simple Storage Service (Amazon S3) Buckets allow user permissions through access control lists (ACLs). Not supported in all regions
  • s3-bucket-server-side-encryption-enabled: Checks if S3 bucket either has the S3 default encryption enabled or that S3 policy explicitly denies put-object requests without SSE that uses AES-256 or AWS KMS.

Usage

Note: This module sets up AWS IAM Roles and Policies, which are globally namespaced. If you plan to have multiple instances of AWS Config, make sure they have unique values for config_name.

Note: If you use this module in multiple regions, be sure to disable duplicate checks and global resource types.

module"aws_config" {
source="trussworks/config/aws"config_name="my-aws-config"config_logs_bucket="my-aws-logs"
}

Requirements

NameVersion
terraform>= 1.0
aws>= 2.70

Providers

NameVersion
aws>= 2.70

Modules

No modules.

Resources

NameType
aws_config_config_rule.access_keys_rotatedresource
aws_config_config_rule.acm-certificate-expiration-checkresource
aws_config_config_rule.approved-amis-by-tagresource
aws_config_config_rule.cloud-trail-cloud-watch-logs-enabledresource
aws_config_config_rule.cloud-trail-encryption-enabledresource
aws_config_config_rule.cloud-trail-log-file-validation-enabledresource
aws_config_config_rule.cloudtrail-enabledresource
aws_config_config_rule.cloudwatch_log_group_encryptedresource
aws_config_config_rule.cmk_backing_key_rotation_enabledresource
aws_config_config_rule.cw-loggroup-retention-period-checkresource
aws_config_config_rule.db-instance-backup-enabledresource
aws_config_config_rule.dynamodb-table-encrypted-kmsresource
aws_config_config_rule.dynamodb-table-encryption-enabledresource
aws_config_config_rule.ebs-optimized-instanceresource
aws_config_config_rule.ebs_snapshot_public_restorableresource
aws_config_config_rule.ec2-encrypted-volumesresource
aws_config_config_rule.ec2-imdsv2-checkresource
aws_config_config_rule.ec2-volume-inuse-checkresource
aws_config_config_rule.ecr-private-image-scanning-enabledresource
aws_config_config_rule.ecr-private-lifecycle-policy-configuredresource
aws_config_config_rule.ecs-awsvpc-networking-enabledresource
aws_config_config_rule.ecs-containers-nonprivilegedresource
aws_config_config_rule.ecs-containers-readonly-accessresource
aws_config_config_rule.ecs-no-environment-secretsresource
aws_config_config_rule.efs-encrypted-checkresource
aws_config_config_rule.eip_attachedresource
aws_config_config_rule.elb-deletion-protection-enabledresource
aws_config_config_rule.elb-logging-enabledresource
aws_config_config_rule.guardduty-enabled-centralizedresource
aws_config_config_rule.iam-group-has-users-checkresource
aws_config_config_rule.iam-password-policyresource
aws_config_config_rule.iam-policy-no-statements-with-admin-accessresource
aws_config_config_rule.iam-policy-no-statements-with-full-accessresource
aws_config_config_rule.iam-user-no-policies-checkresource
aws_config_config_rule.iam_root_access_keyresource
aws_config_config_rule.internet-gateway-authorized-vpc-onlyresource
aws_config_config_rule.mfa_enabled_for_iam_console_accessresource
aws_config_config_rule.multi-region-cloud-trail-enabledresource
aws_config_config_rule.nacl-no-unrestricted-ssh-rdpresource
aws_config_config_rule.rds-cluster-deletion-protection-enabledresource
aws_config_config_rule.rds-instance-public-access-checkresource
aws_config_config_rule.rds-snapshot-encryptedresource
aws_config_config_rule.rds-snapshots-public-prohibitedresource
aws_config_config_rule.rds-storage-encryptedresource
aws_config_config_rule.required-tagsresource
aws_config_config_rule.restricted-common-portsresource
aws_config_config_rule.restricted_sshresource
aws_config_config_rule.root-account-mfa-enabledresource
aws_config_config_rule.s3-bucket-acl-prohibitedresource
aws_config_config_rule.s3-bucket-level-public-access-prohibitedresource
aws_config_config_rule.s3-bucket-public-read-prohibitedresource
aws_config_config_rule.s3-bucket-public-write-prohibitedresource
aws_config_config_rule.s3_bucket_ssl_requests_onlyresource
aws_config_config_rule.vpc-sg-open-only-to-authorized-portsresource
aws_config_config_rule.vpc_default_security_group_closedresource
aws_config_configuration_aggregator.organizationresource
aws_config_configuration_recorder.mainresource
aws_config_configuration_recorder_status.mainresource
aws_config_delivery_channel.mainresource
aws_iam_policy.aws-config-policyresource
aws_iam_role.aggregatorresource
aws_iam_role.mainresource
aws_iam_role_policy_attachment.aggregatorresource
aws_iam_role_policy_attachment.aws-config-policyresource
aws_iam_role_policy_attachment.managed-policyresource
aws_caller_identity.currentdata source
aws_iam_policy_document.aws-config-role-policydata source
aws_iam_policy_document.aws_config_aggregator_role_policydata source
aws_iam_policy_document.aws_config_policydata source
aws_partition.currentdata source

Inputs

NameDescriptionTypeDefaultRequired
access_key_max_ageMaximum number of days without rotation.number90no
acm_days_to_expirationSpecify the number of days before the rule flags the ACM Certificate as noncompliant.number14no
aggregate_organizationAggregate compliance data by organizationboolfalseno
ami_required_tag_key_valueTag/s key and value which AMI has to have in order to be compliant: Example: key1:value1,key2:value2string""no
authorized_vpc_idsComma-separated list of the authorized VPC IDs with attached IGWs. If parameter is not provided all attached IGWs will be NON_COMPLIANT.string"example,CSV"no
check_access_keys_rotatedEnable access-keys-rotated rulebooltrueno
check_acm_certificate_expiration_checkEnable acm-certificate-expiration-check rulebooltrueno
check_approved_amis_by_tagEnable approved-amis-by-tag ruleboolfalseno
check_cloud_trail_encryptionEnable cloud-trail-encryption-enabled ruleboolfalseno
check_cloud_trail_log_file_validationEnable cloud-trail-log-file-validation-enabled ruleboolfalseno
check_cloudtrail_enabledEnable cloudtrail-enabled rulebooltrueno
check_cloudwatch_log_group_encryptedEnable cloudwatch-log-group-encryption rulebooltrueno
check_cmk_backing_key_rotatedEnable cmk_backing_key_rotation_enabled rulebooltrueno
check_cw_loggroup_retention_periodEnable cloudwatch-log-group-retention-period-check ruleboolfalseno
check_db_instance_backup_enabledEnable db-instance-backup-enabled ruleboolfalseno
check_dynamodb_table_encrypted_kmsEnable dynamodb-table-encrypted-kms ruleboolfalseno
check_dynamodb_table_encryption_enabledEnable checkdynamodb-table-encryption-enabled rulebooltrueno
check_ebs_optimized_instanceEnable ebs-optimized-instance-check ruleboolfalseno
check_ebs_snapshot_public_restorableEnable ebs-snapshot-public-restorable rulebooltrueno
check_ec2_encrypted_volumesEnable ec2-encrypted-volumes rulebooltrueno
check_ec2_imdsv2Enable IMDSv2 ruleboolfalseno
check_ec2_volume_inuse_checkEnable ec2-volume-inuse-check rulebooltrueno
check_ecr_private_image_scanning_enabledEnable ecr-private-image-scanning-enabled rulebooltrueno
check_ecr_private_lifecycle_policy_configuredEnable ecr-private-lifecycle-policy-configured rulebooltrueno
check_ecs_awsvpc_networking_enabledEnable ecs-awsvpc-networking-enabled rulebooltrueno
check_ecs_containers_nonprivilegedEnable ecs-containers-nonprivileged rulebooltrueno
check_ecs_containers_readonly_accessEnable ecs-containers-readonly-access rulebooltrueno
check_ecs_no_environment_secretsEnable ecs-no-environment-secrets ruleboolfalseno
check_eip_attachedEnable eip-attached ruleboolfalseno
check_elb_deletion_protection_enabledEnable elb-deletion-protection-enabled rulebooltrueno
check_elb_logging_enabledEnable elb-logging-enabled ruleboolfalseno
check_guard_dutyEnable guardduty-enabled-centralized ruleboolfalseno
check_iam_group_has_users_checkEnable iam-group-has-users-check rulebooltrueno
check_iam_password_policyEnable iam-password-policy rulebooltrueno
check_iam_policy_no_statements_with_admin_accessEnable iam-policy-no-statements-with-admin-access rulebooltrueno
check_iam_policy_no_statements_with_full_accessEnable iam-policy-no-statements-with-full-access rulebooltrueno
check_iam_root_access_keyEnable iam-root-access-key rulebooltrueno
check_iam_user_no_policies_checkEnable iam-user-no-policies-check rulebooltrueno
check_internet_gateway_authorized_vpc_onlyEnable internet-gateway-authorized-vpc-only ruleboolfalseno
check_mfa_enabled_for_iam_console_accessEnable mfa-enabled-for-iam-console-access rulebooltrueno
check_multi_region_cloud_trailEnable multi-region-cloud-trail-enabled ruleboolfalseno
check_nacl_no_unrestricted_ssh_rdpEnable nacl-no-unrestricted-ssh-rdp rulebooltrueno
check_rds_cluster_deletion_protection_enabledEnable rds-cluster-deletion-protection-enabled rulebooltrueno
check_rds_public_accessEnable rds-instance-public-access-check ruleboolfalseno
check_rds_snapshot_encryptedEnable rds-snapshot-encrypted rulebooltrueno
check_rds_snapshots_public_prohibitedEnable rds-snapshots-public-prohibited rulebooltrueno
check_rds_storage_encryptedEnable rds-storage-encrypted rulebooltrueno
check_required_tagsEnable required-tags ruleboolfalseno
check_restricted_common_portsEnable restricted-common-ports-checkboolfalseno
check_restricted_sshEnable restricted-ssh rulebooltrueno
check_root_account_mfa_enabledEnable root-account-mfa-enabled ruleboolfalseno
check_s3_bucket_acl_prohibitedEnable s3-bucket-acl-prohibited rulebooltrueno
check_s3_bucket_level_public_access_prohibitedEnable s3-bucket-level-public-access-prohibited ruleboolfalseno
check_s3_bucket_public_read_prohibitedEnable s3-bucket-public-read-prohibited ruleboolfalseno
check_s3_bucket_public_write_prohibitedEnable s3-bucket-public-write-prohibited rulebooltrueno
check_s3_bucket_ssl_requests_onlyEnable s3-bucket-ssl-requests-only rulebooltrueno
check_vpc_default_security_group_closedEnable vpc-default-security-group-closed rulebooltrueno
check_vpc_sg_open_only_to_authorized_portsEnable vpc-sg-open-only-to-authorized-ports ruleboolfalseno
cloud_trail_cloud_watch_logs_enabledEnable cloud_trail_cloud_watch_logs_enabled rulebooltrueno
config_aggregator_nameThe name of the aggregator.string"organization"no
config_delivery_frequencyThe frequency with which AWS Config delivers configuration snapshots.string"Six_Hours"no
config_logs_bucketThe S3 bucket for AWS Config logs. If you have set enable_config_recorder to false then this can be an empty string.stringn/ayes
config_logs_bucket_kms_key_arnThe ARN of the AWS KMS key used to encrypt objects delivered by AWS Config. Must belong to the same Region as the destination S3 bucket.stringnullno
config_logs_prefixThe S3 prefix for AWS Config logs.string"config"no
config_max_execution_frequencyThe maximum frequency with which AWS Config runs evaluations for a rule.string"TwentyFour_Hours"no
config_nameThe name of the AWS Config instance.string"aws-config"no
config_recording_frequencyDefault recording frequency for the AWS Configstring"CONTINUOUS"no
config_recording_frequency_overridesSpecific overrides of the recording frequency for the AWS Configset(object({ description = optional(string, null) resource_types = list(string) recording_frequency = string }))[]no
config_role_permissions_boundaryThe ARN of the permissions boundary to apply to IAM roles created for AWS Configstringnullno
config_sns_topic_arnAn SNS topic to stream configuration changes and notifications to.stringnullno
cw_loggroup_retention_periodRetention period for cloudwatch logs in number of daysnumber3653no
dynamodb_arn_encryption_listComma separated list of AWS KMS key ARNs allowed for encrypting Amazon DynamoDB Tables.string"example,CSV"no
ecs_no_environment_secretsComma-separated list of key names to search for in the environment variables of container definitions within Task Definitions. Extra spaces will be removed.string"example,CSV"no
elb_logging_s3_bucketsComma-separated list of Amazon S3 bucket names for Amazon ELB to deliver the log files.string"example,CSV"no
enable_config_recorderEnables configuring the AWS Config recorder resources in this module.booltrueno
enable_efs_encrypted_checkEnable efs-encrypted-check ruleboolfalseno
enable_multi_account_logsEnable sending of logs and snapshots from different Config accounts / regions into a single bucketboolfalseno
exclude_permission_boundaryBoolean to exclude the evaluation of IAM policies used as permissions boundaries. If set to 'true', the rule will not include permissions boundaries in the evaluation. Otherwise, all IAM policies in scope are evaluated when set to 'false.'boolfalseno
expected_delivery_window_ageMaximum age in hours of the most recent delivery to CloudWatch logs that satisfies compliance.number12no
include_global_resource_typesSpecifies whether AWS Config includes all supported types of global resources with the resources that it records.booltrueno
kms_key_idAmazon Resource Name (ARN) of the KMS key that is used to encrypt the EFS file system.string"example,CSV"no
password_max_ageNumber of days before password expiration.number90no
password_min_lengthPassword minimum length.number14no
password_require_lowercaseRequire at least one lowercase character in password.booltrueno
password_require_numbersRequire at least one number in password.booltrueno
password_require_symbolsRequire at least one symbol in password.booltrueno
password_require_uppercaseRequire at least one uppercase character in password.booltrueno
password_reuse_preventionNumber of passwords before allowing reuse.number24no
required_tagsA map of required resource tags. Format is tagNKey, tagNValue, where N is int. Values are optional.map(string){}no
required_tags_resource_typesResource types to check for tags.list(string)[]no
resource_typesA list that specifies the types of AWS resources for which AWS Config records configuration changes (for example, AWS::EC2::Instance or AWS::CloudTrail::Trail). See relevant part of AWS Docs for available types.list(string)[]no
s3_bucket_public_access_prohibited_exclusionComma-separated list of known allowed public Amazon S3 bucket names.string"example,CSV"no
sns_kms_key_idThe ARN of the KMS key used to encrypt the Amazon SNS topic.stringnullno
tagsTags to apply to AWS Config resourcesmap(string){}no
vpc_sg_authorized_portsObject with values as Comma-separated list of ports authorized to be open to 0.0.0.0/0. Ranges are defined by dash. example, '443,1020-1025'object({ authorizedTcpPorts = optional(string, null) authorizedUdpPorts = optional(string, null) }){}no

Outputs

NameDescription
aws_config_role_arnThe ARN of the AWS config role.
aws_config_role_nameThe name of the IAM role used by AWS config
required_tags_rule_arnThe ARN of the required-tags config rule.

Upgrade Paths

Upgrading from 2.3.0 to 2.4.x

Version 2.4.0 changed how AWS Config IAM polices would be attached to IAM roles. When applying the upgrade, you will likely see a race condition resulting in the following error

Error: Provider produced inconsistent result after apply

A second terraform apply should resolve the issue.

Developer Setup

Install dependencies (macOS)

brew install pre-commit go terraform terraform-docs

About

Enables AWS Config and adds managed config rules with good defaults.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages