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.
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.
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.
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.
> 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.