code: func ParseResourceStateKey(k string) (*ResourceStateKey, error) {
  	parts := strings.Split(k, ".")
  	mode := config.ManagedResourceMode
  	if len(parts) > 0 && parts[0] == "data" {
  		mode = config.DataResourceMode
  		// Don't need the constant "data" prefix for parsing
  		// now that we've figured out the mode.
  		parts = parts[1:]
  	}
  	if len(parts) < 2 || len(parts) > 3 {
  		return nil, fmt.Errorf("Malformed resource state key: %s", k)
  	}
  	rsk := &ResourceStateKey{
  		Mode:  mode,
  		Type:  parts[0],
  		Name:  parts[1],
  		Index: -1,
  	}
  	if len(parts) == 3 {
  		index, err := strconv.Atoi(parts[2])
  		if err != nil {
  			return nil, fmt.Errorf("Malformed resource state key index: %s", k)
  		}
  		rsk.Index = index
  	}
  	return rsk, nil
  }
docs: // ParseResourceStateKey accepts a key in the format used by
  // ModuleState.Resources and returns a resource name and resource index. In the
  // state, a resource has the format "type.name.index" or "type.name". In the
  // latter case, the index is returned as -1.