You can do this in the Portal or the CLI. The rules you need are quite straightforward, but you need to think about the priority order they’ll be applied in.
Need more? Here’s the solution.