MIDREAL
Menu

Testing Terraform with AWS Emulator

https://notes.hatedabamboo.me/terraform-tests-with-aws-emulator/ (notes.hatedabamboo.me)

76 points | 20h ago | Discuss on Hacker News | Back to Radar

Comments

0xbadcafebee 15h ago on HN
The problem with testing with Terraform or any other tool is that the emulator won't accurately reflect real-world behavior. The real world services have a bunch of logic and code of them which isn't all replicated in the emulator. The only thing the emulator does is replicate the API. It's a bit like trying to build a model of a house by building the model to look like the outside of the house. Gives you an idea what it looks like, but working within that model is not going to be the same as working within the actual house.
ozarkerD 14h ago on HN
Agreed. We also have a fair amount of TF testing involving IAM to make sure we get permissions right which the emulator doesn’t emulate at all unfortunately.
QGQBGdeZREunxLe 13h ago on HN
The problem with full e2e tests for Terraform is that they are 1. Extremely slow 2. Can be expensive.

LocalStack and hopefully the new AWS Emulator can give you a fairly high degree of confidence.

ctkhn 13h ago on HN
Most teams I've been on have used a pre-production environment for a combination of performance testing and making sure infra worked as expected. To a smaller degree with less instances etc, we use our dev and test environments to make sure infra works the same as it should in higher envs.
OJFord 12h ago on HN
Let's not do unit tests or local dev environments either then.
jamesfinlayson 10h ago on HN
Yep. Twice this year I've had working CloudFormation break because AWS decided to change validation without telling us.
whinvik 14h ago on HN
Nice. Now for GCP to also release such a tool
mdaniel 11h ago on HN
I am not currently in a position to test it to see how it compares to the amount of energy which has gone into emulating AWS control plane, but https://github.com/floci-io/floci-gcp#supported-services (MIT)
itintheory 11h ago on HN
> These mock calls can't know for a fact that you already have a resource in AWS called "my-bucket-asdasdasd"

Doesn't seem like the AWS Emulator would know that either, unless it's connecting to real AWS... Also, bucket names are global, so it doesn't matter what you have, it's what anyone has.

sschnei8 11h ago on HN
You can use account regional namepsaces to avoid the global issue. https://aws.amazon.com/blogs/aws/introducing-account-regiona...
danw1979 1h ago on HN
PSA: don’t ever pass your AWS credentials as TF_VAR_s, they’ll end up in the state file, which is a bad thing.

from the article, in a github actions workflow:

‘TF_VAR_secret_key: … ‘

and yeah this was just for the “emulator” provider config but you know someone will come along and copy your example for a real workflow and provider config.

(Yes, I know about state encryption, thank you.)

Comments are loaded live from Hacker News and are not stored by Mid or Real.