Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Testing Terraform with AWS Emulator

Terraform, a popular infrastructure-as-code tool, sometimes encounters issues when transitioning from plan to apply jobs. This discrepancy arises because plan jobs cannot fully emulate every API call to a live infrastructure. While it's possible to manually apply changes locally, this approach disrupts the automation workflow. To address this issue, AWS released the Emulator, a self-contained binary or Docker container that emulates AWS API endpoints locally.

The key benefit of the AWS Emulator lies in its ability to provide a realistic AWS API environment, enabling developers to test their Terraform code without affecting real infrastructure. By utilizing the emulator, developers can run the familiar "Plan Apply" workflow, transitioning to "Plan Apply against mock AWS infrastructure to test the plan Apply on actual AWS Infrastructure."

To set up the AWS Emulator, you can install it via package manager or build it using Docker. For local testing, Docker is recommended. Once installed, you can interact with the emulator using the provided admin endpoint. To deploy infrastructure, configure Terraform to interact with the emulator instead of the real AWS APIs. The configuration requires setting up insecure connections and mapping each service to an emulator endpoint.

After configuring Terraform, you can test the setup by running the plan job, which should pass without issues. The real test comes when applying the changes against the emulator. While the emulator doesn't log API requests, it effectively stores its state in memory, ensuring a clean slate for each container restart.

Integrating the AWS Emulator into a CI pipeline is straightforward, requiring a similar setup to the local environment. This allows developers to catch errors early in the development process, preventing issues from propagating to the actual AWS infrastructure. By incorporating the emulator into the workflow, developers can save time and ensure that their Terraform code behaves as expected before deploying to production.

In conclusion, the AWS Emulator is a valuable tool for developers looking to streamline their Terraform workflows and catch potential issues early in the development process. By running tests against a realistic AWS API environment, developers can ensure that their infrastructure-as-code configurations are robust and reliable.

Rewritten by urgent.news; may contain errors — check the original.

Source: notes.hatedabamboo.me

Read the original at notes.hatedabamboo.me →

Report a problem with this story

More in Tech

More from Sunday 22 November →