code: func upgradeStateV2ToV3(old *State) (*State, error) {
  	new := old.DeepCopy()
  
  	// Ensure the copied version is v2 before attempting to upgrade
  	if new.Version != 2 {
  		return nil, fmt.Errorf("Cannot apply v2->v3 state upgrade to " +
  			"a state which is not version 2.")
  	}
  
  	// Set the new version number
  	new.Version = 3
  
  	// Change the counts for things which look like maps to use the %
  	// syntax. Remove counts for empty collections - they will be added
  	// back in later.
  	for _, module := range new.Modules {
  		for _, resource := range module.Resources {
  			// Upgrade Primary
  			if resource.Primary != nil {
  				upgradeAttributesV2ToV3(resource.Primary)
  			}
  
  			// Upgrade Deposed
  			if resource.Deposed != nil {
  				for _, deposed := range resource.Deposed {
  					upgradeAttributesV2ToV3(deposed)
  				}
  			}
  		}
  	}
  
  	return new, nil
  }
docs: // The upgrade process from V2 to V3 state does not affect the structure,
  // so we do not need to redeclare all of the structs involved - we just
  // take a deep copy of the old structure and assert the version number is
  // as we expect.