mirror of https://github.com/hashicorp/terraform
Mildwonkey/node resource validate (#26206)
* terraform: refactor signature of EvalContext.InitProvisioner Nothing was using the returned provisioners.Interface, so I simplified the signature. * terraform: remove provisioner-related EvalTree()s The various Evals in eval_provisioner were removed from all callers and replaced with straight-through code. `NodeValidatableResource.EvalTree()` to `Execute()` was more involved. I chose to leave the `EvalValidateResource` and `EvalValidateProvisioner` Eval functions mostly as-is, changing the main function to `.Validate` to make it clear that these are no longer eval nodes. Eventually I expect to rename the file (perhaps to just Validate).pull/26243/head
parent
b213ec883d
commit
7b510c4add
@ -1,55 +0,0 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/configs/configschema"
|
||||
"github.com/hashicorp/terraform/provisioners"
|
||||
)
|
||||
|
||||
// EvalInitProvisioner is an EvalNode implementation that initializes a provisioner
|
||||
// and returns nothing. The provisioner can be retrieved again with the
|
||||
// EvalGetProvisioner node.
|
||||
type EvalInitProvisioner struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (n *EvalInitProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
||||
return ctx.InitProvisioner(n.Name)
|
||||
}
|
||||
|
||||
// EvalCloseProvisioner is an EvalNode implementation that closes provisioner
|
||||
// connections that aren't needed anymore.
|
||||
type EvalCloseProvisioner struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (n *EvalCloseProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
||||
ctx.CloseProvisioner(n.Name)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// EvalGetProvisioner is an EvalNode implementation that retrieves an already
|
||||
// initialized provisioner instance for the given name.
|
||||
type EvalGetProvisioner struct {
|
||||
Name string
|
||||
Output *provisioners.Interface
|
||||
Schema **configschema.Block
|
||||
}
|
||||
|
||||
func (n *EvalGetProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
||||
result := ctx.Provisioner(n.Name)
|
||||
if result == nil {
|
||||
return nil, fmt.Errorf("provisioner %s not initialized", n.Name)
|
||||
}
|
||||
|
||||
if n.Output != nil {
|
||||
*n.Output = result
|
||||
}
|
||||
|
||||
if n.Schema != nil {
|
||||
*n.Schema = ctx.ProvisionerSchema(n.Name)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/provisioners"
|
||||
)
|
||||
|
||||
func TestEvalInitProvisioner_impl(t *testing.T) {
|
||||
var _ EvalNode = new(EvalInitProvisioner)
|
||||
}
|
||||
|
||||
func TestEvalInitProvisioner(t *testing.T) {
|
||||
n := &EvalInitProvisioner{Name: "foo"}
|
||||
provisioner := &MockProvisioner{}
|
||||
ctx := &MockEvalContext{InitProvisionerProvisioner: provisioner}
|
||||
if _, err := n.Eval(ctx); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if !ctx.InitProvisionerCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if ctx.InitProvisionerName != "foo" {
|
||||
t.Fatalf("bad: %#v", ctx.InitProvisionerName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvalCloseProvisioner(t *testing.T) {
|
||||
n := &EvalCloseProvisioner{Name: "foo"}
|
||||
provisioner := &MockProvisioner{}
|
||||
ctx := &MockEvalContext{CloseProvisionerProvisioner: provisioner}
|
||||
if _, err := n.Eval(ctx); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if !ctx.CloseProvisionerCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if ctx.CloseProvisionerName != "foo" {
|
||||
t.Fatalf("bad: %#v", ctx.CloseProvisionerName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvalGetProvisioner_impl(t *testing.T) {
|
||||
var _ EvalNode = new(EvalGetProvisioner)
|
||||
}
|
||||
|
||||
func TestEvalGetProvisioner(t *testing.T) {
|
||||
var actual provisioners.Interface
|
||||
n := &EvalGetProvisioner{Name: "foo", Output: &actual}
|
||||
provisioner := &MockProvisioner{}
|
||||
ctx := &MockEvalContext{ProvisionerProvisioner: provisioner}
|
||||
if _, err := n.Eval(ctx); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if actual != provisioner {
|
||||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
|
||||
if !ctx.ProvisionerCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if ctx.ProvisionerName != "foo" {
|
||||
t.Fatalf("bad: %#v", ctx.ProvisionerName)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue