How Terraform Tests Saved a Prod Deployment

Picture this: It’s 1 AM. I am not even joking:

You’ve just refactored your Terraform module to add the auto-scaling magic. You merge. You deploy. You go to bed. The next morning? Production is literally on fire πŸ”₯ because your β€œtiny” change accidentally nuked the database.

How to stop β€œOops” from becoming β€œOH NO” …


Test-Driven Chaos Prevention πŸ§ͺ

Terraform tests (available in v1.6+) let you validate config changes before they touch your infrastructure. Think of them as your code’s personal bouncer, checking IDs at the door.

# valid_string_concat.tftest.hcl
run "did_i_break_everything" {
  command = plan
  assert {
    condition = aws_s3_bucket.bucket.name == "my-glittery-unicorn-bucket"
    error_message = "Name mismatch! Abort mission! 🚨"
  }
}

Translation: β€œIf the bucket name isn’t β€˜my-glittery-unicorn-bucket,’ error and abort.”


How Terraform Tests Save You πŸ€—

1️⃣ command = plan: Simulate changes without touching real infra. β€œWhat if…?” but for adults.
2️⃣ Assertions: Like a clingy ex, they’ll text you 100x if something’s wrong. Example:

assert {
  condition = output.bucket_name == "test-bucket" 
  error_message = "This is NOT the bucket you’re looking for. πŸ‘‹"
}

3️⃣ Variables & Overrides: Test edge cases without redeploying. Example: β€œWhat if someone sets bucket_prefix to πŸ”₯?”


Some Tips !

  • Mock Providers (v1.7+): Fake it ’til you make it. Test AWS without paying AWS πŸ‘
  • Expect Failure: Want to validate that a config should break? Use expect_failures. Example:
run "expect_chaos" {
  variables { input = 1 } # Odd number β†’ should fail validation
  expect_failures = [var.input]
}

Translation: β€œIf this doesn’t fail, I’ve lost faith in humanity.” (I have already tbh)

  • Modules in Tests: Reuse setup/teardown logic like a lazy genius. Example: A β€œtest” module that pre-creates a VPC so you can focus on actual work.
module "consul" {
  source  = "hashicorp/consul/aws"
  version = "0.0.5"

  servers = 3
}

The Takeaway πŸš€

Testing is like adding seat belts to your code: boring until you crash !

Use run blocks, assertions, and provider mocking to:

  • Avoid β€œWorks on My Machine” syndrome
  • Sleep better (no 3 AM β€œWHY IS S3 DOWN”)
  • Brag in PR reviews (β€œMy tests caught 10 bugs. Your move, Karen.”)

TL;DR: Write tests. Save your sanity.

Resources:
[1] https://www.paloaltonetworks.com/blog/prisma-cloud/hashicorp-terraform-cloud-run-tasks-integration
[2] https://developer.hashicorp.com/terraform/language/tests

Equal Experts Geek Conference 2023

Hey guys, 4 months ago I had a 5 minutes lightning talk about How the QA will look like in the future at the Equal Experts Conference.

We went through the evolution of the role and how it is right now, then we quickly talk about the trends that are coming so you can already prepare yourself to be up to date πŸ™‚


In this 5-minute talk, we will quickly talk about the future of Quality Assurance (QA) position and discuss the evolution of the QA role in response to emerging trends.

The QA role has come a long way from its traditional focus on manual testing and bug detection. As technology advances, QA professionals are adapting to new demands and becoming integral contributors to the software development process.

TheΒ  future of QA position will be marked by AI Tests,Β  Tests in the Cloud, Web3 Tests, Alerting and Monitoring, along with strong soft skills. By embracing these trends and developing the necessary skills, QA professionals will be well-equipped to drive quality and innovation in the ever-changing software development industry.