Skip to content

This repository describes how to use AWS Control Tower controls, HashiCorp Terraform, and infrastructure as code (IaC) to implement and administer preventive, detective, and proactive security controls. A control (also known as a guardrail) is a high-level rule that provides ongoing governance for your overall AWS Control Tower environment.

License

Notifications You must be signed in to change notification settings

aws-samples/aws-control-tower-controls-terraform

Deploy and manage AWS Control Tower controls by using Terraform

AWS Prescriptive Guidance

For a complete guide, prerequisites and instructions for using this AWS Prescriptive Guidance pattern, see Deploy and manage AWS Control Tower controls by using Terraform.

Goal

This pattern describes how to use AWS Control Tower controls, HashiCorp Terraform, and infrastructure as code (IaC) to implement and administer preventive, detective, and proactive security controls. A control (also known as a guardrail) is a high-level rule that provides ongoing governance for your overall AWS Control Tower environment. For example, you can use controls to require logging for your AWS accounts and then configure automatic notifications if specific security-related events occur.

AWS Control Tower helps you implement preventive, detective, and proactive controls that govern your AWS resources and monitor compliance across multiple AWS accounts. Each control enforces a single rule. In this pattern, you use a provided IaC template to specify which controls you want to deploy in your environment.

AWS Control Tower controls apply to an entire organizational unit (OU), and the control affects every AWS account within the OU. Therefore, when users perform any action in any account in your landing zone, the action is subject to the controls that govern the OU.

Implementing AWS Control Tower controls helps establish a strong security foundation for your AWS landing zone. By using this pattern to deploy the controls as IaC through Terraform, you can standardize the controls in your landing zone and more efficiently deploy and manage them.

Target Audience

This pattern is recommended for users who have experience with AWS Control Tower, Terraform, and AWS Organizations.

Prerequisites and limitations

Prerequisites

  • Active AWS accounts managed as an organization in AWS Organizations and an AWS Control Tower landing zone. For instructions, see Create an account structure (AWS Well-Architected Labs).

  • AWS Command Line Interface (AWS CLI), installed and configured.

  • An AWS Identity and Access Management (IAM) role in the management account that has permissions to deploy this pattern. For more information about the required permissions and a sample policy, see Least privilege permissions for the IAM role in the Additional information section of this pattern.

  • Permissions to assume the IAM role in the management account.

  • Apply the service control policy (SCP)-based control with the identifier CLOUDFORMATION.PR.1. This SCP must be activated to deploy proactive controls. For instructions, see Disallow management of resource types, modules, and hooks within the AWS CloudFormation registry.

  • Terraform CLI, installed (Terraform documentation).

  • Terraform AWS Provider, configured (Terraform documentation).

  • Terraform backend, configured (Terraform documentation).

Architecture

This section provides a high-level overview of this solution and the architecture established by the sample code. The following diagram shows controls deployed across the various accounts in the OU.

Architecture

AWS Control Tower controls are categorized according to their behavior and their guidance.

There are three primary types of control behaviors:

  1. Preventive controls are designed to prevent actions from occurring. These are implemented with service control policies (SCPs) in AWS Organizations. The status of a preventive control is either enforced or not enabled. Preventive controls are supported in all AWS Regions.

  2. Detective controls are designed to detect specific events when they occur and log the action in CloudTrail. These are implemented with AWS Config rules. The status of a detective control is either clear, in violation, or not enabled. Detective controls apply only in those AWS Regions supported by AWS Control Tower.

  3. Proactive controls scan resources that would be provisioned by AWS CloudFormation and check whether they are compliant with your company policies and objectives. Resources that are not compliant will not be provisioned. These are implemented with AWS CloudFormation hooks. The status of a proactive control is PASS, FAIL, or SKIP.

Control guidance refers to the recommended practice for how to apply each control to your OUs. AWS Control Tower provides three categories of guidance: mandatory, strongly recommended, and elective. The guidance of a control is independent of its behavior. For more information, see Control behavior and guidance.

Tools

AWS services

  • AWS CloudFormation helps you set up AWS resources, provision them quickly and consistently, and manage them throughout their lifecycle across AWS accounts and Regions.

  • AWS Config provides a detailed view of the resources in your AWS account and how they’re configured. It helps you identify how resources are related to one another and how their configurations have changed over time.

  • AWS Control Tower helps you set up and govern an AWS multi-account environment, following prescriptive best practices.

  • AWS Organizations is an account management service that helps you consolidate multiple AWS accounts into an organization that you create and centrally manage.

Other tools

  • HashiCorp Terraform is an open-source infrastructure as code (IaC) tool that helps you use code to provision and manage cloud infrastructure and resources.

Best practices

Control Behavior And Guidance

Controls are categorized according to their behavior and their guidance.

