Interview Prep/Terraform/Testing and Policy as Code

How do mock providers work in `terraform test`?

AdvancedProductionTesting and Policy as Code
Answer

Since 1.7 you can declare mock_provider "aws" {} so tests run without credentials or cloud calls; computed attributes get generated values, and you can set specific ones with mock_resource, mock_data or override_resource.

mock_provider "aws" {
  mock_data "aws_availability_zones" {
    defaults = { names = ["ap-south-1a", "ap-south-1b"] }
  }
}

They are great for logic tests (conditionals, for_each keys, validation) in seconds, but cannot prove the cloud accepts your config.

All Terraform questions Roadmap: Terraform in production

More on Testing and Policy as Code