diff --git a/internal/core/vagrantfile.go b/internal/core/vagrantfile.go index c2c9251e8..9fc8eb935 100644 --- a/internal/core/vagrantfile.go +++ b/internal/core/vagrantfile.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/go-argmapper" "github.com/hashicorp/go-hclog" + "github.com/pkg/errors" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" @@ -18,6 +19,7 @@ import ( "github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cleanup" "github.com/hashicorp/vagrant-plugin-sdk/internal-shared/dynamic" "github.com/hashicorp/vagrant-plugin-sdk/internal-shared/protomappers" + "github.com/hashicorp/vagrant-plugin-sdk/localizer" "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" "github.com/hashicorp/vagrant/internal/plugin" "github.com/hashicorp/vagrant/internal/server/proto/vagrant_server" @@ -444,7 +446,7 @@ func (v *Vagrantfile) Target( return nil, err } - conf, err := v.TargetConfig(name, provider, false) + conf, err := v.TargetConfig(name, provider, true) if err != nil { return } @@ -496,7 +498,6 @@ func (v *Vagrantfile) Target( // Generate a new Vagrantfile for the given target // NOTE: This function may return a nil result without an error -// TODO(spox): Provider validation is not currently implemented // TODO(spox): Needs box configuration applied func (v *Vagrantfile) TargetConfig( name, // name of the target @@ -511,6 +512,29 @@ func (v *Vagrantfile) TargetConfig( return nil, err } + if provider != "" { + pp, err := v.factory.plugins.Find(provider, component.ProviderType) + if err != nil { + return nil, err + } + if validateProvider { + usable, err := pp.Component.(core.Provider).Usable() + if err != nil { + return nil, err + } + if !usable { + // TODO: include message provided in the error + return nil, errors.New( + localizer.LocalizeMsg( + "provider_not_usable", + map[string]string{"Provider": provider, "Machine": name}, + ), + ) + + } + } + } + cid := name + "+" + provider if cv := v.cache.Get(cid); cv != nil { return cv.(core.Vagrantfile), nil diff --git a/plugins/commands/serve/service/provider_service.rb b/plugins/commands/serve/service/provider_service.rb index e978645ca..cf66efe38 100644 --- a/plugins/commands/serve/service/provider_service.rb +++ b/plugins/commands/serve/service/provider_service.rb @@ -20,7 +20,7 @@ module VagrantPlugins def usable(req, ctx) with_plugin(ctx, :providers, broker: broker) do |plugin| - is_usable = plugin.usable? + is_usable = plugin.usable?(true) SDK::Provider::UsableResp.new( is_usable: is_usable, )