Azure Data sources are not Idempotent!?!?

I want to conditionally create a resource group if it does not exist already. I wanted to use a data source to see if the resource exists already, but the data source will error and exit terraform if the resource does not exist.

I’m not sure how to do this in terraform, or if terraform supports idempotence with data resources.

In bash, I can do this idemptoently:

if ! az group list | jq '.[].name' -r | grep -q ${MY_RESOURCE_GROUP}; then
  az group create --name=${MY_RESOURCE_GROUP} --location=${MY_LOCATION}
fi

Is there a way to do this in Terraform? Or Terraform is not capable of doing this with azurerm provider?