-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Soren Mathiasen
committed
Feb 5, 2016
1 parent
57836e0
commit e7ed5de
Showing
7 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ website/node_modules | |
.*.swp | ||
.idea | ||
*.test | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
resource "test_instance" "foo" { | ||
ami = "bar" | ||
|
||
# This is here because at some point it caused a test failure | ||
network_interface { | ||
device_index = 0 | ||
description = "Main network interface ${var.this_is_an_error}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
resource "test_instance" "foo" { | ||
ami = "bar" | ||
|
||
# This is here because at some point it caused a test failure | ||
network_interface { | ||
device_index = 0 | ||
description = "Main network interface" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/config" | ||
"path/filepath" | ||
) | ||
|
||
// VerifyCommand is a Command implementation that verifies the terraform files | ||
type VerifyCommand struct { | ||
Meta | ||
} | ||
|
||
const defaultPath = "." | ||
|
||
func (c *VerifyCommand) Help() string { | ||
return "" | ||
} | ||
|
||
func (c *VerifyCommand) Run(args []string) int { | ||
args = c.Meta.process(args, false) | ||
var dirPath string | ||
|
||
if len(args) == 1 { | ||
dirPath = args[0] | ||
} else { | ||
dirPath = "." | ||
} | ||
dir, err := filepath.Abs(dirPath) | ||
if err != nil { | ||
c.Ui.Error(fmt.Sprintf( | ||
"Unable to locate directory %v\n", err.Error())) | ||
} | ||
|
||
rtnCode := c.validate(dir) | ||
|
||
return rtnCode | ||
} | ||
|
||
func (c *VerifyCommand) Synopsis() string { | ||
return "Validates the Terraform files" | ||
} | ||
|
||
func (c *VerifyCommand) validate(dir string) int { | ||
cfg, err := config.LoadDir(dir) | ||
if err != nil { | ||
c.Ui.Error(fmt.Sprintf( | ||
"Error loading files %v\n", err.Error())) | ||
return 1 | ||
} | ||
err = cfg.Validate() | ||
if err != nil { | ||
c.Ui.Error(fmt.Sprintf( | ||
"Error validating: %v\n", err.Error())) | ||
return 1 | ||
} | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package command | ||
|
||
import ( | ||
"github.com/mitchellh/cli" | ||
"testing" | ||
) | ||
|
||
func TestVerifyCommand(t *testing.T) { | ||
ui := new(cli.MockUi) | ||
c := &VerifyCommand{ | ||
Meta: Meta{ | ||
Ui: ui, | ||
}, | ||
} | ||
|
||
args := []string{ | ||
testFixturePath("verify-valid"), | ||
} | ||
|
||
if code := c.Run(args); code != 0 { | ||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) | ||
} | ||
} | ||
|
||
func TestVerifyFailingCommand(t *testing.T) { | ||
ui := new(cli.MockUi) | ||
c := &VerifyCommand{ | ||
Meta: Meta{ | ||
Ui: ui, | ||
}, | ||
} | ||
|
||
args := []string{ | ||
testFixturePath("verify-invalid"), | ||
} | ||
|
||
if code := c.Run(args); code == 0 { | ||
t.Fatalf("Should have failed: %d\n\n%s", code, ui.ErrorWriter.String()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
layout: "docs" | ||
page_title: "Command: verify" | ||
sidebar_current: "docs-commands-verify" | ||
description: |- | ||
The `terraform verify` command is used to validate the format and structure of the terraform files. | ||
--- | ||
|
||
# Command: verify | ||
|
||
The `terraform verify` command is used to validate the format and structure of the terraform files. | ||
Terraform performas an analysis of the terraform files, and will display information about missing | ||
variables and errors in the structure of the files. | ||
|
||
## Usage | ||
|
||
Usage: `terraform verify [dir]` | ||
|
||
By default, `verify` requires no flags and looks in the current directory | ||
for the configurations. |