hn.today

Testing Terraform with AWS Emulator

notes.hatedabamboo.me76 points10 comments
Screenshot of Testing Terraform with AWS Emulator

Terraform plans can look correct yet fail during apply because planning relies on declared configuration and cannot reproduce every AWS API constraint or the state of live resources. The proposed safeguard is AWS Emulator, a self-contained binary or Docker image that exposes AWS-compatible API endpoints. Terraform can apply changes to this temporary environment before the same changes are applied to real AWS, catching more failures without requiring developers to test against production or disrupt the pull-request workflow.

A local demonstration configures Terraform’s AWS provider to route the services used by a sample stack - such as EC2, Lambda, IAM, CloudWatch, and SNS - to the emulator. It also accounts for the emulator’s self-signed HTTPS certificate, path-style S3 requests, and skipped AWS credential and metadata checks. Both planning and applying succeed, creating 15 resources; the emulator keeps state in memory, so restarting it resets the environment. A GitHub Actions workflow shows the same approach in CI: install and start the emulator, wait for its health endpoint, configure its generated credentials and certificate, then run Terraform initialization, validation, planning, and applying. The example pipeline completes in about 1 minute 25 seconds. The extra runtime is presented as a worthwhile tradeoff for detecting apply-time problems before changes reach actual AWS.

Read on notes.hatedabamboo.me10 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.