I'm writing a Vagrant file that I want to work for both the virtualbox and aws providers, and I want to keep my sensitive AWS credentials in a separate, non-version-controlled file. The behavior that I want is that when I type "vagrant up --provider=aws", vagrant loads the credentials from the external file, or if the external file is not present, exits with an error message. Also, when I type "vagrant up --provider=virtualbox" (or just "vagrant up", since virtualbox is the default), I'd like vagrant to spin up the VM regardless of whether the AWS credentials file is present, since it isn't needed in that case.
My Vagrant file looks something like the following:
What is happening, though, is that the code inside the "config.vm.provider :aws do |aws, override|" block is being executed regardless of which provider I invoke "vagrant up" with, so if the aws.yml file is missing, vagrant always exits with the message "File aws.yml not present!".
Is there a way that I can write code in the Vagrantfile that tests which provider is requested, so that I can only execute a certain block of code for particular provider?