For a full list of preventive, detective and proactive available controls, see the The AWS Control Tower controls library.

Setup

To deploy this solution, you need

Name Version
AWS Control Tower >= 3.0

and the following requirements.

Requirements

Name Version
terraform ~> 1.5
aws ~> 4.67

Providers

Name Version
aws 4.67.0

Modules

No modules.

Resources

Name Type
aws_controltower_control.guardrails resource
aws_organizations_organization.organization data source
aws_organizations_organizational_units.ous_depth_1 data source
aws_organizations_organizational_units.ous_depth_2 data source
aws_organizations_organizational_units.ous_depth_3 data source
aws_organizations_organizational_units.ous_depth_4 data source
aws_organizations_organizational_units.root data source
aws_region.current data source

Inputs

Name Description Type Default Required
controls Configuration of AWS Control Tower Guardrails for the whole organization
list(object({
control_names = list(string)
organizational_unit_ids = list(string)
}))
n/a yes

Outputs

Name Description
ous_id_to_arn_map Map from OU id to OU arn for the whole organization

Controls Configuration File

The following is an example of an updated variables.tfvars file.

controls = [
    {
        control_names = [
            "AWS-GR_ENCRYPTED_VOLUMES",
            ...
        ],
        organizational_unit_ids = ["ou-1111-11111111", "ou-2222-22222222"...],
    },
    {
        control_names = [
            "AWS-GR_SUBNET_AUTO_ASSIGN_PUBLIC_IP_DISABLED",
            ...
        ],
        organizational_unit_ids = ["ou-1111-11111111"...],
    },
]
  1. In the controls section, in the control_names parameter, enter the control API identifier. Each control has a unique API identifier for each Region in which AWS Control Tower is available. To find the control identifier, do the following:

    1. In Tables of control metadata, locate the control you want to enable.

    2. In the Control API identifiers, by Region column, locate the API identifier for the Region in which you are making the API call, such as arn:aws:controltower:us-east-1::control/AWS-GR_AUDIT_BUCKET_ENCRYPTION_ENABLED.

    3. Extract the control identifier from the Regional identifier, such as GR_AUDIT_BUCKET_ENCRYPTION_ENABLED.

  2. In the controls section, in the organizational_unit_ids parameter, enter the ID of the organizational unit where you want to enable the control, such as ou-1111-11111111. Enter the ID in double quotation marks, and separate multiple IDs with commas. For more information about how to retrieve OU IDs, see Viewing the details of an OU.

  3. Save and close the variables.tfvars file. For an example of an updated variables.tfvars file, see the Additional information section of this pattern.

Deployment

In the management account, assume the IAM role that has permissions to deploy the Terraform configuration file. For more information about the permissions required and a sample policy, see Least privilege permissions for the IAM role in the Additional information section. For more information about assuming an IAM role in the AWS CLI, see Use an IAM role in the AWS CLI.

  1. Enter the following command to initialize Terraform.
$ terraform init -upgrade
  1. Enter the following command to preview the changes compared the current state.
$ terraform plan -var-file="variables.tfvars"
  1. Review the configuration changes in the Terraform plan and confirm that you want to implement these changes in the organization.

  2. Enter the following command to deploy the resources.

$ terraform apply -var-file="variables.tfvars"
  1. (optional) Enter the following command to remove the resources deployed by this pattern.
$ terraform destroy -var-file="variables.tfvars"

Least privilege permissions for the IAM role

This APG pattern requires that you assume an IAM role in the management account. Best practice is to assume a role with temporary permissions and limit the permissions according to the principle of least privilege. The following sample policy allows the minimum actions required to enable or disable AWS Control Tower controls.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "controltower:EnableControl",
                "controltower:DisableControl",
                "controltower:GetControlOperation",
                "controltower:ListEnabledControls",
                "organizations:AttachPolicy",
                "organizations:CreatePolicy",
                "organizations:DeletePolicy",
                "organizations:DescribeOrganization",
                "organizations:DetachPolicy",
                "organizations:ListAccounts",
                "organizations:ListAWSServiceAccessForOrganization",
                "organizations:ListChildren",
                "organizations:ListOrganizationalUnitsForParent",
                "organizations:ListParents",
                "organizations:ListPoliciesForTarget",
                "organizations:ListRoots",
                "organizations:UpdatePolicy"
            ],
            "Resource": "*"
        }
    ]
}

Authors

Pattern created by Ivan Girardi (AWS) and Iker Reina Fuente (AWS).

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

This repository describes how to use AWS Control Tower controls, HashiCorp Terraform, and infrastructure as code (IaC) to implement and administer preventive, detective, and proactive security controls. A control (also known as a guardrail) is a high-level rule that provides ongoing governance for your overall AWS Control Tower environment.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages