terraform: can't move module to module that exists

This commit is contained in:
Mitchell Hashimoto 2016-04-11 17:40:23 -07:00
parent bbc812d035
commit 30cf550fc5
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 40 additions and 4 deletions

View File

@ -61,6 +61,12 @@ func (s *State) Add(addrRaw string, raw interface{}) error {
func stateAddFunc_Module_Module(s *State, addr *ResourceAddress, raw interface{}) error {
src := raw.(*ModuleState)
// If the target module exists, it is an error
path := append([]string{"root"}, addr.Path...)
if s.ModuleByPath(path) != nil {
return fmt.Errorf("module target is not empty: %s", addr)
}
// TODO: outputs
// TODO: dependencies

View File

@ -426,11 +426,13 @@ func TestStateIncrementSerialMaybe(t *testing.T) {
func TestStateAdd(t *testing.T) {
cases := map[string]struct {
Err bool
Address string
Value interface{}
One, Two *State
}{
"ModuleState => Module Addr (new)": {
false,
"module.foo",
&ModuleState{
Path: rootModulePath,
@ -475,17 +477,45 @@ func TestStateAdd(t *testing.T) {
},
},
},
"ModuleState => Module Addr (existing)": {
true,
"module.foo",
&ModuleState{},
&State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root", "foo"},
Resources: map[string]*ResourceState{
"test_instance.baz": &ResourceState{
Type: "test_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
},
},
},
nil,
},
}
for k, tc := range cases {
// Make sure they're both initialized as normal
tc.One.init()
tc.Two.init()
if tc.Two != nil {
tc.Two.init()
}
// Add the value
if err := tc.One.Add(tc.Address, tc.Value); err != nil {
err := tc.One.Add(tc.Address, tc.Value)
if (err != nil) != tc.Err {
t.Fatalf("bad: %s\n\n%s", k, err)
}
if tc.Err {
continue
}
// Prune them both to be sure
tc.One.prune()
@ -493,8 +523,8 @@ func TestStateAdd(t *testing.T) {
// Verify equality
if !tc.One.Equal(tc.Two) {
t.Fatalf("Bad: %s\n\n%#v\n\n%#v", k, tc.One, tc.Two)
//t.Fatalf("Bad: %s\n\n%s\n\n%s", k, tc.One.String(), tc.Two.String())
//t.Fatalf("Bad: %s\n\n%#v\n\n%#v", k, tc.One, tc.Two)
t.Fatalf("Bad: %s\n\n%s\n\n%s", k, tc.One.String(), tc.Two.String())
}
}
}