The first AWS account is usually built by clicking through the console, with a promise to "script it later". Six months on, nobody can say why a Prod security group is open to the internet, NonProd has settings nobody chose, and the person who clicked has moved to another project.
Write the infrastructure as code before you create it. On day 1 the baseline is small: a few accounts, some guardrails and a trail. Every week you wait, more of it exists only in the console. You can import it later, for example with CloudFormation's IaC generator, but then you are describing what someone clicked, not what you meant to build.
The same advice applies in Azure. See Do you know how to create Azure resources?
Some things have to exist before a pipeline can run:
northwind-deploy, trusted through OIDC and not a stored keyWrite these steps in a runbook. Everything after them is code: the OUs and accounts, the northwind-deploy role in each account, service control policies, SSO permission sets, the organization trail and the alerts.
| Tool | Choose it when |
|---|---|
| Terraform or OpenTofu | You also run Azure and want one language and one pipeline for both clouds. Bicep only deploys to Azure |
| CloudFormation | You want the AWS-native option with no state file to host. StackSets can deploy a baseline to every account in an OU, including accounts you add later |
| AWS CDK | Your developers want to write C# or TypeScript. It generates CloudFormation |
With Terraform, you host the state file yourself. Put it in an S3 bucket with versioning on, in an account that workload admins cannot reach, such as Log/Security, and use the built-in lock file. That account does not exist on day 1. Start with local state, then move it with terraform init -migrate-state once your code has created the account. The older DynamoDB lock table is deprecated.
terraform {backend "s3" {bucket = "northwind-terraform-state"key = "org/baseline.tfstate"region = "ap-southeast-2"use_lockfile = true}}
Code only stays true if it is the only way to change things.
northwind-deploy, and only from a protected branch after a pull request is approvedNorthwind's audit log bucket was set up in the console in March. In October an auditor asks why it keeps logs for 3 months when the policy says 12. Nobody knows whether that was a decision or a slip.
❌ Figure: Bad example - Bad example - The console keeps no record of what you intended
The bucket is 40 lines of Terraform. git blame shows who set the retention, when, and which pull request approved it.
✅ Figure: Good example - Good example - The history of every setting is in source control
During an incident, someone will fix something in the console. That is fine, as long as it does not stay that way.
terraform plan on a schedule and alert when it shows changesCode also makes cleaning up safe, because deleting a stack removes everything in it. See Do you monitor traffic and cull unused AWS resources?