The problem Infrastructure built by hand
Apex needs compute, a relational database, settlement file storage, messaging, network isolation, secrets, monitoring and backups. Clicking each one together in the console works once. Then environments drift apart, changes cannot be reviewed, nothing can be recreated reliably, mistakes cannot be traced, and nobody holds a full record of what was intended.
Infrastructure as code (IaC) describes infrastructure in machine-readable files that are reviewed, tested, versioned and applied the same way every time. AWS CloudFormation, the AWS CDK and Terraform are common choices; pick one and use it consistently. The skill is understanding the infrastructure model and its consequences, not memorizing syntax.
hclA database that is private, encrypted and backed up (Terraform excerpt)
resource "aws_db_instance" "reconciliation" {
identifier = "apex-reconciliation-${var.environment}"
engine = "postgres"
instance_class = var.db_instance_class
db_subnet_group_name = aws_db_subnet_group.isolated.name
vpc_security_group_ids = [aws_security_group.db.id]
publicly_accessible = false
storage_encrypted = true
kms_key_id = aws_kms_key.data.arn
backup_retention_period = var.backup_retention_days
deletion_protection = true
manage_master_user_password = true # the password lives in Secrets Manager, not in this file
}Three kinds of setting Infrastructure, configuration and secrets
| Kind | Examples | Where it lives |
|---|---|---|
| Infrastructure definition | Network and subnets, compute, database, buckets, queues, IAM roles, security groups, monitoring | IaC repository, reviewed |
| Environment configuration | Connection parameters, feature flags, endpoints, log levels, processing limits | Per-environment configuration |
| Secrets | Database credentials, provider credentials, signing keys, API tokens | Secrets Manager, never Git or images |
Isolation Separate environments, separate accounts
Development, test, staging and production should be separated by accounts or equally strong boundaries, matching the customer’s security model. Different names inside one account do not isolate anything: one over-broad role can still reach production.
The file that knows everything Terraform state: secure, locked and separate
Terraform records what it built in a state file, and that file can contain secrets in plain text, such as generated database passwords. Treat it as sensitive data, and set up four things before the first production apply:
| Practice | How |
|---|---|
| Secure remote state | An S3 bucket with versioning, encryption with a KMS key, all public access blocked, and access limited to the pipeline role and a few named administrators. Never on a laptop |
| Locking | Only one apply at a time: S3 native locking (use_lockfile, Terraform 1.10 and later) or, on older versions, a DynamoDB lock table |
| One state per environment | Separate state for development, staging and production, each in its own account, so a mistake in one cannot touch another |
| Protected production plans | The pipeline creates the plan and saves it; a reviewer approves that exact plan; the apply uses the saved plan file, so nothing changes between review and apply. No production apply from a laptop |
Stay honest Infrastructure drift
An engineer opens a security group in the console to fix a connectivity problem and never updates the code. Months later the environment is recreated from code and the fix disappears, or worse, the open rule stays forever unreviewed. Run drift detection on a schedule (a plan against production is enough) and treat every difference as a change to review.
Practice Define the Apex infrastructure
Practical exercise
Exercise 02: infrastructure for the platform
Document or provision the Apex infrastructure and show a reviewed plan.
- VPC and subnet strategy, application runtime and relational database.
- Settlement file storage, queue and IAM execution roles.
- Secrets management, logging, monitoring and backups.
- Environment separation and a drift detection strategy.
Show a sample drift policy
- Daily: the pipeline runs a plan against production; any difference opens a ticket for the platform owner.
- Emergency console change: allowed only in an incident, recorded, and back in code within two working days.
2 questions
Check your understanding
What you can do now
- Define infrastructure as reviewed code.
- Separate infrastructure, configuration and secrets.
- Isolate environments and detect drift.