Skip to content

Commit

Permalink
Work around vagrant-aws plugin bug
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vohi committed Jan 31, 2022
1 parent aa3959c commit 527ff95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions basebox/aws/linux/Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$settings[:aws_boxes] ||= []
$settings[:aws_boxes] << "tqtc/linux-aws"

Vagrant.configure('2') do |config|
config.vm.guest = :linux
config.vm.provider :aws
Expand Down
3 changes: 3 additions & 0 deletions basebox/aws/windows/Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$settings[:aws_boxes] ||= []
$settings[:aws_boxes] << "tqtc/windows-aws"

Vagrant.configure('2') do |config|
config.vm.guest = :windows
config.vm.provider :aws
Expand Down
15 changes: 11 additions & 4 deletions minicoin/lib/aws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# AWS specific settings
def aws_setup(box, machine)
$settings[:aws] ||= {}
$settings[:aws_boxes] ||= []

return unless Vagrant.has_plugin?('vagrant-aws')
return if $AWS_CLI_INSTALLED == false
# this has to happen on machine level, even though it's only needed for the
Expand All @@ -27,10 +29,15 @@ def aws_setup(box, machine)
# this group is created by minicoin with permissions for SSH, RDP, and WinRM
aws.security_groups = [ "minicoin" ]

# if the box is not installed or doesn't specify an AMI, then the minicoin.yaml file
# has to specify it. And we can't override what is set here in the box's Vagrantfile,
# so we are stuck. https://github.com/mitchellh/vagrant-aws/issues/538
aws.ami = box.minicoin.machine['ami'] unless box.minicoin.machine['ami'].nil?
# Workaround for https://github.com/mitchellh/vagrant-aws/issues/538: if the box we
# want is not installed yet, then the AWS plugin fails the validation before the box
# gets downloaded and installed. To check whether the box is installed, we use an entry
# in our global settings hash that boxes add themselves to via their Vagrantfile.
# If the box is not loaded yet, then setting the ami to a dummy value satisfies the
# plugin without overwriting the box file or the AWS-specific provisioning declared
# in the minicoin machine configuration.
aws.ami = "dummy" unless $settings[:aws_boxes].include?(box.minicoin.machine['box'])

aws.tags = {
"minicoin" => box.minicoin.machine['name']
}
Expand Down

0 comments on commit 527ff95

Please sign in to comment.