command/plan: can take no args and default to pwd for config
This commit is contained in:
parent
235a253848
commit
04f7281e8c
|
@ -33,13 +33,22 @@ func (c *PlanCommand) Run(args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var path string
|
||||||
args = cmdFlags.Args()
|
args = cmdFlags.Args()
|
||||||
if len(args) != 1 {
|
if len(args) > 1 {
|
||||||
c.Ui.Error(
|
c.Ui.Error(
|
||||||
"The plan command expects only one argument with the path\n" +
|
"The plan command expects at most one argument with the path\n" +
|
||||||
"to a Terraform configuration.\n")
|
"to a Terraform configuration.\n")
|
||||||
cmdFlags.Usage()
|
cmdFlags.Usage()
|
||||||
return 1
|
return 1
|
||||||
|
} else if len(args) == 1 {
|
||||||
|
path = args[0]
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
path, err = os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
c.Ui.Error(fmt.Sprintf("Error getting pwd: %s", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load up the state
|
// Load up the state
|
||||||
|
@ -59,7 +68,7 @@ func (c *PlanCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := config.Load(args[0])
|
b, err := config.LoadDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf("Error loading blueprint: %s", err))
|
c.Ui.Error(fmt.Sprintf("Error loading blueprint: %s", err))
|
||||||
return 1
|
return 1
|
||||||
|
@ -111,10 +120,14 @@ func (c *PlanCommand) Run(args []string) int {
|
||||||
|
|
||||||
func (c *PlanCommand) Help() string {
|
func (c *PlanCommand) Help() string {
|
||||||
helpText := `
|
helpText := `
|
||||||
Usage: terraform plan [options] [terraform.tf]
|
Usage: terraform plan [options] [dir]
|
||||||
|
|
||||||
Shows the differences between the Terraform configuration and
|
Generates an execution plan for Terraform.
|
||||||
the actual state of an infrastructure.
|
|
||||||
|
This execution plan can be reviewed prior to running apply to get a
|
||||||
|
sense for what Terraform will do. Optionally, the plan can be saved to
|
||||||
|
a Terraform plan file, and apply can take this plan file to execute
|
||||||
|
this plan exactly.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
|
@ -127,7 +140,8 @@ Options:
|
||||||
-refresh=true Update state prior to checking for differences.
|
-refresh=true Update state prior to checking for differences.
|
||||||
|
|
||||||
-state=statefile Path to a Terraform state file to use to look
|
-state=statefile Path to a Terraform state file to use to look
|
||||||
up Terraform-managed resources.
|
up Terraform-managed resources. By default it will
|
||||||
|
use the state "terraform.tfstate" if it exists.
|
||||||
|
|
||||||
`
|
`
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
|
|
|
@ -10,6 +10,29 @@ import (
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestPlan(t *testing.T) {
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
if err := os.Chdir(testFixturePath("plan")); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
defer os.Chdir(cwd)
|
||||||
|
|
||||||
|
p := testProvider()
|
||||||
|
ui := new(cli.MockUi)
|
||||||
|
c := &PlanCommand{
|
||||||
|
ContextOpts: testCtxConfig(p),
|
||||||
|
Ui: ui,
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{}
|
||||||
|
if code := c.Run(args); code != 0 {
|
||||||
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPlan_destroy(t *testing.T) {
|
func TestPlan_destroy(t *testing.T) {
|
||||||
originalState := &terraform.State{
|
originalState := &terraform.State{
|
||||||
Resources: map[string]*terraform.ResourceState{
|
Resources: map[string]*terraform.ResourceState{
|
||||||
|
|
Loading…
Reference in New Issue