last Evals without diagnostics
This commit is contained in:
parent
786a7291bf
commit
77cabe187d
|
@ -20,7 +20,7 @@ type EvalValidateSelfRef struct {
|
||||||
ProviderSchema **ProviderSchema
|
ProviderSchema **ProviderSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *EvalValidateSelfRef) Eval(ctx EvalContext) (interface{}, error) {
|
func (n *EvalValidateSelfRef) Eval(ctx EvalContext) tfdiags.Diagnostics {
|
||||||
var diags tfdiags.Diagnostics
|
var diags tfdiags.Diagnostics
|
||||||
addr := n.Addr
|
addr := n.Addr
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ func (n *EvalValidateSelfRef) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.ProviderSchema == nil || *n.ProviderSchema == nil {
|
if n.ProviderSchema == nil || *n.ProviderSchema == nil {
|
||||||
return nil, fmt.Errorf("provider schema unavailable while validating %s for self-references; this is a bug in Terraform and should be reported", addr)
|
diags = diags.Append(fmt.Errorf("provider schema unavailable while validating %s for self-references; this is a bug in Terraform and should be reported", addr))
|
||||||
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
providerSchema := *n.ProviderSchema
|
providerSchema := *n.ProviderSchema
|
||||||
|
@ -46,7 +47,8 @@ func (n *EvalValidateSelfRef) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if schema == nil {
|
if schema == nil {
|
||||||
return nil, fmt.Errorf("no schema available for %s to validate for self-references; this is a bug in Terraform and should be reported", addr)
|
diags = diags.Append(fmt.Errorf("no schema available for %s to validate for self-references; this is a bug in Terraform and should be reported", addr))
|
||||||
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
refs, _ := lang.ReferencesInBlock(n.Config, schema)
|
refs, _ := lang.ReferencesInBlock(n.Config, schema)
|
||||||
|
@ -63,5 +65,5 @@ func (n *EvalValidateSelfRef) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, diags.NonFatalErr()
|
return diags
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/configs/configschema"
|
"github.com/hashicorp/terraform/configs/configschema"
|
||||||
"github.com/hashicorp/terraform/tfdiags"
|
|
||||||
|
|
||||||
"github.com/hashicorp/hcl/v2"
|
"github.com/hashicorp/hcl/v2"
|
||||||
"github.com/hashicorp/hcl/v2/hcltest"
|
"github.com/hashicorp/hcl/v2/hcltest"
|
||||||
|
@ -98,11 +97,7 @@ func TestEvalValidateSelfRef(t *testing.T) {
|
||||||
Config: body,
|
Config: body,
|
||||||
ProviderSchema: &ps,
|
ProviderSchema: &ps,
|
||||||
}
|
}
|
||||||
result, err := n.Eval(nil)
|
diags := n.Eval(nil)
|
||||||
if result != nil {
|
|
||||||
t.Fatal("result should always be nil")
|
|
||||||
}
|
|
||||||
diags := tfdiags.Diagnostics(nil).Append(err)
|
|
||||||
if diags.HasErrors() != test.Err {
|
if diags.HasErrors() != test.Err {
|
||||||
if test.Err {
|
if test.Err {
|
||||||
t.Errorf("unexpected success; want error")
|
t.Errorf("unexpected success; want error")
|
||||||
|
|
|
@ -68,9 +68,9 @@ func (n *NodePlannableResourceInstance) dataResourceExecute(ctx EvalContext) err
|
||||||
Config: config.Config,
|
Config: config.Config,
|
||||||
ProviderSchema: &providerSchema,
|
ProviderSchema: &providerSchema,
|
||||||
}
|
}
|
||||||
_, err = validateSelfRef.Eval(ctx)
|
diags = validateSelfRef.Eval(ctx)
|
||||||
if err != nil {
|
if diags.HasErrors() {
|
||||||
return err
|
return diags.ErrWithWarnings()
|
||||||
}
|
}
|
||||||
|
|
||||||
readDataPlan := &evalReadDataPlan{
|
readDataPlan := &evalReadDataPlan{
|
||||||
|
@ -144,9 +144,9 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext)
|
||||||
Config: config.Config,
|
Config: config.Config,
|
||||||
ProviderSchema: &providerSchema,
|
ProviderSchema: &providerSchema,
|
||||||
}
|
}
|
||||||
_, err = validateSelfRef.Eval(ctx)
|
diags = validateSelfRef.Eval(ctx)
|
||||||
if err != nil {
|
if diags.HasErrors() {
|
||||||
return err
|
return diags.ErrWithWarnings()
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceRefreshState, err = n.ReadResourceInstanceState(ctx, addr)
|
instanceRefreshState, err = n.ReadResourceInstanceState(ctx, addr)
|
||||||
|
|
Loading…
Reference in New Issue