Terraform and AWS Control Tower for Provisioning a Complete AWS Landing Zone

Ainomugisha Solomon
Stackademic
Published in
4 min readMay 6, 2024

--

Terrform can be used to provision IaC for All Cloud Providers

AWS Control Tower simplifies setting up and governing a new multi-account AWS environment. It automates the setup of a well-architected multi-account AWS environment, including the creation of accounts, roles, and policies. Terraform, an open-source infrastructure as code (IaC) tool, allows you to define and provide data center infrastructure using a declarative configuration language. This article will guide you through using Terraform and AWS Control Tower to provision a complete AWS Landing Zone.

Prerequisites

  • An AWS account with administrative privileges.
  • Terraform installed on your local machine or CI/CD pipeline.
  • AWS CLI configured with appropriate permissions.

Step 1: Setting Up AWS Control Tower

Before integrating Terraform, ensure that AWS Control Tower is set up correctly in your AWS environment. Follow these steps:

  1. Enable AWS Control Tower: Navigate to the AWS Management Console, go to the AWS Control Tower service, and click “Set up”. Follow the prompts to enable AWS Control Tower.
  2. Create a New Account: Once AWS Control Tower is enabled, create a new account that will serve as the management account for your landing zone.
  3. Configure Accounts: After creating the management account, configure other accounts as needed for your landing zone. AWS Control Tower provides a guided experience for setting up accounts, roles, and policies.

Step 2: Installing Terraform

Ensure Terraform is installed on your local machine or within your CI/CD pipeline. You can download Terraform from the official website or install it using package managers like apt for Ubuntu or brew for macOS.

# For Ubuntu
sudo apt-get update && sudo apt-get install terraform
# For macOS
brew install terraform

Step 3: Writing Terraform Configuration

Create a directory for your Terraform project and initialize it with Terraform:

mkdir terraform-aws-control-tower
cd terraform-aws-control-tower
terraform init

Next, create a Terraform configuration file (main.tf) to define the resources you want to manage. For provisioning an AWS Landing Zone with AWS Control Tower, you might start with something simple like creating an S3 bucket:

provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "control_tower_logs" {
bucket = "control-tower-logs-${random_string.suffix.result}"
acl = "log-delivery-write"
tags = {
Name = "ControlTowerLogsBucket"
Environment = "Production"
}
}

This example creates an S3 bucket for storing AWS Control Tower logs. You’ll need to expand this configuration based on your specific requirements.

Step 4: Integrating Terraform with AWS Control Tower

To integrate Terraform with AWS Control Tower, you’ll typically use Terraform to manage resources that support your AWS Control Tower environment, such as S3 buckets for log storage, IAM roles, and policies. However, directly managing AWS Control Tower resources (like accounts, stacks, etc.) with Terraform is not supported due to the nature of AWS Control Tower’s managed services.

Instead, focus on managing the infrastructure that supports your AWS Control Tower environment. For example, you can use Terraform to automate the creation and management of VPCs, subnets, security groups, and other networking components that your AWS Control Tower environment relies on.

The below link gives all the resources to create the VPCs, Subnets etc. Thanks to the awesome documentation by HashiCorp, Makers of Terraform.

https://registry.terraform.io/providers/hashicorp/aws/latest

Step 5: Applying Your Terraform Configuration

After defining your Terraform configuration, apply it to create or update your AWS resources:

terraform apply

Review the changes Terraform plans to make and confirm the action if everything looks correct.

Conclusion

While Terraform and AWS Control Tower can be powerful tools for managing AWS environments, they serve different purposes. Terraform excels at managing infrastructure as code, while AWS Control Tower focuses on setting up and governing a multi-account AWS environment. By combining these tools, you can automate the provisioning and management of your AWS Landing Zone, ensuring consistency and repeatability across your AWS environment.

Remember, direct management of AWS Control Tower resources via Terraform is not supported. Instead, use Terraform to manage the underlying infrastructure that supports your AWS Control Tower environment. This approach allows you to leverage the strengths of both tools, achieving a robust and automated AWS environment.

Lastly, HashiCorp is presumed to be acquired by IBM, as you choose to use Terraform for your enterprise Cloud Architecture, be mindful that it might go Commercial with the takeover by IBM.

Stackademic 🎓

Thank you for reading until the end. Before you go:

--

--