-
Notifications
You must be signed in to change notification settings - Fork 573
aws.ami is forced to be defined when it shouldnt need to be #538
Comments
No one support this provider? |
Hi @ju2wheels , did you found a way to do that ? |
I would be interested in the solution. |
@deft01 No, unfortunately I had no choice but to add the aws.ami into the project's Vagrantfile (even though it shouldnt be needed) in addition to it being defined in the Vagrantfile in the custom AWS Vagrant box. |
Running into this problem, I came up with a hack: in your box's Vagrantfile, add the box's name to a global array in the global scope, i.e. before the
Then in your aws-specific provider configuration in the project Vagrantfile, check if the box you want to use is in that array, and if not, set the ami to a dummy value:
What will happen is that Vagrant runs your project aws provider, will set "dummy"; it will then download the missing box file from your server, load that box's Vagrantfile, and the box is added to $SEEN_BOXES. The box's Vagrantfile's aws provider code will overwrite "dummy" with the value you want, and your project Vagrantfile's aws provider code will not overwrite that anymore. The limitation this has is that you need to know under what name the box will be added to in the box's Vagrantfile, but for distributing your boxes internally that should be ok. |
Due to mitchellh/vagrant-aws#538 they won't be downloaded automatically unless the minicoin.yml specifies an AMI, which then needs to be the correct AMI. So unfortunately the boxes are not quite as useful as they could be to get started.
mitchellh/vagrant-aws#538 would block the automatic download of AWS vagrant boxes unless we explicitly specify an AMI, which in turn would then always overwrite the default from the box. Workaround as per the comment.
I dont get how that solves the problem. The Vagrant box name and the AMI ID are two completely separate things. All you end up doing there is not setting a default AMI in the base box (by setting the default to dummy you are just creating a base box that you always have to override), which defeats making a base box for AWS in the first place since you want the base box to be tied to a specific AMI ID. This issue is entirely tied to Hashicorp's weird obsession with nested scopes or whatever it is and how it does validation on the defaults associated with that, I forget its been a while since I did Vagrant plugin development. |
@ju2wheels in the base box's Vagrantfile you set the ami, and you add the box name to the global array. In the environment Vagrantfile, you check the global array, and if the box file has been loaded, then its name will be in the array. Then you don't overwrite the ami with "dummy". If the entry is not in the array, then set the ami to "dummy" and the plugin will be satisfied with the validation conditions, download the box file, load that box file's Vagrantfile and overwrite your "dummy" setting. See the commits referenced above for how I do it in my project. It ain't pretty and I'd rather not need it (I don't need it in the Azure box logic), but it works. |
I have a repository manager manager for hosting Vagrant boxes (we can assume its just an HTTP server here) and I have my Vagrant boxes and a box.json on this server (not using Atlas).
The idea being that I should just be able to define
vm.box
andvm.box_url
(pointing to box.json) and not need to define anything else for the provider (since the box has AWS provider defaults). Vagrant should then be able to get the box and create an instance.Example Vagrantfile:
Error:
This is unexpected because the Vagrant box retrieved by box.json will have
aws.ami
defined in it as a default for the providerThe above will work if I explicitly add
aws.ami
to the provider above to override the box provider defaults or if I already have the box installed locally then we dont have to override the box value at all.This forced verification here seems wrong.
The text was updated successfully, but these errors were encountered: