backend/remote: make sure we show the correct error
Previously we would show two errors when there was a version constraint error. But of course one is enough.
This commit is contained in:
parent
15cd6d8300
commit
1e4c20686e
|
@ -214,6 +214,17 @@ func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
|
||||||
// Discover the service URL for this host to confirm that it provides
|
// Discover the service URL for this host to confirm that it provides
|
||||||
// a remote backend API and to get the version constraints.
|
// a remote backend API and to get the version constraints.
|
||||||
service, constraints, err := b.discover()
|
service, constraints, err := b.discover()
|
||||||
|
|
||||||
|
// First check any contraints we might have received.
|
||||||
|
if constraints != nil {
|
||||||
|
diags = diags.Append(b.checkConstraints(constraints))
|
||||||
|
if diags.HasErrors() {
|
||||||
|
return diags
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// When we don't have any constraints errors, also check for discovery
|
||||||
|
// errors before we continue.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
diags = diags.Append(tfdiags.AttributeValue(
|
diags = diags.Append(tfdiags.AttributeValue(
|
||||||
tfdiags.Error,
|
tfdiags.Error,
|
||||||
|
@ -221,15 +232,6 @@ func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
|
||||||
"", // no description is needed here, the error is clear
|
"", // no description is needed here, the error is clear
|
||||||
cty.Path{cty.GetAttrStep{Name: "hostname"}},
|
cty.Path{cty.GetAttrStep{Name: "hostname"}},
|
||||||
))
|
))
|
||||||
}
|
|
||||||
|
|
||||||
// Check any retrieved constraints to make sure we are compatible.
|
|
||||||
if constraints != nil {
|
|
||||||
diags = diags.Append(b.checkConstraints(constraints))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return if we have any discovery of version constraints errors.
|
|
||||||
if diags.HasErrors() {
|
|
||||||
return diags
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,8 +393,19 @@ func (b *Remote) checkConstraints(c *disco.Constraints) tfdiags.Diagnostics {
|
||||||
return diags.Append(checkConstraintsWarning(err))
|
return diags.Append(checkConstraintsWarning(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
var action, toVersion string
|
|
||||||
var excludes []*version.Version
|
var excludes []*version.Version
|
||||||
|
for _, exclude := range c.Excluding {
|
||||||
|
v, err := version.NewVersion(exclude)
|
||||||
|
if err != nil {
|
||||||
|
return diags.Append(checkConstraintsWarning(err))
|
||||||
|
}
|
||||||
|
excludes = append(excludes, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort all the excludes.
|
||||||
|
sort.Sort(version.Collection(excludes))
|
||||||
|
|
||||||
|
var action, toVersion string
|
||||||
switch {
|
switch {
|
||||||
case minimum.GreaterThan(v):
|
case minimum.GreaterThan(v):
|
||||||
action = "upgrade"
|
action = "upgrade"
|
||||||
|
@ -400,18 +413,7 @@ func (b *Remote) checkConstraints(c *disco.Constraints) tfdiags.Diagnostics {
|
||||||
case maximum.LessThan(v):
|
case maximum.LessThan(v):
|
||||||
action = "downgrade"
|
action = "downgrade"
|
||||||
toVersion = "<= " + maximum.String()
|
toVersion = "<= " + maximum.String()
|
||||||
case len(c.Excluding) > 0:
|
case len(excludes) > 0:
|
||||||
for _, exclude := range c.Excluding {
|
|
||||||
v, err := version.NewVersion(exclude)
|
|
||||||
if err != nil {
|
|
||||||
return diags.Append(checkConstraintsWarning(err))
|
|
||||||
}
|
|
||||||
excludes = append(excludes, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort all the excludes.
|
|
||||||
sort.Sort(version.Collection(excludes))
|
|
||||||
|
|
||||||
// Get the latest excluded version.
|
// Get the latest excluded version.
|
||||||
action = "upgrade"
|
action = "upgrade"
|
||||||
toVersion = "> " + excludes[len(excludes)-1].String()
|
toVersion = "> " + excludes[len(excludes)-1].String()
|
||||||
|
|
|
@ -30,8 +30,8 @@ type Constraints struct {
|
||||||
Service string `json:"service"`
|
Service string `json:"service"`
|
||||||
Product string `json:"product"`
|
Product string `json:"product"`
|
||||||
Minimum string `json:"minimum"`
|
Minimum string `json:"minimum"`
|
||||||
Excluding []string `json:"excluding"`
|
|
||||||
Maximum string `json:"maximum"`
|
Maximum string `json:"maximum"`
|
||||||
|
Excluding []string `json:"excluding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrServiceNotProvided is returned when the service is not provided.
|
// ErrServiceNotProvided is returned when the service is not provided.
|
||||||
|
|
Loading…
Reference in New Issue