deniz.in

Markets

Weather

Loading weather

· via Hacker News – Front Page (native)

Guide runs Terraform apply against AWS's Emulator to catch failures before real infrastructure

A front-page Hacker News guide walks through running Terraform plans and applies against AWS's Emulator, a local stand-in for real AWS APIs, to catch apply-time failures before they reach live infrastructure.

Guide runs Terraform apply against AWS's Emulator to catch failures before real infrastructure

A hands-on guide that reached the Hacker News front page shows how to rehearse Terraform applies against a local stand-in for AWS before touching a real account. The post, published on notes.hatedabamboo.me, uses the Emulator that, according to the author, AWS recently released to emulate actual AWS API endpoints.

The starting point is a familiar failure mode: the plan job runs green, the apply job then dies with an obscure error about a resource that cannot be changed, and the fix means another pull request and another round of waiting.

The plan-versus-apply gap

As the write-up explains, terraform plan works from static declarations — the expected order of application, necessary parameters and configuration values — and cannot make the live API calls that would surface conflicts. It has no way of knowing that a bucket named in the configuration already exists in the account, or that a PostgreSQL RDS upgrade from version 14 to version 18 will fail without an explicit apply-immediately flag. Applying manually to a real environment is the usual workaround, but the author argues this defeats the purpose of an automated workflow.

Existing tools can imitate AWS services in part or in full, the post notes, but they lack authentic knowledge of each service's architecture, and those small differences can cause problems of their own. The Emulator's pitch is essentially to be the AWS API itself, only ephemeral.

A three-stage workflow

The Emulator ships as a self-contained binary or Docker container and can run locally or inside CI. That turns the usual plan-then-apply pipeline into plan, then apply against the emulated AWS to test the plan, then apply against real infrastructure. Jobs get somewhat longer, the author concedes, but when applies run on commits to the main branch after a pull request, the rehearsal step avoids opening a corrective branch just to fix a failure.

Running it locally

The guide builds the image with Docker — noting it weighs about 1.24GB — and starts a container listening on port 9297 with request authentication disabled through the -a off flag. The startup output carries warnings worth heeding: with auth off, the emulator accepts any request, signed or not, and by default it binds to 0.0.0.0, meaning any machine that can reach the port can call it. The emulator also collects usage and error telemetry on by default, with an opt-out via EMULATOR_TELEMETRY=off or the config file. AWS's documentation, cited in the post, recommends memory and swap limits of 2GB for the container. A curl against the /__admin/health endpoint confirms the service is up.

Pointing Terraform at it

On the Terraform side, the provider block needs a handful of accommodations. Because the emulator serves HTTPS with a self-signed certificate, insecure = true skips verification; s3_use_path_style = true puts bucket names in the path since the emulator uses a single endpoint. Skip flags disable credential validation, the metadata API, account ID requests and region validation so nothing calls out to real AWS. Every service in use — the example covers EC2, Lambda, IAM, STS, CloudWatch, logs, events and SNS — gets an endpoints override pointing at the emulator's local address.

With that wiring in place, the author's example stack of 15 resources, spanning a Lambda function, an SNS topic, a CloudWatch alarm, an events rule and the usual VPC pieces, completes both plan and apply cleanly, returning outputs with placeholder-style identifiers such as a zeroed account ID in the ARNs. One rough edge stands out: the running container does not log which API requests it receives, so visibility into what happens under the hood is limited.

Why it matters

The distance between a clean plan and a failing apply is a recurring cost in infrastructure-as-code work — measured in failed pipeline runs, follow-up branches and delayed deployments. An API-faithful emulator moves that discovery earlier: the full apply path, including ordering and parameter validation, can be exercised without cloud spend or blast radius, and the whole thing fits inside CI as an ordinary container. The caveats in the guide — telemetry on by default, loose network and authentication defaults, a 1.24GB image and no request logging — suggest a young tool, but the pattern of rehearsing applies against ephemeral, authentic AWS APIs is one teams stuck in plan-green, apply-red loops will want to watch.

  • #terraform
  • #aws
  • #infrastructure-as-code
  • #devops
  • #testing

Related posts