terraform: Apply takes a plan

This commit is contained in:
Mitchell Hashimoto 2014-06-20 12:49:01 -07:00
parent a0cbbab03b
commit 3aab0cd21b
2 changed files with 6 additions and 9 deletions

View File

@ -103,9 +103,9 @@ func New(c *Config) (*Terraform, error) {
}, nil }, nil
} }
func (t *Terraform) Apply(s *State, d *Diff) (*State, error) { func (t *Terraform) Apply(p *Plan) (*State, error) {
result := new(State) result := new(State)
err := t.graph.Walk(t.applyWalkFn(s, d, result)) err := t.graph.Walk(t.applyWalkFn(p, result))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -128,8 +128,7 @@ func (t *Terraform) Refresh(*State) (*State, error) {
} }
func (t *Terraform) applyWalkFn( func (t *Terraform) applyWalkFn(
state *State, p *Plan,
diff *Diff,
result *State) depgraph.WalkFunc { result *State) depgraph.WalkFunc {
var l sync.Mutex var l sync.Mutex
@ -162,7 +161,7 @@ func (t *Terraform) applyWalkFn(
return vars, nil return vars, nil
} }
return t.genericWalkFn(state, diff, cb) return t.genericWalkFn(p.State, p.Diff, cb)
} }
func (t *Terraform) planWalkFn( func (t *Terraform) planWalkFn(

View File

@ -203,17 +203,16 @@ func TestNew_variables(t *testing.T) {
} }
} }
/*
func TestTerraformApply(t *testing.T) { func TestTerraformApply(t *testing.T) {
tf := testTerraform(t, "apply-good") tf := testTerraform(t, "apply-good")
s := &State{} s := &State{}
d, err := tf.Diff(s) p, err := tf.Plan(s)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
state, err := tf.Apply(s, d) state, err := tf.Apply(p)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -228,7 +227,6 @@ func TestTerraformApply(t *testing.T) {
t.Fatalf("bad: \n%s", actual) t.Fatalf("bad: \n%s", actual)
} }
} }
*/
func TestTerraformPlan(t *testing.T) { func TestTerraformPlan(t *testing.T) {
tf := testTerraform(t, "plan-good") tf := testTerraform(t, "plan-good")