mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
command: adhere to new API
This commit is contained in:
parent
4b263992cc
commit
d64ba66edb
@ -86,16 +86,13 @@ func (c *ApplyCommand) Run(args []string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
tfconfig := c.TFConfig
|
||||
tfconfig.Config = b
|
||||
|
||||
tf, err := terraform.New(tfconfig)
|
||||
tf, err := terraform.New(c.TFConfig)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error initializing Terraform: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
plan, err := tf.Plan(state)
|
||||
plan, err := tf.Plan(b, state, nil)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error running plan: %s", err))
|
||||
return 1
|
||||
|
@ -60,16 +60,13 @@ func (c *PlanCommand) Run(args []string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
tfconfig := c.TFConfig
|
||||
tfconfig.Config = b
|
||||
|
||||
tf, err := terraform.New(tfconfig)
|
||||
tf, err := terraform.New(c.TFConfig)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error initializing Terraform: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
plan, err := tf.Plan(state)
|
||||
plan, err := tf.Plan(b, state, nil)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error running plan: %s", err))
|
||||
return 1
|
||||
|
@ -1,6 +1,7 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -22,7 +23,12 @@ type Plan struct {
|
||||
}
|
||||
|
||||
func (p *Plan) String() string {
|
||||
return p.Diff.String()
|
||||
buf := new(bytes.Buffer)
|
||||
buf.WriteString("DIFF:\n\n")
|
||||
buf.WriteString(p.Diff.String())
|
||||
buf.WriteString("\nSTATE:\n\n")
|
||||
buf.WriteString(p.State.String())
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (p *Plan) init() {
|
||||
|
@ -49,6 +49,10 @@ func (s *State) Orphans(c *config.Config) []string {
|
||||
}
|
||||
|
||||
func (s *State) String() string {
|
||||
if len(s.Resources) == 0 {
|
||||
return "<no state>"
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
names := make([]string, 0, len(s.Resources))
|
||||
|
@ -109,6 +109,7 @@ func (t *Terraform) plan(
|
||||
p := &Plan{
|
||||
Config: c,
|
||||
Vars: vs,
|
||||
State: s,
|
||||
}
|
||||
err := g.Walk(t.planWalkFn(p, vs))
|
||||
return p, err
|
||||
|
@ -161,6 +161,34 @@ func TestTerraformPlan_computed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerraformPlan_state(t *testing.T) {
|
||||
c := testConfig(t, "plan-good")
|
||||
tf := testTerraform2(t, nil)
|
||||
|
||||
s := &State{
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.foo": &ResourceState{
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
plan, err := tf.Plan(c, s, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if len(plan.Diff.Resources) < 2 {
|
||||
t.Fatalf("bad: %#v", plan.Diff.Resources)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(plan.String())
|
||||
expected := strings.TrimSpace(testTerraformPlanStateStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerraformRefresh(t *testing.T) {
|
||||
rpAWS := new(MockResourceProvider)
|
||||
rpAWS.ResourcesReturn = []ResourceType{
|
||||
@ -431,15 +459,23 @@ aws_instance.foo:
|
||||
`
|
||||
|
||||
const testTerraformPlanStr = `
|
||||
DIFF:
|
||||
|
||||
UPDATE: aws_instance.bar
|
||||
foo: "" => "2"
|
||||
type: "" => "aws_instance"
|
||||
UPDATE: aws_instance.foo
|
||||
num: "" => "2"
|
||||
type: "" => "aws_instance"
|
||||
|
||||
STATE:
|
||||
|
||||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformPlanComputedStr = `
|
||||
DIFF:
|
||||
|
||||
UPDATE: aws_instance.bar
|
||||
foo: "" => "<computed>"
|
||||
type: "" => "aws_instance"
|
||||
@ -447,4 +483,24 @@ UPDATE: aws_instance.foo
|
||||
id: "" => "<computed>"
|
||||
num: "" => "2"
|
||||
type: "" => "aws_instance"
|
||||
|
||||
STATE:
|
||||
|
||||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformPlanStateStr = `
|
||||
DIFF:
|
||||
|
||||
UPDATE: aws_instance.bar
|
||||
foo: "" => "2"
|
||||
type: "" => "aws_instance"
|
||||
UPDATE: aws_instance.foo
|
||||
num: "" => "2"
|
||||
type: "" => ""
|
||||
|
||||
STATE:
|
||||
|
||||
aws_instance.foo:
|
||||
ID = bar
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user