Terraform against AWS Emulator: what the emulated apply catches, and the five failures only your real account can show you

An emulator validates the shape of the request: it catches the two-letter DynamoDB table name that plan lets through. It does not see names that already…

2026-11-23

This note on video: The emulator said yes. The account said no. Terraform on an AWS emulator (0:25)

The short answer: an emulator validates the shape of the request. It does not see quotas, capacity, names that already exist, IAM or the previous state of the account, because none of that lives in the API; it lives in your account. A terraform apply against AWS Emulator catches the malformed parameter that plan lets through, and that alone is worth it. What keeps failing in the real account is a different list, and this note is that list.

I just came out of the Hacker News thread from 11/22 about [testing Terraform with AWS Emulator](https://notes.hatedabamboo.me/terraform-tests-with-aws-emulator/) (78 points, 14 comments) and re-read the emulator docs with the question I actually care about: if I put this in the pipeline tomorrow, which red apply does it save me, and which one still gets through?

The pipeline that started the thread

On 11/12 Kirill Solovei published a GitHub Actions pipeline that installs the emulator, runs terraform plan and terraform apply against https://127.0.0.1:9297, and only if that passes applies against the real account. The test architecture is 15 resources: a VPC, a security group, a Lambda, CloudWatch, an EventBridge rule and an SNS topic. The emulated apply finished with 15 added, 0 changed, 0 destroyed and the whole pipeline took 1m25s.

The part that convinced me is the failure case he added on purpose: a DynamoDB table named ab. The plan accepts it, because the provider does not validate the name length. The emulator rejects it with the same error AWS would:

Error: creating AWS DynamoDB Table (ab): operation error DynamoDB: CreateTable,
https response error StatusCode: 400, api error ValidationException:
1 validation error detected: Value 'ab' at 'tableName' failed to satisfy constraint:
Member must have length greater than or equal to 3

That is exactly what an emulator can do well: the [fidelity page](https://docs.aws.amazon.com/emulator/latest/userguide/fidelity.html) says that for every operation it implements it aims for the same results as AWS for valid calls and the same errors for invalid ones, and that anything not implemented returns HTTP 501 with NotImplemented, so the test fails right away instead of passing quietly.

What the emulated apply catches, and why I would still add it

Before the list of what it does not see, what it does see, because it is more than plan sees. terraform plan validates syntax, resolves references and refreshes the state of what it already manages; I already wrote about the six things it does not verify. The emulated apply adds a layer: it actually executes every Create against a service that knows the API's validation rules.

Two things about the emulator itself worth having on hand before deciding. According to its [repository](https://github.com/aws/aws-emulator), state is in-memory, it serves HTTPS on 127.0.0.1:9297 with a self-signed certificate, the license is CC0 1.0 and they do not accept pull requests: AI agents keep it up to date. And the [versions page](https://docs.aws.amazon.com/emulator/latest/userguide/versioning.html) warns that fidelity fixes can change your test results between versions, and explains how to install a specific one. Which to me means: a fixed version in the pipeline, upgrades treated as one more change.

1. Names that already exist

It was the first objection in the thread, and the simplest: the emulator cannot know that a bucket called my-bucket-asdasdasd already exists, and since S3 names are global, what matters is not what you have but what anyone has. The same goes for IAM role names (unique per account) and CloudWatch log groups (unique per account and region). The emulator starts empty, so every name is free.

What the real apply hits: BucketAlreadyExists or BucketAlreadyOwnedByYou, EntityAlreadyExists for the role, ResourceAlreadyExistsException for the log group. What you can ask beforehand, with the read-only credential:

# S3: 200 if it is yours, 403 if it is someone else's, 404 if it is free
aws s3api head-bucket --bucket "$BUCKET"
# IAM: NoSuchEntity is the good answer
aws iam get-role --role-name "$ROLE"
# CloudWatch Logs: an empty list is the good answer
aws logs describe-log-groups --log-group-name-prefix "/aws/lambda/$FN" --query "logGroups[].logGroupName"

2. Quotas and capacity

Quotas are not an attribute of any resource, so there is no request that validates them. The emulator accepts the sixth Elastic IP; the real account, by default, does not: the [VPC quotas table](https://docs.aws.amazon.com/vpc/latest/userguide/amazon-vpc-limits.html) lists 5 Elastic IPs per Region as the starting value, adjustable. On-demand vCPUs work the same way: the quota is read from Service Quotas, not from EC2.

Capacity is worse, because it cannot even be read beforehand. Having quota for eight vCPUs does not mean there is a free host for that type in that zone right now. The [EC2 troubleshooting guide](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/troubleshooting-launch.html) describes InsufficientInstanceCapacity as the error when launching or restarting an instance and AWS does not have enough on-demand capacity, and the way out it proposes is the usual one: wait and retry, ask for fewer instances, change the type or launch without pinning a zone. No emulator will reproduce that, and it is not a flaw: it is not API information.

# Standard on-demand vCPUs (A, C, D, H, I, M, R, T, Z) in the region
aws service-quotas get-service-quota --service-code ec2 --quota-code L-1216C47A --query "Quota.Value"
# Elastic IPs: quota and usage, to compare with what the plan adds
aws service-quotas list-service-quotas --service-code ec2 --query "Quotas[?QuotaName=='EC2-VPC Elastic IPs'].Value"
aws ec2 describe-addresses --query "length(Addresses)"

3. IAM, SCPs and resource policies

No interpretation needed here: the [emulator security page](https://docs.aws.amazon.com/emulator/latest/userguide/security.html) says not to use it to test IAM policies and permissions boundaries, resource-based policies such as bucket policies, KMS key policies, access across accounts or Regions, or any other security control. One commenter in the thread summed it up from the other side: they have a fair amount of Terraform testing involving IAM to make sure permissions come out right, and the emulator does not emulate it at all.

What the real apply hits: AccessDenied halfway through, with half the resources already created. And an organization SCP does not even show up in the policy simulator; it only shows up in the attempt.

# Who am I and what can I do, according to IAM (SCPs not included)
aws sts get-caller-identity
aws iam simulate-principal-policy --policy-source-arn "$ROLE_ARN" \
  --action-names s3:CreateBucket dynamodb:CreateTable lambda:CreateFunction \
  --query "EvaluationResults[].{a:EvalActionName,d:EvalDecision}"

4. The previous state: drift and what was never in the state

The objection I found most interesting came from lmz: how does this replicate the current state from the live environment? Would it not always be a from-scratch creation? And the author confirmed it: yes, every pipeline run starts from scratch, the emulator state is in-memory only. That means the emulated apply tests a world where everything is a create. It does not test an update on a resource someone touched by hand, it does not test a replace that destroys first and fails afterwards, it does not test drift.

Nor does it see what was never in the state: the load balancer another team created from the console, the subnet that arrived through a ticket, the security group someone added a rule to on Friday. That inventory lives in the account, and the only way to see it is to ask the account.

# What changed in what Terraform manages, without touching anything
terraform plan -refresh-only -input=false
# What is in the account with the project tag, managed or not
aws resourcegroupstaggingapi get-resources --tag-filters Key=project,Values=ttwae --query "ResourceTagMappingList[].ResourceARN"
# and the difference against what the state knows
terraform state list

5. Multi-account, multi-region and the 501s

The same security page excludes access across accounts and Regions, so a template with a provider alias per region or an assume_role into the network account does not get fully tested in the emulator. Then there are the services that are not there yet. [Creuto counted the published fidelity tests](https://creuto.com/aws-emulator-vs-localstack-test-split) for release 1.0.471, read on 11/17: S3 passes 2,172 of 2,845 (76%), DynamoDB 1,657 of 2,142 (77%), Lambda 2,103 of 3,021 (70%), EC2 1,346 of 2,499 (54%) and CloudFormation 1,022 of 4,282 (24%). Their decision table puts CloudFormation, Terraform or CDK deployments in the "Real AWS" column.

I would not be that categorical, because of the ab table: Kirill's emulated apply passed 15 resources and caught a real error. But the EC2 number explains why his example has no instances, and the CloudFormation number explains why modules that wrap stacks will not pass. A 501 in the pipeline is the emulator's honest answer; what you have to decide is what to do with it.

How I would chain it

The emulator and the real account answer different questions, so they go in different steps of the same pipeline. First the emulated apply, on every pull request, with no credentials: it catches the shape. Then, with the read-only credential of the target account, the five questions above about what the plan JSON says it will create. Only then the real apply in the sandbox. The second step needs no new tool:

#!/usr/bin/env bash
set -euo pipefail
# 1. emulated apply (shape): fails fast and needs no account; the provider
#    points at https://127.0.0.1:9297 as in Kirill's pipeline
terraform apply -auto-approve -input=false
# 2. against the real account, read-only
terraform plan -out plan.out -input=false
PLAN=$(terraform show -json plan.out)
for b in $(echo "$PLAN" | jq -r '.resource_changes[] | select(.type=="aws_s3_bucket" and (.change.actions|index("create"))) | .change.after.bucket // empty'); do
  aws s3api head-bucket --bucket "$b" 2>/dev/null && { echo "bucket $b already exists"; exit 1; } || true
done
NEED=$(echo "$PLAN" | jq '[.resource_changes[] | select(.type=="aws_eip" and (.change.actions|index("create")))] | length')
USED=$(aws ec2 describe-addresses --query "length(Addresses)")
QUOTA=$(aws service-quotas list-service-quotas --service-code ec2 --query "Quotas[?QuotaName=='EC2-VPC Elastic IPs'].Value | [0]")
[ $(echo "$USED + $NEED <= $QUOTA" | bc) -eq 1 ] || { echo "EIPs: $USED used + $NEED new > quota $QUOTA"; exit 1; }
# 3. only now, the real sandbox

The script's limits are the usual ones: it knows one provider, reads what the plan already decided and cannot read capacity. What it does do is make the red apply in the sandbox rare, and when it comes, make it be for something that could not be known.

Where Control Cloud fits, and where it does not

Control Cloud reads the account through the provider's API, not through the state, so the map shows what lives outside Terraform: the load balancer created by hand, the disk, the IP or the NIC with nothing behind it. Before a deploy, the pre-flight uses that same read-only credential to verify the credential's scope, the subnet and internet egress, the template's dependencies and the hosts. That covers point 4 and part of 1 and 3, and it replaces neither terraform plan nor the emulated apply: they are three different readings of the same account. What it does not do today: it does not check real quotas or effective IAM (what it sees is whether the connected credential can read each resource type), it does not simulate capacity, it does not run as a CI hook and it has no public API; it runs from the canvas and from Pre-Deploy. No agents on the VMs. The AWS guide explains which permissions the read credential needs.

If you already have an emulated apply in your pipeline: what was the last red apply that still got through, and which of the five points was it?