config: outputs must be unique

This commit is contained in:
Mitchell Hashimoto 2016-08-25 14:43:57 -07:00
parent 8494cad8c4
commit 099293b690
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 60 additions and 31 deletions

View File

@ -586,7 +586,18 @@ func (c *Config) Validate() error {
}
// Check that all outputs are valid
{
found := make(map[string]struct{})
for _, o := range c.Outputs {
// Verify the output is new
if _, ok := found[o.Name]; ok {
errs = append(errs, fmt.Errorf(
"%s: duplicate output. output names must be unique.",
o.Name))
continue
}
found[o.Name] = struct{}{}
var invalidKeys []string
valueKeyFound := false
for k := range o.RawConfig.Raw {
@ -626,6 +637,7 @@ func (c *Config) Validate() error {
}
}
}
}
// Check that all variables are in the proper context
for source, rc := range c.rawConfigs() {

View File

@ -300,6 +300,13 @@ func TestConfigValidate_outputBadField(t *testing.T) {
}
}
func TestConfigValidate_outputDuplicate(t *testing.T) {
c := testConfig(t, "validate-output-dup")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_pathVar(t *testing.T) {
c := testConfig(t, "validate-path-var")
if err := c.Validate(); err != nil {

View File

@ -0,0 +1,10 @@
resource "aws_instance" "web" {
}
output "ip" {
value = "foo"
}
output "ip" {
value = "bar"
}