config: resource should be unique

This commit is contained in:
Mitchell Hashimoto 2014-07-18 16:31:01 -07:00
parent 2864605b04
commit 50095612a2
3 changed files with 25 additions and 0 deletions

View File

@ -145,7 +145,18 @@ func (c *Config) Validate() error {
// Check that all references to resources are valid
resources := make(map[string]*Resource)
dupped := make(map[string]struct{})
for _, r := range c.Resources {
if _, ok := resources[r.Id()]; ok {
if _, ok := dupped[r.Id()]; !ok {
dupped[r.Id()] = struct{}{}
errs = append(errs, fmt.Errorf(
"%s: resource repeated multiple times",
r.Id()))
}
}
resources[r.Id()] = r
}
for source, vs := range vars {

View File

@ -22,6 +22,13 @@ func TestConfigValidate_badMultiResource(t *testing.T) {
}
}
func TestConfigValidate_dupResource(t *testing.T) {
c := testConfig(t, "validate-dup-resource")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_outputBadField(t *testing.T) {
c := testConfig(t, "validate-output-bad-field")
if err := c.Validate(); err == nil {

View File

@ -0,0 +1,7 @@
resource "aws_instance" "web" {
count = 5
}
resource "aws_instance" "web" {
count = 10
}