config: resource should be unique
This commit is contained in:
parent
2864605b04
commit
50095612a2
|
@ -145,7 +145,18 @@ func (c *Config) Validate() error {
|
||||||
|
|
||||||
// Check that all references to resources are valid
|
// Check that all references to resources are valid
|
||||||
resources := make(map[string]*Resource)
|
resources := make(map[string]*Resource)
|
||||||
|
dupped := make(map[string]struct{})
|
||||||
for _, r := range c.Resources {
|
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
|
resources[r.Id()] = r
|
||||||
}
|
}
|
||||||
for source, vs := range vars {
|
for source, vs := range vars {
|
||||||
|
|
|
@ -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) {
|
func TestConfigValidate_outputBadField(t *testing.T) {
|
||||||
c := testConfig(t, "validate-output-bad-field")
|
c := testConfig(t, "validate-output-bad-field")
|
||||||
if err := c.Validate(); err == nil {
|
if err := c.Validate(); err == nil {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
resource "aws_instance" "web" {
|
||||||
|
count = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "web" {
|
||||||
|
count = 10
|
||||||
|
}
|
Loading…
Reference in New Issue