Testing Terraform with AWS Emulator
The post frames a familiar Terraform problem: plan passes, then apply fails on an obscure error. The author says plan cannot emulate every real API call, so it cannot know a bucket named "my-bucket-asdasdasd" already exists or that an RDS PostgreSQL instance is being upgraded from version 14 to 18 without an explicit apply-immediately flag. Existing tools that emulate AWS services partially or fully lack knowledge of the actual service architecture, the author writes, while AWS Emulator is closest to the real API because it is the same API but ephemeral. The author describes AWS Emulator as a self-contained binary or Docker container usable locally or in CI, changing the workflow to plan, apply against mock AWS infrastructure to test the plan, then apply on actual AWS. Jobs get slightly longer, but the author says this avoids creating a new branch just to fix an apply failure on main. The walkthrough builds the image with Docker, which the author notes is about 1.24GB, and runs it on port 9297 with the -a off flag. Logs show the emulator starting, an endpoint URL of https://127.0.0.1:9297, a health check at /__admin/health, and a warning that it listens on 0.0.0.0 rather than loopback. The emulator collects usage and error telemetry by default, which can be disabled with EMULATOR_TELEMETRY=off or a telemetry setting in the config file.
The post shows developers can run Terraform apply against a local AWS API emulator to catch apply-time errors before touching real infrastructure.