Perhaps you want to look at something like Hashicorp's Terraform (https://www.terraform.io/) which will do most, if not all, of what you're looking for.
That's exactly what I was looking for, thanks! Only feature missing is that it apparently can't dump an existing setup to file; looks like you have to write them from scratch.