How do people manage KV namespace IDs?

AFAIU, you have to manually insert the KV namespace ID into your wrangler.toml.

So what if I want to automatically set up a fresh staging environment for running integration tests. I would have to set up the KV namespace using Wrangler or the API, and then generate a wrangler.toml with the ID? Or is there a better way?