How to test data block conditions

I would like to validate that this data block is fetching the right subnet ids. I am also not allowed to use an active AWS account to create ephemeral resources for this. I am also not allowed to use localstack or other aws api emulators.

How do I mock some data or override data/resources to validate that the data block is fetching the correct subnets?

data "aws_subnets" "app" {
  tags = {
    Tier = "app"
  }
}

p.s the use case is more complex but im using a simpler example to better understand the problem first

Are you trying to do this in Terraform’s test framework?

I think generally, if you’re mocking the data, by definition, you’ll usually no longer really be validating that it’s fetching the right things.

For example, consider this example – in test.tf:

data "aws_subnets" "app" {
  tags = {
    Tier = "app"
  }
}

and in test.tftest.hcl:

mock_provider "aws" {

  mock_data "aws_subnets" {
    defaults = {
      "ids" =  ["asdf"] ## This is just bogus - you'd probably want to put in more realistic mock data
    }
  }
}

run "aws_subnets_app" {
  assert {
    condition     = data.aws_subnets.app.ids.0 == "asdf"
    error_message = "didn't get expected value"
  }
}

This will pass, even though the tags you’re filtering on aren’t present in the mocked data structure. You can, however, use this to provide reliable data returned from the provider, and to validate some custom logic you might be doing to manipulate what you get back in your own code, so it really depends on what you’re trying to do here.