-
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
Nov 6, 2015
1 parent
bf11be8
commit 01fe2a1
Showing
6 changed files
with
123 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 |
---|---|---|
|
@@ -20,3 +20,4 @@ website/node_modules | |
*~ | ||
.*.swp | ||
.idea | ||
*.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