I think my question is rather simple. I want to define some Terraform tests using mock_provider. Of course, I don’t want those provider to actually make remote calls (thus requiring the Internet). I simply want to override various behaviors in those providers to return mock data.
Concrete example
I am using the following provider:
http = {
source = "hashicorp/http"
version = "~> 3.4"
}
I am making simple HTTP calls (expecting 200 response codes):
lifecycle {
postcondition {
condition = contains([200], data.http.validate_backstage_system.status_code)
error_message = "System not found in Backstage"
}
}
data "http" "validate_backstage_system" {
url = "https://server.com/api/catalog/entities/by-name/system/default/${var.my_system}"
}
I am mocking the provider using:
mock_provider "http" {}
================================
I always get the following response:
╷
│ Error: Resource postcondition failed
│
│ on datadog.tf line 115, in resource "datadog_service_level_objective" "dd_slo":
│ 115: condition = contains([200], data.http.validate_backstage_system.status_code) # located here below
│ ├────────────────
│ │ data.http.validate_backstage_system.status_code is 0
│
│ System not found in Backstage
The bottom-line question is:
- how do I define the mock_provider so that I can avoid making the actual HTTP calls?
- it’s got to be some version of
override_module
,override_data
, oroverride_resource
- but ALL examples on the web are only for
aws
and there’s very, very little info anywhere for the mock_provider ability