Has anyone successfully mocked an external data source for a terraform test?

We have a module which uses an external data source to set count to conditionally provision a resource depending on whether something not owned by Terraform exists.

We need to mock this in order to be able to run some Terraform tests against the module.

I have looked at Tests - Provider Mocking | Terraform | HashiCorp Developer and tried some things, but I’ve not got anything to work yet.

Hoping someone has already done this and can sign post an example.

I had the same problem but I was able to fix it by overriding the module so that Terraform does not create any resource in the module.

# my.tftest.hcl

override_module {
  target = module.external_module_to_mock
}

run "foo" {
  ...
}

If needed, you can also mock the outputs.