terraform: V1 to V2 upgrade should treat nil path as root path

It appears there are no tests for this as far as I can find.

We change V1 states (very old) to assume a nil path is a root path.
Staet.Validate() later will catch any duplicate paths.
This commit is contained in:
Mitchell Hashimoto 2017-03-21 11:12:44 -07:00
parent e8240afcb0
commit e7b07e109f
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 6 additions and 1 deletions

View File

@ -68,6 +68,11 @@ func (old *moduleStateV1) upgradeToV2() (*ModuleState, error) {
if err != nil {
return nil, fmt.Errorf("Error upgrading ModuleState V1: %v", err)
}
if path == nil {
// We found some V1 states with a nil path. Assume root and catch
// duplicate path errors later (as part of Validate).
path = rootModulePath
}
// Outputs needs upgrading to use the new structure
outputs := make(map[string]*OutputState)

View File

@ -18,7 +18,7 @@ func upgradeStateV2ToV3(old *State) (*State, error) {
// Ensure the copied version is v2 before attempting to upgrade
if new.Version != 2 {
return nil, fmt.Errorf("Cannot appply v2->v3 state upgrade to " +
return nil, fmt.Errorf("Cannot apply v2->v3 state upgrade to " +
"a state which is not version 2.")
}