diff --git a/internal/core/project.go b/internal/core/project.go index 96bf290fa..ae7a1194d 100644 --- a/internal/core/project.go +++ b/internal/core/project.go @@ -751,7 +751,6 @@ func (p *Project) scrubTargets() (err error) { } if resp.Target.State == vagrant_server.Operation_NOT_CREATED || - resp.Target.State == vagrant_server.Operation_UNKNOWN || resp.Target.State == vagrant_server.Operation_DESTROYED { p.logger.Trace("target does not exist, removing", "target", resp.Target, diff --git a/internal/core/vagrantfile.go b/internal/core/vagrantfile.go index 96ba62de4..abd6f2795 100644 --- a/internal/core/vagrantfile.go +++ b/internal/core/vagrantfile.go @@ -29,6 +29,9 @@ import ( // when merging type LoadLocation uint8 +// DEFAULT_VM_NAME is the name that a target gets when none has been specified. +const DEFAULT_VM_NAME = "default" + const ( VAGRANTFILE_BOX LoadLocation = iota // Box VAGRANTFILE_BASIS // Basis @@ -1133,6 +1136,7 @@ func (v *Vagrantfile) targetNameLookup( if cname, ok := v.cache.Fetch("lookup" + nameOrId); ok { return cname.(string), nil } + // Run a lookup first to verify if this target actually exists. If it does, // then request it. resp, err := v.factory.client.FindTarget(v.factory.ctx, @@ -1145,6 +1149,18 @@ func (v *Vagrantfile) targetNameLookup( }, ) if err != nil { + // When we are in Basis-only mode (VAGRANT_CWD does not have a + // Vagrantfile), legacy Vagrant still expects to be able to retrieve config + // for the default vm in order to successfully bootstrap its + // Vagrant::Environment. In order to retain that behavior, we allow the + // DEFAULT_VM_NAME to pass through successfully even when no targets + // exist. Note we are specifically skipping the cache registration + // below for this short circuit - we only want to do that when a target + // exists. + if s := status.Convert(err); s.Code() == codes.NotFound && nameOrId == DEFAULT_VM_NAME { + v.logger.Info("ignoring target not found error for DEFAULT_VM_NAME") + return DEFAULT_VM_NAME, nil + } return "", err }